}//default constructor /** Prompts the user for the new values with which to update a person. * @param ui the user interface with which to communicate with the user * @param aPerson the person object to update * @param retainOldValue if true, the current value of an attribute is * retained if the user does not specify a new value. * If false, and a value is required for the * attribute, the user will be prompted repeatedly * to enter a value until the value is valid. */ public void updatePerson(UserInterface ui, Person aPerson , bool retainOldValue) { try { if (retainOldValue) { ui.message("\nEnter new values. " + "Press Enter for values that are correct."); } string input = ui.promptForString("\nName: "); if (input.Length == 0 && retainOldValue) { aPerson.setName(aPerson.getName()); //ensure valid name } else { aPerson.setName(input); } input = ui.promptForString("Street Address: "); if (input.Length == 0 && retainOldValue) { ; //retain old value } else { aPerson.setStreet(input); } input = ui.promptForString("City: "); if (input.Length == 0 && retainOldValue) { ; //retain old value } else { aPerson.setCity(input); } input = ui.promptForString("State: "); if (input.Length == 0 && retainOldValue) { ; //retain old value } else { aPerson.setState(input); } input = ui.promptForString("Zip Code: "); if (input.Length == 0 && retainOldValue) { ; //retain old value } else { aPerson.setZip(input); } input = ui.promptForString("Email: "); if (input.Length == 0 && retainOldValue) { ; //retain old value } else { aPerson.setEmail(input); } } catch (ArgumentOutOfRangeException ex) { ui.errorMessage(ex.Message); ui.message("Current details:\n"); ui.message(aPerson.toFormattedString()); ui.message("\nPlease repeat input.\n"); updatePerson(ui, aPerson, true); //Give the user another chance } }//updatePerson
/** * Creates a new SchedulerInterface which then runs the accounting procedure. */ public SchedulerInterface() { //for communciation with the tester UserInterface ui = new UserInterface(); ui.message("\nRunning the accounting procedure ...\n"); //Use today's date for all reports DateTime now = new DateTime(); try { //Generate provider reports ui.message("Generating the providers' reports ..."); Providers providers = new Providers(); providers.open(); List <Person> allProviders = providers.getAll(); foreach (Person person in allProviders) { Provider provider = (Provider)person; ProviderReportGenerator generator = new ProviderReportGenerator(provider, now); ProviderReport theReport = generator.getReport(); if (theReport.getDetailCount() > 0) { theReport.sendByEmail(provider.getName()); } } providers.close(); //Generate member reports ui.message("Generating the members' reports ..."); Members members = new Members(); members.open(); List <Person> allMembers = members.getAll(); foreach (Person person in allMembers) { Member member = (Member)person; MemberReportGenerator generator = new MemberReportGenerator(member, now); MemberReport theReport = generator.getReport(); if (theReport.getDetailCount() > 0) { theReport.sendByEmail(member.getName()); } } members.close(); //Generate accounts payable report ui.message("Generating the accounts payable report ..."); AccountsPayableReportGenerator generator = new AccountsPayableReportGenerator(now); generator.getReport().sendByEmail("Accounts Payable"); //Generate EFT data ui.message("Generating the EFT data ..."); EFTReportGenerator eftGenerator = new EFTReportGenerator(now); eftGenerator.getReport().print("EFT Data"); ui.message("\nAccounting procedure completed successfully.\n\n"); } catch (FileNotFoundException ex) { //occurs if a file cannot be created ui.errorMessage(ex.Message); } }//default constructor