class wz
{
public static void main(String []args)
{
int convert; //the main object user wants to convert
int choicetemp; //chosing either from f to c or c to f
int celsiusvalue; //celsius value
int farvalue;//farenheit value
int choiceweight;//chosing from pds to kgs or kgs to pds
int cmvalue; //centimeter value
int inchvalue;// inch value
int choicelength; //inches to inche to cm or inverse
int pdvalue; //pound value
int kgvalue; // centimeter value
System.out.println("What would you like to convert?"); //allows user to choose what he wants to convert
System.out.println("1-Temperature.");
System.out.println("2-Length.");
System.out.println("3-Weight.");
convert=TextIO.getInt(); //allows user input
System.out.println(""); //empty line
switch (convert) //enabling switch case for general selection
{
case 1: //case 1 is the TEMPERATURE
System.out.println("Temperature Conversion");
System.out.println(".......................");
System.out.println("a. Celsius to Fahreinheit");
System.out.println("b. Fahrenheit to Celsius");
System.out.println("");
System.out.println("Please enter a choice");
choicetemp=TextIO.getChar(); //chosing a or b
switch (choicetemp) //enables the switch
{
case 'a': //what happens when he types a in
System.out.println("Enter Celsius value:");
celsiusvalue=TextIO.getInt(); //accepting celsius value
System.out.println(celsiusvalue + " Celsius = " + (celsiusvalue*33.8) + " Fahrenheit"); //the math equation to convert
break; //end the case
}
switch (choicetemp) //enables the switch
{
case 'b': //what happens when he types a in
System.out.println("Enter Fahrenheit value:");
farvalue=TextIO.getInt();
System.out.println(farvalue + " Fahrenheit = " + (farvalue-32)/1.8 + " Celsius");
break;
}
case 2: //LENGTH
System.out.println("Length Conversion");
System.out.println("..................");
System.out.println("a. Centimeters to Inches");
System.out.println("b. Inches to Centimeters");
System.out.println("");
System.out.println("Please enter a choice");
choicelength=TextIO.getChar(); //accepts if he wants either cm to inch of opposite
switch (choicelength) //turns on the switch case
{
case 'a': // what happens when he types a
System.out.println("Enter centimeter value");
cmvalue=TextIO.getInt();// accepts value for cm
System.out.println(cmvalue + " Centimeter = " + (cmvalue*0.39) + " Inch"); //takes previous value and calculate
break;
case 'b': // what happens when he types b
System.out.println("Enter Inche value");
inchvalue=TextIO.getInt();// accepts value for inch
System.out.println(inchvalue + " Inch = " + (inchvalue*2.54) + " Centimeter");
break;
}
case 3: //WEIGHT
System.out.println("Weigth Conversion");
System.out.println("...................");
System.out.println("a. Pounds to Kilograms");
System.out.println("b. Kilograms to Pounds");
System.out.println("");
System.out.println("Please enter a choice");
choiceweight=TextIO.getChar();
switch (choiceweight)
{
case'a':
System.out.println("Enter Pound value");
pdvalue=TextIO.getInt();
System.out.println(pdvalue + " Pound = " + (pdvalue*0.45) + " Kilogram");
break;
case 'b':
System.out.println("Enter Kilogram value");
kgvalue=TextIO.getInt();
System.out.println(kgvalue + " Kilograms = " + (kgvalue*2.2) + " Pound");
break;
}
break;// closes small switch
}//closes big switch
}//closes main
} //closes class
Hello everyone, I have a problem with this program that I made. When I type in all the required stuff, then it just post
--------------------Configuration: <Default>-------------------- What would you like to convert? 1-Temperature. 2-Length. 3-Weight. 1 Temperature Conversion ....................... a. Celsius to Fahreinheit b. Fahrenheit to Celsius Please enter a choice ? a Enter Celsius value: 212 212 Celsius = 7165.599999999999 Fahrenheit Length Conversion .................. a. Centimeters to Inches b. Inches to Centimeters Please enter a choice ?
Normaly it should end after it said the temp in Fahrenheit, but then I get the length conversion printed. I recon it's problem with a break; but I just cannot find where it is. Any help would be greatly appreciated
Thanks you

New Topic/Question
Reply



MultiQuote



|