// The "LiquidConversion" class. import java.awt.*; import hsa.Console; public class LiquidConversion { static Console c; // The output console static String procstr; static int proc; static String amountstr; static double amount; static String unitstr; static int unit; static double none = 0; static char unit2; static char amount2; static boolean runLoop = true; private void title () { c.print (' ', 31); c.print ("Liquid Conversion"); c.println (); } public void intro () { c = new Console (); title (); c.println ("This program will allow you to conver an amount of litre into kilolitres, millilitres, barrels, cups, teaspoons, tablespoons, gallons, quarts, and pints. Press 0 to go back to the main menu."); while (runLoop = true) { try { procstr = c.readLine (); proc = Integer.parseInt (procstr); if (proc == 0) mainmenu(); if (proc != 0) runLoop = true; break; } catch (NumberFormatException e) { c.println ("That's not an integer. Please Try Again"); } } } public void mainmenu () { title (); c.println ("If you wish to exit press 5, if you want to go the intro press 2, and if you want to continue 3:"); while (runLoop = true) { try { procstr = c.readLine (); proc = Integer.parseInt (procstr); if (proc == 3) askData (); if (proc == 2) intro (); if (proc == 5) goodbye (); if (proc == 5 || proc == 3 || proc == 2) runLoop = false; break; } catch (NumberFormatException e) { c.println ("That's not an integer. Please Try Again"); } } //while (proc == 5 && proc == 2 && proc == 3); } public void askData () { c = new Console (); c.print ("1 for Litres, 2 for Kilolitres, 3 for Millilitres, 4 for Barrels, 5 for cups, 6 for teaspoons, 7 for tablespoons, 8 gallons, 9 for quartz and 10 for pints."); c.println ("The amount your converting will be in litres. Please input the amount you want to convert: "); while (true) { try { amountstr = c.readLine (); amount = Double.parseDouble (amountstr); break; } catch (NumberFormatException e) { c.println ("That's not an integer. Please Try Again"); } } c.println ("Please input the unit you want your amount to be converted to: "); while (true) { try { unitstr = c.readLine (); unit = Integer.parseInt (unitstr); displayData (); break; } catch (NumberFormatException e) { c.println ("That's not an integer. Please Try Again"); } } } private double convertLiquid (double none2, char hunt2, char new2) { if (unit == 1) return (amount * 33.8140227); if (unit == 2) return (amount * 0.001); if (unit == 3) return (amount * 1000); if (unit == 4) return (amount * 0.00852167911); if (unit == 5) return (amount * 4.22675284); if (unit == 6) return (amount * 202.884136); if (unit == 7) return (amount * 67.6280454); if (unit == 8) return (amount * 0.264172052); if (unit == 9) return (amount * 1.05668821); if (unit == 10) return (amount * 2.11337642); else return (none); } public void displayData () { c = new Console (); title (); c.println ("Your amount is " + amount + " converted to " + convertLiquid (none2,hunt2,new2)); c.println ("If you want to go back the main menu press 1, if you wish to exit press 0: "); while (true) { try { procstr = c.readLine (); proc = Integer.parseInt (procstr); if (proc == 1) mainmenu (); if (proc == 0) goodbye (); break; } catch (NumberFormatException e) { c.println ("That's not an integer. Please Try Again"); } } } public void goodbye () { c = new Console (); title (); c.print ("Thank you for using the program!"); } public static void main (String[] args) { c = new Console (); LiquidConversion d; d = new LiquidConversion (); d.mainmenu (); // Place your program here. 'c' is the output console } // main method } // LiquidConversion class