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

Customer class: Customer is an abstract class, which represents the basic attrib

ID: 3663984 • Letter: C

Question

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. The attributes (should be protected).

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.

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.

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

The assignment5 program was given by the instructor

Explanation / Answer

Customer.java(Abstract class)

abstract class Customer {

   public Customer(String fName, String lName, double amount, int year,
           int month, int date) {
       firstName = fName;
       lastName = lName;
       purchasedAmount = amount;
       purchasedYear = year;
       purchasedMonth = month;
       purchasedDate = date;

       paymentAmount = 0.0;
   }

   protected String firstName;
   protected String lastName;
   protected double purchasedAmount;
   protected int purchasedYear;
   protected int purchasedMonth;
   protected int purchasedDate;

   protected double paymentAmount;

   public double getPaymentAmount() {
       return paymentAmount;
   }

   public abstract void computePaymentAmount();

   public String toString() {
      
       String s = "First name " + firstName + " ";
       s += "Last name " + lastName + " ";
       s += "Purchased Amount: $" + purchasedAmount + " ";
       s += "Purchased Date " + purchasedMonth + "/" + "purchasedDate" + "/"
               + purchasedYear + " ";
       s += "Payment Amount " + paymentAmount + " ";
      
       return s;
   }

}

NonMemberCustomer.java


public class NonMemberCustomer extends Customer {

  
   protected double visitFee;
  
   public NonMemberCustomer(String fName, String lName, double amount, int year, int month, int date, double fee)
   {
       super(fName,lName,amount,year,month,date);
       visitFee=fee;
   }

   @Override
   public void computePaymentAmount()
   {
       paymentAmount=purchasedAmount+visitFee;
   }
  
   public String toString()
   {
       String s="NonMember Customer ";
       s+=super.toString();
       s+="Visit Fee $"+visitFee+" ";
       return s;
   }

}

MemberCustomer.java


public class MemberCustomer extends Customer {

   protected int pointsCollected;
  
   public MemberCustomer(String fName, String lName, double amount, int year, int month, int date, int points) {
      
       super(fName,lName,amount,year,month,date);
       pointsCollected=points;
   }

   @Override
   public void computePaymentAmount()
   {
       if(pointsCollected>100)
       {
           paymentAmount=purchasedAmount*0.8;
       }
       else
       {
           paymentAmount=purchasedAmount*0.9;
       }
      
       pointsCollected+=purchasedAmount*0.01;
   }
  
   public String toString()
   {
       String s="Member Customer: ";
       s+=super.toString();
       s+="Collected Points "+pointsCollected+" ";
       return s;
   }

}

CustomerParser.java


public class CustomerParser {

   public static Customer parseStringToCustomer(String lineToParse)
   {
       String s[]=lineToParse.split("/");
      
       String type=s[0];
       String fName=s[1];
       String lName=s[2];
       double amount=Double.parseDouble(s[3]);
       int year=Integer.parseInt(s[4]);
       int month=Integer.parseInt(s[5]);
       int date=Integer.parseInt(s[6]);
      
       if(type.equalsIgnoreCase("NonMember"))
       {
           double fee=Double.parseDouble(s[7]);
           NonMemberCustomer customer=new NonMemberCustomer(fName,lName,amount,year,month,date,fee);
           return customer;
       }
       else if(type.equalsIgnoreCase("Member"))
       {
           int points=Integer.parseInt(s[7]);
           MemberCustomer customer=new MemberCustomer(fName,lName,amount,year,month,date,points);
           return customer;
       }
       return null;
      
   }
  
}

Test.java(I used it to test my code)


public class Test {

   public Test() {
       // TODO Auto-generated constructor stub
   }

   public static void main(String[] args) {
      
       String nonmember="NonMember/Mickey/Mouse/1000.30/2016/1/15/10.00";
       String member="Member/Donald/Duck/500.50/2016/1/16/99";
      
       Customer nm=CustomerParser.parseStringToCustomer(nonmember);
       Customer m=CustomerParser.parseStringToCustomer(member);
      
       nm.computePaymentAmount();
       m.computePaymentAmount();
      
       System.out.println(nm.toString());
       System.out.println(m.toString());

   }

}

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