$15
Important: This is an individual assignment. Please do not collaborate. No late assignment will be accepted. Make sure that you write every line of your code. Using code written by someone else will be considered a violation of the academic integrity and will result in a report to the Dean's office. Minimal Submitted Files You are required, but not limited, to turn in the following source files: Assignment5.java (Download this file and use it as your driver program for this assignment. You need to add more codes to complete it.)
Customer.java
NonMemberCustomer.java
MemberCustomer.java
CustomerParser.java Requirements to get full credits in Documentation
The assignment number, your name, StudentID, Lecture number/time, and a class description need to be included at the top of each class/file.
A description of each method is also needed.
Some additional comments inside of methods (especially for a "main" method) to explain code that are hard to follow should be written.
You can look at Java programs in the text book to see how comments are added to programs. Skills to be Applied In addition to what has been covered in previous assignments, the use of the following items, discussed in class, will probably be needed: Inheritance
The protected modifier
The super Reference
Abstract class
NumberFormat/DecimalFormat
Wrapper classes
ArrayList Program Description Class Diagram:
In Assignment #5, you will need to make use of inheritance by creating a class hierarchy for students. Customer class Customer is an abstract class, which represents the basic attributes of any customer in a store . It is used as the root of the store customer hierarchy. It has the following attributes (should be protected): Attribute name Attribute type Description firstName String The first name of the customer lastName String The last name of the customer purchasedAmount double a purchased amount of the customer purchasedYear int The purchased year of the purchase purchasedMonth int The purchased month of the purchase purchasedDate int The purchased date of the purchase paymentAmount double a payment amount of the customer The following constructor method should be provided to initialize the instance variables. public Customer(String fName, String lName, double amount, int year, int month, int date) The firstName, lastName, purchasedAmount, purchasedYear, purchasedMonth, purchasedDate are initialized to the value of its corresponding parameter. The paymentAmount should be initialized to 0.0. The following accessor method should be provided for purchasedAmount: public double getPurchasedAmount() The class Customer also has an abstract method (which should be implemented by its child classes NonMember and Member classes) to compute the pay of the customer: public abstract void computePaymentAmount(); The following public method should be provided: public String toString() toString method returns a string of the following format: \nFirst name:\t\tElvis\n
Last name:\t\tPresley\n
Purchased Amount:\t$300.50\n
Purchased Date:\t\t1/15/2016\n
Payment Amount:\t\t$0.00\n NonMemberCustomer class NonMemberCustomer is a subclass of Customer class. It represents a non-member customer that can also shop at the store by paying a visit fee of the day they visit the store. It has the following attribute in addition to the inherited ones: Attribute name Attribute type Description visitFee double A visit fee of the day. The following constructor method should be provided: public NonMemberCustomer(String fName, String lName, double amount, int year, int month, int date, double fee) The firstName, lastName, purchasedAmount, purchasedYear, purchasedMonth, and purchasedDate are initialized to the value of its corresponding parameter. The paymentAmount should be initialized to 0.0. Thus they are done by calling the constructor of the parent. The visitFee is initialized to the value of the last parameter. The following method should be implemented: public void computePaymentAmount() It computes the payment amount for the non-member customer by adding purchasedAmount and visitFee. Also, the following method should be implemented: public String toString() The toString() method inherited from Customer class should be used to create a new string, and display a non-member customer's information using the following format: \nNonMember Customer:
\nFirst name:\t\tElvis\n
Last name:\t\tPresley\n
Purchased Amount:\t$300.50\n
Purchased Date:\t\t1/15/2016\n
Payment Amount:\t\t$0.00\n
Visit Fee:\t\t$10.00\n\n This toString method should make use of the toString method of the parent class. MemberCustomer class MemberCustomer is a subclass of Customer class. It represents a member customer in a store. It has the following additional attributes: Attribute name Attribute type Description pointsCollected int The collected points of the customer The following constructor method should be provided: public MemberCustomer(String fName, String lName, double amount, int year, int month, int date, int points) The firstName, lastName, purchasedAmount, purchasedYear, purchasedMonth, and purchasedDate are initialized to the value of its corresponding parameter. The paymentAmount should be initialized to 0.0. Thus they are done by calling the constructor of the parent. The pointsCollected is initialized to the value of the last parameter. The following method should be implemented: public void computePaymentAmount() It computes the payment amount for the member customer as follows:
If the customer has collected more than 100 points, then the customer gets a discount of 20%, i.e., the payment amount will be purchase amount * (0.8).
Otherwise the customer gets a discount of 10%, i.e., the payment amount will be purchase amount * (0.9).
Then the customer gets more points based on his/her purchase. The points to be added to the pointsCollected is purchasedAmount*(0.01), and only its integer part will become additional points.
Please update the customer's purchasedAmount accordingly. Also, the following method should be implemented: public String toString() The toString() method inherited from Customer class should be used to create a new string, and display a member customer's information using the following format: \nMember Customer:
\nFirst name:\t\tElvis\n
Last name:\t\tPresley\n
Purchased Amount:\t$300.50\n
Purchased Date:\t\t1/15/2016\n
Payment Amount:\t\t$0.00\n
Collected Points:\t80\n\n CustomerParser class The CustomerParser class is a utility class that will be used to create an customer object (one of a non-member or member customer object) from a parsable string. The CustomerParser class object will not be instantiated. It must have the following method: public static Customer parseStringToCustomer(String lineToParse) The parseStringToCustomer method's argument will be a string in the following format: For a non-member customer, type/firstName/lastName/purchaseAmount/purchasedYear/purchasedMonth/purchasedDate/visitFee For a member customer, type/firstName/lastName/purchaseAmount/purchasedYear/purchasedMonth/purchasedDate/pointsCollected A real example of this string would be: NonMember/Mickey/Mouse/1000.30/2016/1/15/10.00 OR Member/Donald/Duck/500.50/2016/1/16/99 The CustomerParser will parse this string, pull out the information, create/instantiate a new object of one of NonMember or Member using their constructor with attributes of the object (depending on whether the first substring is NonMember or Member), and return it to the calling method. The type will always be present and always be one of NonMember and Member. (It can be lower case or upper case) You may add other methods to the NonMember and Member classes in order to make your life easier. Assignment5 class In this assignment, download Assignment5.java file by clicking the link, and use it for your assignment. You need to add code to this file. The parts you need to add are written in the Assignment5.java file, namely for the four cases "Add Customer", "Compute Pay", "Search for Customer", and "List Customers". All input and output should be handled here. The main method should start by displaying this updated menu in this exact format: Choice\t\tAction\n
------\t\t------\n
A\t\tAdd Customer\n
C\t\tCompute Payment Amount\n
D\t\tCount Certain Customers\n
L\t\tList Customers\n
Q\t\tQuit\n
?\t\tDisplay Help\n\n Next, the following prompt should be displayed: What action would you like to perform?\n Read in the user input and execute the appropriate command. After the execution of each command, redisplay the prompt. Commands should be accepted in both lowercase and uppercase. Add Customer Your program should display the following prompt: Please enter some customer information to add:\n Read in the information and parse it using the customer parser. Then add the new object of one of non-member or member customer (created by customer parser) to the customer list. Compute Payment Amount Your program should compute payment amount for all customers created so far by calling computePaymentAmount() method. After computing pay, display the following: payment amount computed\n Search for Customer Your program should display the following prompt: Please enter a purchased amount:\n Read in the amount and count customers with more purchased amount than the input, then display the following: The number of customers who purchased more than $300.00 is: 1\n Note that the dollar amount should be the value entered by a user and the count shown should be the number of customers with more purchased amount than the input. List Customers List the customers in the customer list. Make use of toString method defined in child classes of the Customer class. A real example is looked like this: NonMember Customer:
First name: Mickey
Last name: Mouse
Purchased Amount: $1,000.30
Purchased Date: 1/15/2016
Payment Amount: $0.00
Visit Fee: $10.00
Member Customer:
First name: Donald
Last name: Duck
Purchased Amount: $500.50
Purchased Date: 1/16/2016
Payment Amount: $0.00
Collected Points: 99
If there is no customer in the customer list, then display following: no customer\n Quit Your program should stop executing and output nothing. Display Help Your program should redisplay the "choice action" menu. Invalid Command If an invalid command is entered, display the following line: Unknown action\n Test cases:
You can download each file individually:
Input The following files are the test cases that will be used as input for your program (Right-click and use "Save As"): Test Case #1
Test Case #2
Test Case #3
Test Case #4 Output The following files are the expected outputs of the corresponding input files from the previous section (Right-click and use "Save As"): Test Case #1
Test Case #2
Test Case #3
Test Case #4 Error Handling Your program is expected to be robust to pass all test cases.
NB// TWO CLASSES NOT COMPLETE, ONLY BUY IF YOU WILL COMPLETE ON YOUR OWN. ( CUSTOMERPARSER ,ASSIGMNET5)