Beispiel #1
0
        }//deleteService

        //Utility method to get user input and update attributes of a service
        private void updateService(UserInterface ui, Service aService
                                   , bool retainOldValue)
        {
            try
            {
                String input;

                //Get value for code if it has not already been set
                if (aService.getCode() == null)  //code may not be changed
                {
                    input = ui.promptForString("Code: ");
                    aService.setCode(input);
                }

                //get value for name
                input = ui.promptForString("Name: ");
                if (input.Length == 0 && retainOldValue)
                {
                    aService.setName(aService.getName());    //ensure valid name
                }
                else
                {
                    aService.setName(input);
                }

                //get value for fee
                double fee;
                if (retainOldValue)
                {
                    fee = ui.promptForDouble("Fee: ", aService.getFee());
                }
                else
                {
                    fee = ui.promptForDouble("Fee: ");
                }
                aService.setFee(fee);
            }
            catch (ArgumentException ex)
            {
                ui.errorMessage(ex.Message);
                ui.message("Current details:");
                ui.message(aService.toFormattedString());
                ui.message("\nPlease repeat input.  "
                           + "Press Enter for details that are correct.");
                updateService(ui, aService, true);    //Give the user another chance
            }
        }//updateService
Beispiel #2
0
        }//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 (ArgumentException 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 Claim Submitter object
         *  @param theProvider the provider submitting the claim
         *  @param theMember the member to whom the service was provided
         */
        public ClaimSubmitter(Provider theProvider, Member theMember)
        {
            try
            {
                ui = new UserInterface();

                services = new Services();
                claims   = new Claims();
                services.open();
                claims.open();

                //get the service date
                DateTime serviceDate = ui.promptForDate
                                           ("Service Date (" + UserInterface.DATE_FORMAT + "): ");

                //get the correct service
                Service theService  = null;
                bool    correctCode = false;
                do
                {
                    //get the service code
                    String serviceCode = ui.promptForString("Service Code: ");
                    theService = services.find(serviceCode);
                    if (theService == null)
                    {
                        ui.errorMessage("Invalid code.  Please re-enter.");
                    }
                    else
                    {
                        //confirm the service
                        String answer = ui.promptForString("Service: "
                                                           + theService.getName()
                                                           + "  \nIs this correct? (Y)es or (N)o: ");
                        if (answer != null && answer.Length >= 1 &&
                            Char.ToUpper(answer[0]) == 'Y')
                        {
                            correctCode = true;
                        }
                    }
                } while (!correctCode);


                //Create new claim.  The constructor initializes
                //the submission date and time with the system time.
                Claim aClaim = new Claim(theService.getCode(),
                                         theProvider.getNumber(), theMember.getNumber(),
                                         serviceDate);
                claims.add(aClaim);
                //Display success confirmation and service fee
                ui.message("Your claim has been submitted successfully.");
                ui.message("Service fee due to you: "
                           + ui.formatAsCurrency(theService.getFee()));

                services.close();
                claims.close();
            }
            catch (Exception ex)
            {
                //File format is incorrect
                ui.errorMessage(ex.Message);
            }
        }//default constructor