July 22, 2010, 8:56 am
ok heres my code again... that loop fix worked. Is there anyway I can put in a do loop and if so can you literally show me??
import java.io.*;
import javax.swing.JOptionPane;
import java.util.Scanner;
import java.text.DecimalFormat;
public class Lab4Fall09
{
public static void main(String[] args)
{
// Variable declarations needed
double optionalFeaturesCost = 0.0;
double discount = 0.0;
double totalHomeCost = 0.0;
double netHomeCost = 0.0;
double taxes = 0.0;
double profit = 0.0;
int number = 0;
int quote;
String inputString="";
final double basicHomeCost = 48000;
final double PERCENT_PROFIT =.33;
final double STATE_TAX_RATE = .075;
Scanner input = new Scanner(System.in);
DecimalFormat formatter = new DecimalFormat("$#,##0.00");
//program introduction
JOptionPane.showMessageDialog(null,"This program allows you to select either a standard or a custom built motor home\n"+
"The program will total up and display the cost of the motor home you select and\n"+
"You will be given up to 6 attempts to pick the motor home you want");
//Start Loop here
quote = 1;
while (quote < 5)
{
optionalFeaturesCost = 0.0;
discount = 0.0;
quote = quote + 1;
inputString = JOptionPane.showInputDialog(("This is try # " + quote + "To get a good cost quote\n" +
"For the Basic Motor home Enter 1\n" + "For a Motor Home with Optional Features Enter 2"));
if((Integer.parseInt (inputString) != 1) && (Integer.parseInt (inputString) != 2))
{
JOptionPane.showMessageDialog(null,"Wrong input for Motor Home Type");
System.out.println("Rerun the program.");
System.exit(0);
}
if(Integer.parseInt (inputString) == 2) //motor home option == 2
//Engine Options
inputString = JOptionPane.showInputDialog("For a Standard Diesel Engine Enter 1\n" +
"For a Heavy Duty Diesel Engine Enter 2");
//Engine Errors
if((Integer.parseInt (inputString) != 1) && (Integer.parseInt(inputString) != 2))
{
System.out.print("Wrong input for Engine Type");
System.out.println("Rerun the program.");
System.exit(0);
}
//Calculate OptionalFeaturesCost
if(Integer.parseInt(inputString) == 1)
optionalFeaturesCost += 4000;
else
optionalFeaturesCost += 8000;
//Transmission Options
inputString = JOptionPane.showInputDialog("For a Standard Shift Transmission Enter 1\n"
+ "To Keep Automatic Transmission Enter 3");
if((Integer.parseInt (inputString) != 1) && (Integer.parseInt (inputString) != 3))
{
System.out.print("Wrong input for Transmission Type");
System.out.println("Rerun the program.");
System.exit(0);
}
//Calculate optionalFeaturesCost
if(Integer.parseInt(inputString) == 1)
optionalFeaturesCost -= 2000;
//Cabinet Options
inputString = JOptionPane.showInputDialog("For Deluxe Wood Cabinets and Granite Counter Tops Enter 1\n" +
"To keep the standard Cabinets and Counter tops Enter 2");
//Calculate optionalFeaturesCost
if(Integer.parseInt(inputString) ==1)
optionalFeaturesCost +=18000;
{
//Get furniture option
inputString = JOptionPane.showInputDialog("For Fully Integrated Designer Furniture with Cloth Upholstery Enter 1\n" +
"For all the above with Real Leather Upholstery Enter 2\n" +
"For all the above with Special Plus Carpeting, Ceramic Tile, and Real Wood Paneling Enter 3\n" +
"For all the above with Gold Kitchen and Bath Fixtures, Jacuzzi, and Sauna Enter 4");
}
switch (Integer.parseInt(inputString))
{
case 1:
JOptionPane.showMessageDialog(null,"You Entered 1.");
break;
case 2:
JOptionPane.showMessageDialog(null,"You Entered 2.");
break;
case 3:
JOptionPane.showMessageDialog(null,"You Entered 3.");
break;
case 4:
JOptionPane.showMessageDialog(null,"You Entered 4.");
}
//Check for furniture option errors
if((Integer.parseInt(inputString) != 1))
if((Integer.parseInt(inputString) != 2))
if((Integer.parseInt(inputString) != 3))
if((Integer.parseInt(inputString) != 4))
{
System.out.println("Incorrect input for Furniture type ");
System.out.println("Rerun the program.");
System.exit(0);
}
//Calculate optionalFeaturesCost
if(Integer.parseInt(inputString) ==1)
optionalFeaturesCost +=15000;
else
if(Integer.parseInt(inputString) ==2)
optionalFeaturesCost +=20000;
else
if(Integer.parseInt(inputString) ==3)
optionalFeaturesCost +=30000;
else
if(Integer.parseInt(inputString) ==4)
optionalFeaturesCost +=35000;
//Get discount if any
discount = .1 * optionalFeaturesCost;