Starting from:
$29.99

$23.99

Assignment #5 Solution

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:

 

Error Handling

Your program is expected to be robust to pass all test cases.

 

Test input and expected out puts

Input 1

L

A

NonMember/Mickey/Mouse/1000.30/2016/1/15/10.00

L

A

Member/Donald/Duck/500.50/2016/1/16/99

L

A

Member/Clarabelle/Cow/800.05/2016/1/18/102

L

Q

 

Input2

A
Member/Luke/Skywalker/355.24/2016/3/14/80
?
A
NonMember/Han/Solo/500.50/2016/1/30/5.00
A
Member/Darth/Vader/300.55/2016/2/6/100
L
C
L
Q
 

Input3

A
Member/Harry/Potter/50.23/2016/1/21/99
A
NonMember/Hermione/Granger/640.23/2016/2/20/16.00
A
Member/Ron/Weasley/400.32/2016/1/20/105
L
D
400.00
D
500.23
Q
 

Input 4

A
Member/Mickey/Mouse/400.50/2016/4/18/98
A
Member/Donald/Duck/200.50/2016/4/20/200
A
NonMember/Daisy/Duck/300.50/2016/1/2/15.00
A
Member/Minnie/Mouse/700.50/2016/4/10/300
L
D
100.10
D
200.50
D
200.49
D
0.00
C
L
Y
u
k
P
Q
 

 

Output1

Choice         Action
------         ------
A              Add Customer
C              Compute Payment Amount
D              Count Certain Customers
L              List Customers
Q              Quit
?              Display Help
 
What action would you like to perform?
no customer
What action would you like to perform?
Please enter some customer information to add:
What action would you like to perform?
 
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
 
What action would you like to perform?
Please enter some customer information to add:
What action would you like to perform?
 
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
 
What action would you like to perform?
Please enter some customer information to add:
What action would you like to perform?
 
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
 
 
Member Customer:
First name:            Clarabelle
Last name:             Cow
Purchased Amount:      $800.05
Purchased Date:        1/18/2016
Payment Amount:        $0.00
Collected Points:      102
 
What action would you like to perform?
 

Output2

Choice         Action
------         ------
A              Add Customer
C              Compute Payment Amount
D              Count Certain Customers
L              List Customers
Q              Quit
?              Display Help
 
What action would you like to perform?
Please enter some customer information to add:
What action would you like to perform?
Choice         Action
------         ------
A              Add Customer
C              Compute Payment Amount
D              Count Certain Customers
L              List Customers
Q              Quit
?              Display Help
 
What action would you like to perform?
Please enter some customer information to add:
What action would you like to perform?
Please enter some customer information to add:
What action would you like to perform?
 
Member Customer:
First name:            Luke
Last name:             Skywalker
Purchased Amount:      $355.24
Purchased Date:        3/14/2016
Payment Amount:        $0.00
Collected Points:      80
 
 
NonMember Customer:
First name:            Han
Last name:             Solo
Purchased Amount:      $500.50
Purchased Date:        1/30/2016
Payment Amount:        $0.00
Visit Fee:             $5.00
 
 
Member Customer:
First name:            Darth
Last name:             Vader
Purchased Amount:      $300.55
Purchased Date:        2/6/2016
Payment Amount:        $0.00
Collected Points:      100
 
What action would you like to perform?
payment amount computed
What action would you like to perform?
 
Member Customer:
First name:            Luke
Last name:             Skywalker
Purchased Amount:      $355.24
Purchased Date:        3/14/2016
Payment Amount:        $319.72
Collected Points:      83
 
 
NonMember Customer:
First name:            Han
Last name:             Solo
Purchased Amount:      $500.50
Purchased Date:        1/30/2016
Payment Amount:        $505.50
Visit Fee:             $5.00
 
 
Member Customer:
First name:            Darth
Last name:             Vader
Purchased Amount:      $300.55
Purchased Date:        2/6/2016
Payment Amount:        $270.50
Collected Points:      103
 
What action would you like to perform?
 

