import java.io.*; public class CarSales{ private static Car car; private static boolean bStart; public static void main(String[] arg)throws Exception{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String sUserInput = ""; System.out.println("Welcome to the Car Store Application!"); car = new Car(); while(!sUserInput.trim().equals("0")){ System.out.println("\n------------------\nPlease select an option below:"); System.out.println("1.- Add a new car" ); System.out.println("2.- Modify car VIN"); System.out.println("3.- Modify carlicense plates"); System.out.println("4.- Modify caryear"); System.out.println("5.- Modify carMake"); System.out.println("6.- Modify carModel"); System.out.println("7.- Get Car Information"); System.out.println("0.- Exit this program"); sUserInput = br.readLine(); if(sUserInput.trim().length() > 0){ switch(sUserInput.charAt(0)){ case '0': System.out.println("Thank you for using this program"); break; case '1': addCar(); break; case '2': if(bStart) carVIN(); else System.out.println("You need to add a Car first."); break; case '3': if(bStart) carLicense(); else System.out.println("You need to add a Car first."); break; case '4': if(bStart) carYear(); else System.out.println("You need to add a Car first."); break; case '5': if(bStart) carMake(); else System.out.println("You need to add a Car first."); break; case '6': if(bStart) carModel(); else System.out.println("You need to add a Car first."); break; case '7': if(bStart) getInfo(); else System.out.println("You need to add a Car first."); break; default: System.out.println("Invalid selection!"); }//switch }//if else System.out.println("Invalid selection"); }//while }//main private static void addCar() throws Exception{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String sUserInput = ""; if(bStart) { System.out.println("Add a new car will erase your current car stored in memory. Continue?"); sUserInput = br.readLine(); } if(!bStart || (sUserInput.trim().length() > 0 && sUserInput.trim().toUpperCase().charAt(0) == 'Y')) { carMake(); carModel(); carLicense(); carVIN(); carYear(); bStart = true; } } private static void carModel() throws Exception{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String sUserInput = ""; boolean bValid = true; while(bValid) { System.out.print("Please enter the car Model's name: "); sUserInput = br.readLine(); try { car.setModel(sUserInput); bValid = false; } catch(CarException ce){ System.out.println(ce.getMessage()); } } } private static void carMake() throws Exception{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String sUserInput = ""; boolean bValid = true; while(bValid) { System.out.print("Please enter the car Maker's name: "); sUserInput = br.readLine(); try { car.setMake(sUserInput); bValid = false; } catch(CarException ce){ System.out.println(ce.getMessage()); } } } private static void carLicense() throws Exception{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); boolean bValid = true; String sUserInput = ""; while(bValid) { System.out.print("Please enter the car's license: "); sUserInput = br.readLine(); try { car.setPlates(sUserInput); bValid = false; } catch(CarException ce){ System.out.println(ce.getMessage()); } } } private static void carVIN() throws Exception{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); boolean bValid = true; String sUserInput = ""; while(bValid) { System.out.print("Please enter the car's Vin Number: "); sUserInput = br.readLine(); try { car.setVin(Integer.parseInt(sUserInput)); bValid = false; } catch(CarException ce){ System.out.println(ce.getMessage()); } catch(NumberFormatException nfe) { System.out.println("Number you've entered is invalid!"); } } } private static void carYear() throws Exception{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); boolean bValid = true; String sUserInput = ""; while(bValid) { System.out.print("Please enter the car's year: "); sUserInput = br.readLine(); try { car.setYear(Integer.parseInt(sUserInput)); bValid = false; } catch(CarException ce){ System.out.println(ce.getMessage()); } catch(NumberFormatException nfe) { System.out.println("Number you've entered is invalid!"); } } } private static void getInfo(){ System.out.println("--Information of your vehicle:"); System.out.println(car); System.out.println("\n-----------END----------"); } }//class