import java.util.*; /*Topics: throwing and catching exceptions * *This program will continue to prompt the use for input until it is happy *with the input provided. It uses exception handling to screen out invalid input */ public class Main{ public static void main(String[] args){ Scanner keyboard = new Scanner(System.in); Person aPerson = null; Address anAddress = null; PhoneNumber aPhoneNumber = null; boolean inputAccepted = false; //Try and obtain a valid person name and make a Person object while(!inputAccepted){ try{ System.out.print("Enter Persons's Name [e.g. Louis Nel] "); String inputString = keyboard.nextLine(); aPerson = new Person(inputString); inputAccepted = true; } catch(IllegalNameSpellingException e){ System.out.println(e); } catch(Exception e){ //REPLACE THIS GENERAL EXCEPTION WITH MORE SPECIFIC CATCH BLOCKS System.out.println(e); } } inputAccepted = false; //Try and obtain a valid address while(!inputAccepted){ try{ System.out.print("Enter Address: [1156 Bank St., Ottawa, K1S 5B6] "); String inputString = keyboard.nextLine(); anAddress = new Address(inputString); inputAccepted = true; } catch(Exception e){ //REPLACE THIS GENERAL EXCEPTION WITH MORE SPECIFIC CATCH BLOCKS System.out.println(e); } } inputAccepted = false; //Try and obtain a valid phone number while(!inputAccepted){ try{ System.out.print("Enter Local Phone#: [238-1225] "); String inputString = keyboard.nextLine(); aPhoneNumber = new PhoneNumber(inputString); inputAccepted = true; } catch(Exception e){ //REPLACE THIS GENERAL EXCEPTION WITH MORE SPECIFIC CATCH BLOCKS System.out.println(e); } } System.out.println(""); System.out.println("INPUT ACCEPTED"); System.out.println("=============="); System.out.println(aPerson); System.out.println(anAddress); System.out.println(aPhoneNumber); } //end main() } //end class Main