Output3

Choice         Action
------         ------
A              Add Customer
C              Compute Payment Amount
D              Count Certain Customers
L              List Customers
Q              Quit
?              Display Help
 
What action would you like to perform?
Please enter some customer information to add:
What action would you like to perform?
Please enter some customer information to add:
What action would you like to perform?
Please enter some customer information to add:
What action would you like to perform?
 
Member Customer:
First name:            Harry
Last name:             Potter
Purchased Amount:      $50.23
Purchased Date:        1/21/2016
Payment Amount:        $0.00
Collected Points:      99
 
 
NonMember Customer:
First name:            Hermione
Last name:             Granger
Purchased Amount:      $640.23
Purchased Date:        2/20/2016
Payment Amount:        $0.00
Visit Fee:             $16.00
 
 
Member Customer:
First name:            Ron
Last name:             Weasley
Purchased Amount:      $400.32
Purchased Date:        1/20/2016
Payment Amount:        $0.00
Collected Points:      105
 
What action would you like to perform?
Please enter a purchased amount:
The number of customers who purchased more than $400.00 is: 2
What action would you like to perform?
Please enter a purchased amount:
The number of customers who purchased more than $500.23 is: 1
What action would you like to perform?
 

Output4

Choice         Action
------         ------
A              Add Customer
C              Compute Payment Amount
D              Count Certain Customers
L              List Customers
Q              Quit
?              Display Help
 
What action would you like to perform?
Please enter some customer information to add:
What action would you like to perform?
Please enter some customer information to add:
What action would you like to perform?
Please enter some customer information to add:
What action would you like to perform?
Please enter some customer information to add:
What action would you like to perform?
 
Member Customer:
First name:            Mickey
Last name:             Mouse
Purchased Amount:      $400.50
Purchased Date:        4/18/2016
Payment Amount:        $0.00
Collected Points:      98
 
 
Member Customer:
First name:            Donald
Last name:             Duck
Purchased Amount:      $200.50
Purchased Date:        4/20/2016
Payment Amount:        $0.00
Collected Points:      200
 
 
NonMember Customer:
First name:            Daisy
Last name:             Duck
Purchased Amount:      $300.50
Purchased Date:        1/2/2016
Payment Amount:        $0.00
Visit Fee:             $15.00
 
 
Member Customer:
First name:            Minnie
Last name:             Mouse
Purchased Amount:      $700.50
Purchased Date:        4/10/2016
Payment Amount:        $0.00
Collected Points:      300
 
What action would you like to perform?
Please enter a purchased amount:
The number of customers who purchased more than $100.10 is: 4
What action would you like to perform?
Please enter a purchased amount:
The number of customers who purchased more than $200.50 is: 3
What action would you like to perform?
Please enter a purchased amount:
The number of customers who purchased more than $200.49 is: 4
What action would you like to perform?
Please enter a purchased amount:
The number of customers who purchased more than $0.00 is: 4
What action would you like to perform?
payment amount computed
What action would you like to perform?
 
Member Customer:
First name:            Mickey
Last name:             Mouse
Purchased Amount:      $400.50
Purchased Date:        4/18/2016
Payment Amount:        $360.45
Collected Points:      102
 
 
Member Customer:
First name:            Donald
Last name:             Duck
Purchased Amount:      $200.50
Purchased Date:        4/20/2016
Payment Amount:        $160.40
Collected Points:      202
 
 
NonMember Customer:
First name:            Daisy
Last name:             Duck
Purchased Amount:      $300.50
Purchased Date:        1/2/2016
Payment Amount:        $315.50
Visit Fee:             $15.00
 
 
Member Customer:
First name:            Minnie
Last name:             Mouse
Purchased Amount:      $700.50
Purchased Date:        4/10/2016
Payment Amount:        $560.40
Collected Points:      307
 
What action would you like to perform?
Unknown action
What action would you like to perform?
Unknown action
What action would you like to perform?
Unknown action
What action would you like to perform?
Unknown action
What action would you like to perform?
 

 

More products