August 29, 2010, 12:24 am
ok here is my code, it compiles and runs but when it does it keeps giving me one total and one discount with each option and i dont know how to fix it so it ouputs the correct total cost. Please help... im just a beginner in this! haha
import java.io.*;
import javax.swing.JOptionPane;
import java.util.Scanner;
import java.text.DecimalFormat;
public class Lab5Fall09
{
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");
descriptionMsg();
//Start Loop here
quote = 0;
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");
inputString = JOptionPane.showInputDialog("Re-enter for the Basic Motor home Enter 1\n" +
"For a Motor Home with Optional Features Enter 2");
}
//motor home option == 1
if((Integer.parseInt (inputString) == 1) && (Integer.parseInt (inputString) != 2))
{
JOptionPane.showMessageDialog(null,"Your quote for a basic motor home is 48000.0");
System.exit(0);
}
else
if(Integer.parseInt (inputString) != 1) //motor home option == 2
getEngineOptions(optionalFeaturesCost);
getTransmissionOptions(optionalFeaturesCost);
getCabinetOptions(optionalFeaturesCost);
{
//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");
}
//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))
{
JOptionPane.showMessageDialog(null,"Incorrect input for Furniture type ");
inputString = JOptionPane.showInputDialog(" Re-Enter 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.");
}
//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;
computeDiscount(optionalFeaturesCost,discount);
computetotalHomeCost(totalHomeCost,optionalFeaturesCost,discount);
}
//ask for more quotes
inputString = JOptionPane.showInputDialog("If You Would Like More Quotes Enter 1\n"+
"To Save Last Quote Enter Any Other Number");
quote++;
if(Integer.parseInt (inputString) == 1) //doesn't exceed the number of quotes and wants more
System.out.println("Rerun Program and Enter Option Choices Again");
else
if(Integer.parseInt (inputString) != 1) //doesn't want more quotes and wants to exit
goodByeMsg();
System.exit(0);
} //End of Main Method
//descriptionMess