NOTE: The following seems long because it is detailed, not because of quantity of work. Don't panic. Create a menu-driven program in NetBeans to meet the following conditions. Program Logic In the...


NOTE: The following seems long because it is detailed, not because of quantity of work. Don't panic.


Create a menu-driven program in NetBeans to meet the following conditions.


Program Logic


In the main() method, establish an ArrayList and initialize it to an empty array. Then create and display the following menu:



  1. Add a Customer

  2. Add an Employee

  3. Show All Persons

  4. Show All Customers

  5. Show All Employees

  6. Exit


For "Add a Customer", instantiate a CustomerHandler object and call its getCustomer() method to get a new Customer object to add to the Person List. The getCustomer() method should ask the user for all the needed inputs to build a Customer object.


For "Add an Employee", instantiate a EmployeeHandler object and call its getEmployee() method to get a new Employee object to add to the Person List. The getEmployee() method should ask the user for all the needed inputs to build a Employee object.


For "Show All Persons", "Show All Customers", and "Show All Employees", create static void methods in the main class that take the Person List as an argument. The method will loop through the list and print each item on its own line. The showAllPersons() method will print all the records. The showAllCustomers() method will only print Customer records, ignoring the others. The showAllEmployees() method will only print Employee records, ignoring the others. The showAllCustomers() and showAllEmployees() methods can use the instanceof operator to determine if the objects are the correct type.


Person


For the above, you will create classes for Person, Customer, and Employee. Person is a superclass, for which Customer and Employee are both subclasses.


The Person class is in the person package and has the following protected attributes:



  • personId (int)

  • dob (LocalDate)

  • firstName (String)

  • lastName (String)


In addition to the accessors and mutators for each of those attributes, Person also has the methodpublic int getAge()which returns the person's age in years. There should also be three constructors. One which takes an argument for every attribute, one which takes only lastName and firstName (using zero as the default ID), and one which takes no arguments (using zero as the ID and empty Strings for the names.)


Helpful Hint: If the dob value for the person is not null, you can get the age in years by using Period class method between(). It will look like this:



age = Period.between(LocalDate.now(), dob).getYears();


Customer


The Customer class is in the package person.customer and extends Person. The Customer had two protected attributes:



  • inStore (boolean) which is true if the customer ever shopped in a brick-and-mortar store

  • online (boolean) which is true if the customer ever shopped on the business' website


These attributes have the standard accessors and mutators.


The customer class has four (4) constructors with the following parameter lists:



  • inStore, online, personId, lastName, firstName, dob

  • inStore, online, personId, lastName, firstName

  • lastName, firstName

  • personId, lastName, firstName, dob


Use default values any time there is a missing parameter.


Employee


The Employee class is in the package person.employee and extends Person. The Employee class has two protected attributes:



  • startDate (LocalDate) The date the employee became an employee, which cannot be null

  • endDate (LocalDate) The date the employee stopped being an employee, where a null value or date in the future means the person is still an employee.


These attributes have the standard accessors and mutators. Note that endDate must be either null or later than startDate.


The Employee class has six (6) constructors with the following parameter lists:



  • startDate, endDate, personId, lastName, firstName, dob

  • startDate, endDate, personId, lastName, firstName

  • startDate, lastName, firstName

  • startDate, personId, lastName, firstName, dob

  • lastName, firstName

  • personId, lastName, firstName, dob


The default endDate is null.


Handlers


The CustomerHandler and EmployeeHandler classes are allowed to interact with the user.


Helpful Hint: Create a PersonHandler that gets all the data from the user to build a Person object. Use that inside of the CustomerHandler and EmployeeHandler to get the common fields. That way you won't have to duplicate that logic.


Another Helpful Hint: When asking the user for data, it is helpful to create a utility method for each data type you need, passing a prompt string as an argument. This helps reduce the code you have to write. Also, once you've tested one of these methods, you don't have to worry about it any more. For example, you can write one method that displays the prompt and returns an int value. Then, when you write a method to get a LocalDate, you can ask for the month, day, and year all as int values that you get by calling the method that returns ints. You can use those int values to build a LocalDate object with the methodLocalDate.of(year, month, day).

Apr 15, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here