Question: Design a class named Person with fields for holding a person\'s name,
ID: 3631977 • Letter: Q
Question
Question:
Design a class named Person with fields for holding a person's name, address and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class's fields. Next, design a class named Customer , which inherits from the Person class. The customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and accessor methods for the class's fields.
A retail store has a preferred 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 preferred customer spends $500, he or she gets a 5% discount on all future purchases.
- When a preferred customer spends $1000, he or she gets a 6% discount on all future purchases.
- When a preferred customer spends $1500, he or she gets a 7% discount on all future purchases.
- When a preferred customer spends $2000, he or she gets a 10% discount on all future purchases.
Design a class named PreferredCustomer, which inherits from the customer class. The PreferredCustomer class should have fields for the amount of the customer's purchases and the customer's discount level. Write one or more constructors and the appropriate mutator and accessor methods for the class's fields.
Explanation / Answer
public class clsPerson { //private fields private String name="", address="", telephone=""; public clsPerson() { name=""; address=""; telephone=""; } //constructor methods public clsPerson(String name, String address, String telephone) { this.name = name; this.address = address; this.telephone = telephone; } //Accessor for name public String getName() { return name; } //Accessor for address public String getAddress() { return address; } //Accessor for telephone number public String getNumber() { return telephone; } //Mutator for name public void setName(String name) { this.name = name; } //Mutator for address public void setAddress(String address) { this.address = address; } //Mutator for telephone number public void setTelephone(String telephone) { this.telephone = telephone; } } ***************************************************************************************** //class for Customer public class clsCustomer extends clsPerson { //private fields private String customerNumber=""; private boolean mailOption = false; public clsCustomer() { customerNumber=""; mailOption=false; } //constructor methods public clsCustomer(String customerNumber, boolean mailOption) { this.customerNumber = customerNumber; this.mailOption = mailOption; } //Accessor for customer number public String getCustomerNumber() { return customerNumber; } //Mutator for customer number public void setCustomerNumber(String customerNumber) { this.customerNumber = customerNumber; } //Accessor for mailOption public boolean isMailOption() { return mailOption; } //Mutator for mail option public void setMailOption(boolean mailOption) { this.mailOption = mailOption; } } ***************************************************************************** //class for preferred customer public class clsPreferredCustomer extends clsCustomer { private double purchaseAmount=0, discountAmount=0; public clsPreferredCustomer() { purchaseAmount=0; discountAmount=0; } //constructor methods public clsPreferredCustomer(double purchaseAmount, double discountAmount) { this.purchaseAmount = purchaseAmount; this.discountAmount = discountAmount; } public double getDiscountAmount() { return discountAmount; } public void setDiscountAmount(double discountAmount) { this.discountAmount = discountAmount; } public double getPurchaseAmount() { return purchaseAmount; } public void setPurchaseAmount(double purchaseAmount) { this.purchaseAmount = purchaseAmount; } } ******************************************************************************** // class for main public class store { public static void main(String[] args) { clsPreferredCustomer customer1 = new clsPreferredCustomer("NameCustomer1", "Street ABC", "1234567899", "ID001", true, 500, 0.05); System.out.println(customer1.getName() + " " + customer1.getAddress() + " " + customer1.getTelephone() + " " + customer1.getCustomerNumber() + " " + customer1.getMailOption().toString() + " " + customer1.getPurchaseAmount().toString() + " " + customer1.getDiscountAmount().toString()); } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.