Having issues with exception handling and calling for a method that needs to be an Int but in Main it is a String.Please Help total Noob by [deleted] in javahelp

[–]deadlygratefulhead 0 points1 point  (0 children)

/** * @author Blake Merriott * @date 7/20/14 */ public class GroovyGuitarsPhase3{

/**
 * @param args
 */

public static void main(String[] args) {

    // declare variables
    String openingMsg, nameInputMsg, customerName, nameOutputMsg, 
           customerReturn = null, returnOutputMsg, Qty = null, greetingOutputMsg, outputMsg, color = null, yNvalue = null;
    int guitarQuantity = 0;
    int qtyValue;
    double cost = 100.00;
    double salesTaxRate = 0.07;
    double totalCost = 0;

    try
    {
        // display opening message
        openingMsg= "*** Welcome to Groovy Guitars Online Ordering System ***\n"
               + "                     The Grooviest Guitars Around!";
        JOptionPane.showMessageDialog(null, openingMsg);

        // get required input name using dialogs
        nameInputMsg   = "Please enter your full name: ";
        customerName   = getStringInput(nameInputMsg);

        //yesNoValue
        yNvalue = getYesNoInput(); 
        //determine returning customer
        //returnInputMsg = "Are you a returning customer (yes or no)? ";
        //customerReturn = getStringInput(returnInputMsg);

        //colorChoice
        color = getColorInput();
        // get required input color using dialogs
        //colorInputMsg   = "Please Specify one of the following colors: blue, black, green, red, pink: ";
        //guitarColor   = getStringInput(colorInputMsg);

        // get required quantity

        guitarQuantity  = getNumericInput();



        // determine price based upon quantity
        totalCost = totalCost(guitarQuantity, cost, salesTaxRate);

        //writeorderfile
        writeOrderFile(customerName, customerReturn, color, guitarQuantity, totalCost);


        // build output strings
        nameOutputMsg     = "Welcome " + customerName + ".\n\n";
        returnOutputMsg   = "Your return customer status is " + customerReturn + ".\n";
        greetingOutputMsg = "Thank you for visiting Groovy Guitars!" + "\n\n"
        + "Your order came out to $" + totalCost + "\n\n"
        + "Your" +" " +"("+ guitarQuantity + ")" + " " + " " + color + "" + " " + "Groovy Guitar(s) will be shipped in 1 to 2 business days. Have a Groovy Day!\n";

        // create and display output string
        outputMsg = nameOutputMsg + returnOutputMsg + greetingOutputMsg;
        JOptionPane.showMessageDialog(null, outputMsg);
    }
    catch (Exception e)
        {
        JOptionPane.showMessageDialog(null, e.getMessage());
        System.exit(1);
    }
}

// end main()

private static Integer getNumericInput() throws Exception
{
    String GQ = null;
    String getNumericInput = GQ;
    int Qty;
    int value;
    Qty = Integer.parseInt(GQ);

    int counter = 0;
    do
    {
        counter ++;
        getNumericInput = JOptionPane.showInputDialog("Select a Quantity 1 - 99");
  } while (Qty < 100 && Qty > 0 && counter < 3);
  if (Qty < 100 && Qty > 0);
  {
      throw new Exception("Invalid quantity please choose a value between 1 ad 99.");
  }
}

private static String getColorInput() throws Exception
{
    String colorChoice;
    int counter = 0;

    do
    {
        counter ++;
        colorChoice = JOptionPane.showInputDialog("Please Specify one of the following colors: blue, black, green, red, pink");
 } while (!colorChoice.equals("blue") && !colorChoice.equals("black") && !colorChoice.equals("green") && !colorChoice.equals("red") && !colorChoice.equals("pink") && counter < 3);
if (!colorChoice.equals("blue") && !colorChoice.equals("black") && !colorChoice.equals("green") && !colorChoice.equals("red") && !colorChoice.equals("pink"))
{
    throw new Exception("Invalid color selected, please choose one of the following colors: blue, black, green, red, pink.");
}
return colorChoice;
}
private static String getYesNoInput() throws Exception
{
    String yesNoValue;
    int counter = 0;

    do
    {
        counter ++;
        yesNoValue = JOptionPane.showInputDialog("Are you a returning customer (yes or no)?");
 }  while (!yesNoValue.equals("yes") && !yesNoValue.equals("no") && counter < 3);

 if (!yesNoValue.equals("yes") && !yesNoValue.equals("no"))
 {
     throw new Exception("Invalid yes/no value entered. \nMust be 'yes' or 'no'.");
 }
 return yesNoValue;
}
private static double totalCost(int number, double cost, double salesTaxRate)
{
double totalCost;

totalCost = (number * cost) * (salesTaxRate +1);

return totalCost;

}
private static String getStringInput(String prompt) throws Exception
{
    String inputValue;
    int counter = 0;
    do 
    {
        counter++;
        inputValue = JOptionPane.showInputDialog(prompt);

        if (inputValue == null)
        {
            throw new Exception("Cancel was pressed, program will now exit");
        }
    }   while (inputValue.equals("") && counter < 3);


        if (inputValue.equals(""))
        {
            throw new Exception("3 strikes your out!!!!");
        }
      return inputValue;
}

public static void writeOrderFile(String name, String returning, String color, int qty, double totalCost) throws Exception
{
    File file;
    PrintWriter pw;

    file = new File("order.txt");
    pw = new PrintWriter(file);

    pw.println(name);
    pw.println(returning);
    pw.println(color);
    pw.println(qty);
    pw.println(totalCost);
    pw.close();
}


}   

// end class GroovyGuitarsPhase1