Main{ public static int promptInt(String prompt){{ /* This function will create an int described by the user input: prompt - a prompt to show the user output: a new int with value given by the user */ Integer tempInt = new Integer(0); System.out.println(prompt); try{tempInt = new Integer(Main.stdin.readLine());} catch (Exception e) {System.out.println("Error reading input");} return tempInt.intValue(); }} public static String promptString(String prompt){{ /* This function will create a string described by the user input: prompt - a string to prompt the user output: a string given by the user */ String returnStr = ""; System.out.println(prompt); try{returnStr = Main.stdin.readLine();} catch (IOException e) {System.out.println("Error reading string input");} return returnStr; }} public static char promptChar(String prompt){{ /* This function will create a char entered by the user input: prompt - a prompt to show the user output: a new char with value given by the user */ char returnChar = ' '; System.out.println(prompt); try{ String temp = Main.stdin.readLine(); if (temp != "") returnChar = temp.charAt(0); } catch (Exception e) {System.out.println("Error reading character input");} return returnChar; }} }//end Main Party{ private static char promptKind(){{ /* This function will return a string specifying what kind of party the user wants return char is guaranteed to be i c or q output: the char 'c' 'i' or 'q' */ char option = ' '; //find out what kind of party (individual or corporate) while (option != 'i' && option != 'c' && option != 'q') option = Main.promptChar("Is this an individual or a corporate account? (i/c/q to quit)"); return option; }} public static Party promptParty(String prompt, boolean newParty){{ /* This function will find a party described by user input. input: prompt - a string to prompt the user newParty - if true, a new Party will be created output: a new party if newParty, otherwise an existing party or null */ Party returnParty; //party to be returned char partyType; //char represents type of party we are adding //find out what subclass of party to add partyType = promptKind(); System.out.println(prompt); //get the party from the user if (partyType == 'i') returnParty = Individual.prompt("", newParty); else if (partyType == 'c') returnParty = CorporateBody.prompt("", newParty); else returnParty = null; return returnParty; }} }//end Party PartyId { public static PartyId prompt(String prompt){{ /* This function will find a partyId given by the user input: prompt - string used to prompt the user output: a new PartyId with value given by the user */ int partyId = Main.promptInt(prompt); PartyId returnId = new PartyId(partyId); return returnId; }} } // end PartyId CorporateBody{ public static CorporateBody prompt(String prompt, boolean newBody){{ /* This function will get a Corporate Body holding information specified by the user. input: prompt - a string to prompt the user newBody - If true, a new CorporateBody will be created. output: a CorporateBody object. a new one if newBody, otherwise, an existing one will be returned or null */ CorporateBody returnMe; PartyId id; //tax id number CompanyName name; //corporation name Rating rating; //corporation risk rating System.out.println(prompt); //get the tax id number id = PartyId.prompt("tax id number: "); //if the id number is not good, abort if (id.get_partyId() == 0) return null; //otherwise continue gathering necessary information if (newBody) { name = CompanyName.prompt("Enter the company name"); rating = Rating.prompt("Enter company rating"); returnMe = new CorporateBody(new Agreement(new Contract_List(), new Agr_Rule_List(), new Day()),id, name, rating); } else { returnMe = (CorporateBody) Main.b.findParty(id, false); } return returnMe; }} }//end CorporateBody CompanyName{ public static CompanyName prompt(String prompt){{ /* This function will get a company name entered by the user input: prompt - a string to prompt the user output: a new CompanyName object */ String name = Main.promptString(prompt); CompanyName returnName = new CompanyName(name); return returnName; }} }//end CompanyName Rating { {{ private static HashMap subclassMap = null; //holds objects of all subclasses of Rating }} private static void setUpSubclassMap(){{ /* populates the subclass table */ subclassMap = new HashMap(); subclassMap.put("C0", new C0()); subclassMap.put("C1", new C1()); subclassMap.put("C9", new C9()); subclassMap.put("D0", new D0()); subclassMap.put("D1", new D1()); subclassMap.put("D3", new D3()); subclassMap.put("D4", new D4()); }} public static Rating prompt(String prompt){{ /* This function will get a rating entered by the user input: prompt - a string to prompt the user output: a new Rating object */ Rating returnRating = null; //Rating to be returned String tempRating = Main.promptString(prompt + " [C0][C1][C9][D0][D1][D3][D4]"); if ((tempRating != "C0") && (tempRating != "C1") && (tempRating != "C9") && (tempRating != "D0") && (tempRating != "D1") && (tempRating != "D3") && (tempRating != "D4")){ System.out.println("invalid rating entered, C0 will be used"); tempRating = "C0"; } if (subclassMap == null) setUpSubclassMap(); returnRating = (Rating) subclassMap.get(tempRating); return returnRating; }} }//end Rating Individual{ public static Individual prompt(String prompt, boolean newIndividual){{ /* This function will find an individual holding information specified by the user. input: prompt - a string to prompt the user for an individual newIndividual - if true, a new Individual will be created. output: the new Individual is newIndividual otherwise, an existing individual or null */ Individual returnIndividual;//individual to be returned PartyId id; //social security number FirstName first; //individual first name LastName last; //individual last name Date birthdate; //individual birthdate System.out.println(prompt); //get social security number id = PartyId.prompt("Enter social security number:"); //if id is not good, abort if (id.get_partyId() == 0) return null; //otherwise continue gathering necessary information if (newIndividual) { first = FirstName.prompt("Enter individual first name"); last = LastName.prompt("Enter individual last name"); birthdate = Date.prompt("Enter individual birthdate"); returnIndividual = new Individual(new Agreement(new Contract_List(), new Agr_Rule_List(), new Day()), id, first, last, birthdate); } else { returnIndividual = (Individual) Main.b.findParty(id, false); } return returnIndividual; }} }//end Individual FirstName { public static FirstName prompt(String prompt){{ /* This function will get a name given by the user input: a string to prompt the user output: a FirstName described by user input */ String name = Main.promptString(prompt); FirstName returnName = new FirstName(name); return returnName; }} }//end FirstName LastName { public static LastName prompt(String prompt) {{ /* This function will get a last name input: a string to prompt the user output: a new LastName object */ String name = Main.promptString(prompt); LastName returnName = new LastName(name); return returnName; }} }//end LastName Description { public static Description prompt(String prompt){{ /* creates a description based on user input input: prompt - a string to prompt the user output: a new Description object */ String desc = Main.promptString(prompt); Description returnMe = new Description(desc); return returnMe; }} }// end Description Location{ void print() to * (PrintVisitor); public static Location prompt(String prompt){{ /* Creates a new location given by the user input: prompt - a string to prompt the user output: a new Location object */ String place = Main.promptString(prompt); Location returnLoc = new Location(place); return returnLoc; }} } //end Location Country{ void print() to * (PrintVisitor); public static Country prompt(String prompt){{ /* Creates a new country given by the user input: prompt - a string to prompt the user output: a new Country object */ String place = Main.promptString(prompt); Country returnCountry = new Country(place); return returnCountry; }} } //end Country Index{ void print() to * (PrintVisitor); public static Index prompt(String prompt){{ /* This function will create an Index described by the user input: prompt - a prompt to show the user output: a new Index object with value given by the user */ int indexVal = Main.promptInt(prompt); Index returnIndex = new Index(indexVal); return returnIndex; }} } //end Index Date { public static Date prompt(String prompt) {{ /* This function will get a new date from the user input: prompt - a string to prompt the user output: a new Birthdate object */ Month month; //the month of the date Day day; //the day of the date Year year; //the year of the date Date returnDate; //the date to return System.out.println(prompt); month = Month.prompt("Enter month"); day = Day.prompt("Enter day of the month"); year = Year.prompt("Enter year"); returnDate = new Date(month, day, year); return returnDate; }} }//end Date Month { public static Month prompt(String prompt) {{ /* This function will get a new month from the user input: prompt - a string to prompt the user output: a new Month object */ int returnMonthVal = 0; //the int value of the month boolean valid = false; //flag tells if the given month is valid while (!valid){ returnMonthVal = Main.promptInt(prompt); valid = (returnMonthVal > 0 && returnMonthVal < 13); } Month returnMonth = new Month(returnMonthVal); return returnMonth; }} }//end Month Day { public static Day prompt(String prompt) {{ /* This function will get a new day from the user input: prompt - a string to prompt the user output: a new Day object */ int dayVal = 0; //int value of the day boolean valid = false; //flag tells if the day is valid while (!valid){ dayVal = Main.promptInt(prompt); valid = (dayVal > 0 && dayVal < 32); } Day returnDay = new Day(dayVal); return returnDay; }} }//end Day Year { public static Year prompt(String prompt) {{ /* This function will get a new day from the user input: prompt - a string to prompt the user output: a new Year object */ int returnYearVal = 0; //int value of the year boolean valid = false; //flag tells if a valid year was given while (!valid){ returnYearVal = Main.promptInt(prompt); valid = (returnYearVal > 1800 && returnYearVal < 3000); } Year returnYear = new Year(returnYearVal); return returnYear; }} }//end Year AccountType{ {{ private static HashMap subclassMap = null; //holds objects of all subclasses of AccountType }} private static void setUpSubclassMap(){{ /* populates the subclass table */ subclassMap = new HashMap(); subclassMap.put("1", new Savings()); subclassMap.put("2", new Checking()); subclassMap.put("3", new Overdraft()); subclassMap.put("4", new CD()); subclassMap.put("5", new Loan()); }} public static AccountType prompt(String prompt){{ /* Creates an AccountType based on user input input: prompt - a string to prompt the user output: a new AccountType object described by the user */ String choice; AccountType returnType; System.out.println(prompt + "\n1) savings \n 2) checking \n 3) overdraft \n 4) CD \n 5) loan"); choice = Main.promptString(""); if ((choice != "1") && (choice != "2") && (choice != "3") && (choice != "4") && (choice != "5")) { System.out.println("Error reading account type. Will be set to savings"); choice = "1"; } returnType = (AccountType) subclassMap.get(choice); return returnType; }} }// end AccountType AccountID { public static AccountID prompt(String prompt){{ /* This function will find an accountId given by the user input : prompt - string used to prompt the user output: a new AccountId with value given by the user */ int accountId = Main.promptInt(prompt); AccountID returnId = new AccountID(accountId); return returnId; }} }//end AccountID Posting{ {{ private static HashMap subclassMap = null; //holds objects of all subclasses of posting }} private static void setUpSubclassMap(){{ /* populates the subclass table */ subclassMap = new HashMap(); subclassMap.put("+", new Credit()); subclassMap.put("-", new Debit()); }} public static Posting prompt(String prompt){{ /* This function will find an posting given by the user input : prompt - string used to prompt the user output: a new posting described by the user */ Posting returnPosting; char postType = Main.promptChar("Enter + for credit or - for debit"); Amount amount = Amount.prompt("how much"); Date date = Date.prompt("enter posting date"); if (postType == '+') returnPosting = new Credit(amount, date); else returnPosting = new Debit(amount, date); return returnPosting; }} }//end Posting Amount { public static Amount prompt(String prompt){{ /* This function will find an amount given by the user input : prompt - string used to prompt the user output: a new amount with value given by the user */ int amount = Main.promptInt(prompt); Amount returnAmount = new Amount(amount); return returnAmount; }} }//end Amount