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

IN JAVA PLEASE Design a class named Person with private fields for that person’s

ID: 3719515 • Letter: I

Question

IN JAVA PLEASE

Design a class named Person with private fields for that person’s:

(1) name,

(2) email address

(3) telephone number

Write no-arg, 1-arg (name), 2-arg (name & address), 2-arg (name & phone), and 3-arg constructors; and a mutator and accessor method for each of the 3 fields.

Design a class named Customer which extends the Person class.

Customer class should have 2 additional private fields:

(1) customer idnumber

(2) Boolean value, reflecting consumer choice to be on email list.

Write constructors for Customer class, referencing the base class (default and 3-arg); and write appropriate mutator and accessor methods for all fields, parent and child.

Once the above tested and operating smoothly, then design a class named PreferredCustomer which extends the Customer class.

In addition to the fields in the Customer class, this class will also have the following:

(1) accumulated purchases to date

(2) discount level.

These are based on the following preferred customer rules:

? Once accumulated purchases exceed $500, a 5% discount applied to future purchases

? Once accumulated purchases exceed $1000, a 6% discount applied to future purchases

? Once accumulated purchases exceed $1500, a 7% discount applied to future purchases

? Once accumulated purchases exceed $2000, a 10% discount applied to future purchases

Write constructors for PreferredCustomer class and appropriate mutator and accessor methods for all fields, derived and base classes.

IN JAVA PLEASE

Explanation / Answer

Below is your code: -

PreferredCustomer.java

public class PreferredCustomer extends Customer {

double purchase;

double discount;

// Constructor

public PreferredCustomer(String name, String address, long telephoneNumber, String customerNumber,

boolean mailingList, double purchase) {

super(name, address, telephoneNumber, customerNumber, mailingList);

this.purchase = purchase;

// "setDiscount" method

if (purchase >= 2000)

setDiscount(10);

else if (purchase > 1500)

setDiscount(7);

else if (purchase > 1000)

setDiscount(6);

else if (purchase > 500)

setDiscount(5);

}

// "setPurchase" stores the parameter value "setPurchase"

public void setPurchase(double purchase) {

this.purchase = purchase;

}

// "setPurchase" stores the parameter value "setPurchase"

private void setDiscount(double discount) {

this.discount = discount;

}

// "getPurchase" returns purchase value

public double getPurchase() {

return purchase;

}

// "getDiscount" returns discount value

public double getDiscount() {

return discount;

}

public String toString() {

String preferredCustomer = super.toString() + " Purchase" + getPurchase() + " Discount " + getDiscount();

return preferredCustomer;

}

}

Customer.java

public class Customer extends Person {

String customerNumber;

boolean mailingList;

public Customer() {

super();

this.customerNumber = "";

this.mailingList = false;

}

// Constructors

public Customer(String name, String address, long telephoneNumber, String customerNumber, boolean mailingList) {

super(name, address, telephoneNumber);

this.customerNumber = customerNumber;

this.mailingList = mailingList;

}

// "setCustomerNumber" stores the parameter value "customerNumber"

public void setCustomerNumber(String customerNumber) {

this.customerNumber = customerNumber;

}

// "setMailOnOff" stores the parameter value for "mailingList"

public void setMailOnOff(boolean mailingList) {

this.mailingList = mailingList;

}

// "getMailOnOff" returns the parameter value "mailingList"

public boolean getMailOnOff() {

return mailingList;

}

// "getCustomerNumber" returns the parameter value "customerNumber"

public String getCustomerNumber() {

return customerNumber;

}

public String toString() {

String customer = super.toString() + " Customer Number: " + getCustomerNumber() + " Customer MailList: "

+ getMailOnOff();

return customer;

}

}

Person.java

public class Person {

// Members of the class person

String name;

String address;

long telephoneNumber;

// Constructors for the data members

public Person(String name, String address, long telephoneNumber) {

this.name = name;

this.address = address;

this.telephoneNumber = telephoneNumber;

}

// Default Constructor

public Person() {

this.name = "";

this.address = "";

this.telephoneNumber = 0;

}

// 1 arg Constructor

public Person(String name) {

this.name = name;

this.address = "";

this.telephoneNumber = 0;

}

// 2 arg Constructor

public Person(String name, String address) {

this.name = name;

this.address = address;

this.telephoneNumber = 0;

}

// 2 arg Constructor

public Person(String name, long telephone) {

this.name = name;

this.address = "";

this.telephoneNumber = telephone;

}

// "setName" stores the parameter "name"

public void setName(String name) {

this.name = name;

}

// "setAddress" stores the parameter "address"

public void setAddress(String address) {

this.address = address;

}

// "setTelephoneNumber" stores the parameter value for "telephoneNumber"

public void setTelephoneNumber(long telephoneNumber) {

this.telephoneNumber = telephoneNumber;

}

// "getName" returns the parameter value "name"

public String getName() {

return name;

}

// "getAddress" returns the parameter value "address"

public String getAddress() {

return address;

}

// "getPhoneNumber" returns the parameter value "telephoneNumber"

public long getPhoneNumber() {

return telephoneNumber;

}

public String toString() {

String person = "Name: " + getName() + " Address: " + getAddress() + " PhoneNumber: " + getPhoneNumber();

return person;

}

}