Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are required, but not limited, to turn in the following source files: Assign

ID: 3664593 • Letter: Y

Question

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

HERE IS Assignment5.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 beprotected):

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:

First name: Elvis
Last name: Presley
Purchased Amount: $300.50
Purchased Date: 1/15/2016
Payment Amount: $0.00

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:

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:

NonMember Customer:
First name: Elvis
Last name: Presley
Purchased Amount: $300.50
Purchased Date: 1/15/2016
Payment Amount: $0.00
Visit Fee: $10.00

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:

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:

Member Customer:
First name: Elvis
Last name: Presley
Purchased Amount: $300.50
Purchased Date: 1/15/2016
Payment Amount: $0.00
Collected Points: 80

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 isNonMember 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 Action
------ ------
A Add Customer
C Compute Payment Amount
D Count Certain Customers
L List Customers
Q Quit
? Display Help

Next, the following prompt should be displayed:

What action would you like to perform?

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:

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

Search for Customer

Your program should display the following prompt:

Please enter a purchased amount:

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

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

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

Input

The following files are the test cases that will be used as input for your program (Right-click and use "Save As"):

Input Test Case #1:

Input Test Case #2:

Output

The following files are the expected outputs of the corresponding input files from the previous section (Right-click and use "Save As"):

Output Test Case #1:

Output Test Case #2:

Output Test Case #3:

Output Test Case #4:

AND THEN HERE IS Assignment5.java (again):

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

Explanation / Answer

package assignment5;

// Assignment #: 5

// Arizona State University - CSE205

//         Name: Your name

//    StudentID: Your id

//      Lecture: Your lecture time (for instance, MWF 10:40am)

// Description: The Assignment 5 class displays a menu of choices

//               (add a member or non-member customer,

//               compute their payment amount, count certain students,

//               list students, quit, display menu) to a user.

//               Then it performs the chosen task. It will keep asking a user to

//               enter the next choice until the choice of 'Q' (Quit) is

//               entered.

import java.io.*;         //to use InputStreamReader and BufferedReader

import java.util.*;       //to use ArrayList

import java.text.NumberFormat;

public class Assignment5

{

public static void main (String[] args)

   {

     char input1;

     String inputInfo = new String();

     String line = new String();

     boolean operation;

     // ArrayList object is used to store customer objects

     ArrayList customerList = new ArrayList();

     try

      {

       printMenu();     // print out menu

       // create a BufferedReader object to read input from a keyboard

       InputStreamReader isr = new InputStreamReader (System.in);

       BufferedReader stdin = new BufferedReader (isr);

       do

        {

         System.out.println("What action would you like to perform?");

         line = stdin.readLine().trim();

         input1 = line.charAt(0);

         input1 = Character.toUpperCase(input1);

         if (line.length() == 1)

          {

           switch (input1)

            {

             case 'A':   //Add Customer

               System.out.print("Please enter some customer information to add: ");

               inputInfo = stdin.readLine().trim();

/***********************************************************************************

*** ADD your code here to create an object of one of child classes of Customer class

*** and add it to the customerList

***********************************************************************************/

               CustomerParser CP=new CustomerParser();

               Customer C=CustomerParser.parseStringToCustomer(inputInfo);

               customerList.add(C);

               break;

             case 'C':   //Compute Payment Amount

/***********************************************************************************

*** ADD your code here to compute the payment amount for all customers the customerList.

***********************************************************************************/

               for(int i=0;i<customerList.size();i++)

               {

                   Customer CC=(Customer)customerList.get(i);

                   CC.computePaymentAmount();

               }

               System.out.print("payment amount computed ");

               break;

             case 'D':   //Count certain customers

               System.out.print("Please enter a purchased amount: ");

               inputInfo = stdin.readLine().trim();

               double amount = Double.parseDouble(inputInfo);

               int count = 0;

/***********************************************************************************

*** ADD your code here to count the number of customers who purchased more than the specified amount.

***********************************************************************************/

               for(int i=0;i<customerList.size();i++)

               {

                  Customer CC=(Customer)customerList.get(i);

                   if(CC.getPurchasedAmount()>amount)

                   {

                       count++;

                   }

               }

                NumberFormat money = NumberFormat.getCurrencyInstance();

                System.out.println("The number of customers who purchased more than " + money.format(amount)

                                 + " is: " + count);

               break;

             case 'L':   //List Customers

/***********************************************************************************

*** ADD your code here to print out all customer objects. If there is no customer,

*** print "no customer "

***********************************************************************************/

                 if(customerList.size()==0)

                 {

                     System.out.println("No Customers");

                 }

             else

                 {

                  for(int i=0;i<customerList.size();i++)

               {

                   Customer CC=(Customer)customerList.get(i);

                   System.out.println(" "+CC.toString());

               }  

                 }

               break;

             case 'Q':   //Quit

               break;

             case '?':   //Display Menu

               printMenu();

               break;

             default:

               System.out.print("Unknown action ");

               break;

            }

         }

        else

         {

           System.out.print("Unknown action ");

          }

        } while (input1 != 'Q'); // stop the loop when Q is read

      }

     catch (IOException exception)

      {

        System.out.println("IO Exception");

      }

}

/** The method printMenu displays the menu to a user **/

public static void printMenu()

