Question
Write a class named SpecialCustomer, which inherits from the Customer class. The SpecialCustomer class should have int fields for the amount of the customer's purchases
Write a class named SpecialCustomer, which inherits from the Customer class. The SpecialCustomer class should have int fields for the amount of the customer's purchases and the customer's discount level.
A retail store has a special customer plan where customers can earn discounts on all their purchases. The amount of a customer's discount is determined by the amount of the customer's cumulative purchases in the store, as follows:
When a special customer spends $500, they get 5% discount on all future purchases.
When a special customer spends $1,000, they get 8% discount on all future purchases.
When a special customer spends $1,500, they get a 10% discount on all future purchases
When a special customer spends $2,000, they get a 15% discount on all future purchases
Write a constructor that initializes the fields of the SpecialCustomer class and define accessor and mutator methods. Use super keyword in the subclass constructor, if needed.
Demonstrate the class by defining a CustomerDemo class that prompts the user to input the customer's name, address, phone number, customer number, whether they want to receive mail, and the amount they've spent, and then uses that information to create a SpecialCustomer object and print its information (for printing the information, you may need toString() method).
Create a UML diagram that shows all three classes and the inheritance relationship between these classes.
Person.java-
public class Customer extends Person { private String customerNumber; // Customer number private boolean mailingList; // Add to mailing list? /** The no-arg constructor initializes the object with empty strings for name, address, phone, and customerNumber. The mailingList field is set to false. */ public Customer() { super(); customerNumber = ""; mailingList = false; } /** This constructor initializes the object with a name, address, a phone number, a customer number, and mailing list status. @param n The name. @param a The address. @param p The phone number. @param c The customer number. @param m Mailing list status (true = yes, false = no). */ public Customer(String n, String a, String p, String c, boolean m) { super(n, a, p); customerNumber = c; mailingList = m; } /** The setCustomerNumber method sets the customerNumber field. @param c The customer number to use. */ public void setCustomerNumber(String c) { customerNumber = c; } /** The setMailingList method sets the mailing list status. @param m The mailing list status (true = add to mailing list, false = do not add to mailing list). */ public void setMailingList(boolean m) { mailingList = m; } /** The getCustomerNumber method retrns the customer number. @return The customer number. */ public String getCustomerNumber() { return customerNumber; } /** The getMailingList method retrns the mailing list status. @return The mailing list status. */ public boolean getMailingList() { return mailingList; } }
Customer.Java-
public class Customer extends Person { private String customerNumber; // Customer number private boolean mailingList; // Add to mailing list? /** The no-arg constructor initializes the object with empty strings for name, address, phone, and customerNumber. The mailingList field is set to false. */ public Customer() { super(); customerNumber = ""; mailingList = false; } /** This constructor initializes the object with a name, address, a phone number, a customer number, and mailing list status. @param n The name. @param a The address. @param p The phone number. @param c The customer number. @param m Mailing list status (true = yes, false = no). */ public Customer(String n, String a, String p, String c, boolean m) { super(n, a, p); customerNumber = c; mailingList = m; } /** The setCustomerNumber method sets the customerNumber field. @param c The customer number to use. */ public void setCustomerNumber(String c) { customerNumber = c; } /** The setMailingList method sets the mailing list status. @param m The mailing list status (true = add to mailing list, false = do not add to mailing list). */ public void setMailingList(boolean m) { mailingList = m; } /** The getCustomerNumber method retrns the customer number. @return The customer number. */ public String getCustomerNumber() { return customerNumber; } /** The getMailingList method retrns the mailing list status. @return The mailing list status. */ public boolean getMailingList() { return mailingList; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started