// Main application class to perform the input and display of address data // Version 1.00 // Created by J.Weigmann 06th April 2007 import java.io.*; class JWAddressInput { // Initilize the keyboard input public static InputStreamReader input = new InputStreamReader(System.in); public static BufferedReader keyboardInput = new BufferedReader(input); public boolean InputValidation() throws IOException { boolean repeatInput; do{ repeatInput = false; // Start of Input & Exception handling try { // Enter input for all fields System.out.print("\nEnter your first name: "); String FirstName = new String (keyboardInput.readLine()); System.out.print("\nEnter your last name: "); String LastName = new String (keyboardInput.readLine()); System.out.print("\nEnter your house number: "); int HouseNumber = new Integer (keyboardInput.readLine()).intValue(); System.out.print("\nEnter your first street name detail: "); String Street1Name = new String (keyboardInput.readLine()); System.out.print("\nEnter your second street name detail: "); String Street2Name = new String (keyboardInput.readLine()); System.out.print("\nEnter your city name: "); String CityName = new String (keyboardInput.readLine()); System.out.print("\nEnter your country telephone prefix: "); int TelephoneCountry = new Integer (keyboardInput.readLine()).intValue(); System.out.print("\nEnter your telephone number: "); long TelephoneNumber = new Long (keyboardInput.readLine()).longValue(); // define a new objects for the AddressSimple and AddressAdvanced object JWAddressSimple AddressSimple = new JWAddressSimple(FirstName, LastName, TelephoneCountry, TelephoneNumber); JWAddressAdvanced AddressAdvanced = new JWAddressAdvanced(FirstName, LastName, TelephoneCountry, TelephoneNumber, HouseNumber, Street1Name, Street2Name, CityName); // Start loop for the choice menu boolean checkInput; do{ checkInput = false; // Start of Input & Exception handling for choosing the output try { // Start with Input System.out.print("\n\nWhich output do you prefer?\nChoose 1 for simple or 2 for detailed. Choose 0 for quit: "); int MakeChoice = new Integer (keyboardInput.readLine()).intValue(); if (MakeChoice == 1) { // Display the results on screen AddressSimple.outputResults(); } else { if (MakeChoice == 2) { // Display the detailed results on screen AddressAdvanced.outputResultsDetails(); } else { if (MakeChoice == 0) { System.out.print("\nThe program will exit now!\n"); System.exit(-1); } else { if (MakeChoice < 0 || MakeChoice > 2) { System.out.print("\nYou entered a incorrect value. Try again!\n"); checkInput = true; } else { System.out.print(""); } } } } } catch (NumberFormatException e) { // Catches letter except integer input System.out.print("\n\nYou entered a letter not a correct value. Try again!\n\n"); checkInput = true; } // End of Input & Exception handling }while(checkInput); // end of choice loop } catch(NumberFormatException nfe) { // Catches letter except double input System.out.println("\n\nYou entered a letter not a correct value. Try again!\n\n"); repeatInput = true; } // End of Input & Exception handling catch(IllegalArgumentException iaf) { // Catches letter except double input System.out.println("\n\nYou entered a number not a letter. Try again!\n\n"); repeatInput = true; } } while(repeatInput); return(false); } // end of the main method } // end of the user input validation class class