   {

     System.out.print("Choice Action " +

                      "------ ------ " +

                      "A Add Customer " +

                     "C Compute Payment Amount " +

                      "D Count Certain Customers " +

                      "L List Customers " +

                      "Q Quit " +

                      "? Display Help ");

}

}

/*-------------------------------------------------------------------------------------------*/

package assignment5;

//Customer.java

public abstract class Customer {

    String firstName;

    String lastName;

    String studentID;

    double purchasedAmount;

    int purchasedYear;

    int purchasedMonth;

    int purchasedDate;

    double paymentAmount;

    public Customer(String first, String last, double purAmount,int year, int month, int day)

    {

        firstName=first;

        lastName=last;

        purchasedAmount=purAmount;

        purchasedYear=year;

        purchasedMonth=month;

        purchasedDate=day;

        paymentAmount=0.0;

    }

    double getPurchasedAmount()

    {

        return purchasedAmount;

    }

    public abstract void computePaymentAmount();

    public String toString()

    {

     String op="Name: "+firstName+" "+lastName+" ";

     op+=" Purchased amount: "+purchasedAmount+" ";

     op+=" purchased Date: "+purchasedDate+"/"+purchasedMonth+"/"+purchasedYear+" ";

     return op;

    }

}

/*----------------------------------------------------------------------------------*/   

package assignment5;

// NonMemberCustomer.java

public class NonMemberCustomer extends Customer{

    double visitFee;

    public NonMemberCustomer(String first, String last, double purAmount, int year, int month, int day, double vFee) {

        super(first, last, purAmount, year, month, day);

        visitFee=vFee;

   }

    @Override

    public void computePaymentAmount()

    {

        paymentAmount=visitFee+getPurchasedAmount();

    }

    @Override

    public String toString()

    {

        String op=super.toString();

        op+=" Visit Fee: "+visitFee;

        return op;

    }

}

/*----------------------------------------------------------------------------------*/   

package assignment5;

//MemberCustomer.java

public class MemberCustomer extends Customer {

    static int pointsCollected;

    public MemberCustomer(String first, String last, double purAmount, int year, int month, int day, int points) {

        super(first, last, purAmount, year, month, day);

        pointsCollected=points;

    }

    @Override

    public void computePaymentAmount() {

        if(pointsCollected>100)

        {

            purchasedAmount *= 0.8;

        }

        else

        {

            purchasedAmount *= 0.9;

        }

        pointsCollected=(int) (purchasedAmount*(0.01));

    }

    @Override

    public String toString()

    {

        String op=super.toString();

        op+=" Points Collected: "+pointsCollected;

        return op;

    }

}

/*----------------------------------------------------------------------------------*/   

package assignment5;

// CustomerParser.java

public class CustomerParser {

    public CustomerParser(){}

    public static Customer parseStringToCustomer(String lineToParse)

    {

        String Array[]=lineToParse.split("/");

        Customer C=null;

        if(Array[0].equalsIgnoreCase("Member"))

        {

           C=new MemberCustomer(Array[1],Array[2],Double.parseDouble(Array[3]),

           Integer.parseInt(Array[4]),Integer.parseInt(Array[5]),

           Integer.parseInt(Array[6]),Integer.parseInt(Array[7]));

        }

        else

        {

           C=new NonMemberCustomer(Array[1],Array[2],Double.parseDouble(Array[3]),

           Integer.parseInt(Array[4]),Integer.parseInt(Array[5]),

           Integer.parseInt(Array[6]),Integer.parseInt(Array[7]));

        }

        return C;

    }

}

/*----------------------------------------------------------------------------------*/   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote