JAVA PROGRAMMING HELP! Design a class named Person with fields for holding a per
ID: 3865680 • Letter: J
Question
JAVA PROGRAMMING HELP!
Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the mutator and accessor methods for the fields, along with a toString( ) method.
Next, design a class named Customer, which inherits from the Person class, The Customer class should have a field for a customer id number and a boolean field indicating if the customer wishes to be on the mailing list. Write one or more constructors and the appropriate mutor and accessor methods for this class. Write a toString( ) method that also calls the super( ) toString method.
• A retail store has a preferred customer plan where customers can earn discounts on all their purchases. The amount of the customer’s discout is determined by the amount of the customers 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 $1,000, he or she gets a 6% discount on all future purchases. • When a preferred customer spends $1,500, he or she get a 7% on all future purchases. • When a preferred customer spends $2,000 or more, he or she gets a %10 discount on all future purchases.
Design a class named PreferredCustomer, which inherits from the Customer class. The PreferredCustomer should have fields for the amount of the customer’s purchases and the customer’s discount level. Write one or more constructors and the mutator and accessor methods along with a toString( ) method that calls the super toString( ) method.
Create a Driver class that creates an array of four Persons. Populate the array with Customers and PreferredCustomer object references. Test the classes you wrote by calling the methods and displaying the results.
Explanation / Answer
Person.java
====
public class Person {
private String name;
private String address;
private String telephone;
public Person(String name, String address, String telephone) {
this.name = name;
this.address = address;
this.telephone = telephone;
}
/* Mutators */
// name
public void setName(String name) {
this.name = name;
}
// address
public void setAddress(String address) {
this.address = address;
}
// telephone
public void setTelephone(String telephone) {
this.telephone = telephone;
}
/* Accessors */
// name
public String getName() {
return this.name;
}
// address
public String setAddress() {
return this.address;
}
// telephone
public String setTelephone() {
return this.telephone;
}
public String toString() {
return
this.name + ", " +
this.address + ", " +
this.telephone + ".";
}
}
Customer.java
====
public class Customer extends Person {
private int customerId;
private boolean subscribed;
public Customer(
String name, String address,
String telephone, int customerId,
boolean subscribed ) {
// initiate super class constructor.
super(name, address, telephone);
this.customerId = customerId;
this.subscribed = subscribed;
}
public String toString() {
super.toString();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.