Project: Person. Customer and PreferredCustomer Class Design a class named Perso
ID: 3699512 • Letter: P
Question
Project: Person. Customer and PreferredCustomer Class 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 extends 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: all future purchases. all future purchases all future purchases. discount on all future purchases. When a preferred customer spends $500, he or she gets a 5 percent discount on When a preferred customer spends $1,000, he or she gets a 6 percent discount on When a preferred customer spends $1,500, he or she gets a 7 percent discount on When a preferred customer spends $2,000 or more, he or she gets a 10 percent Design a class named PreferredCustomer, which extends 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. Demonstrate the class in a simpleExplanation / Answer
// Person.java file
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;
}
public String getTelephone()
{
return telephone;
}
public void setTelephone(String telephone)
{
this.telephone = telephone;
}
public String getAddress()
{
return address;
}
public void setAddress(String address)
{
this.address = address;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
// Customer.java file
public class Customer extends Person
{
private String number;
private boolean>
public Customer(String name, String address, String telephone, String number, boolean onMailingList)
{
super(name, address, telephone);
this.number = number;
this.onMailingList = onMailingList;
}
public String getNumber()
{
return number;
}
public void setNumber(String number)
{
this.number = number;
}
public boolean isOnMailingList()
{
return onMailingList;
}
public void setOnMailingList(boolean onMailingList)
{
this.onMailingList = onMailingList;
}
}
// PreferredCustomer.java file
public class PreferredCustomer extends Customer
{
private int amount;
private int discountLevel;
public PreferredCustomer(String name, String address, String telephone, String number, boolean onMailingList, int amount, int discountLevel)
{
super(name, address, telephone, number, onMailingList);
this.amount = amount;
this.discountLevel = discountLevel;
}
public int getAmount()
{
return amount;
}
public void setAmount(int amount)
{
this.amount = amount;
}
public int getDiscountLevel()
{
return discountLevel;
}
public void setDiscountLevel(int discountLevel)
{
this.discountLevel = discountLevel;
}
}
// Main.java file
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
List<PreferredCustomer> pcustomers = new ArrayList<PreferredCustomer>();
for(int i = 0; true; i++)
{
String name, address, telephone, number;
boolean onMailingList;
int amount, discountLevel = 0;
System.out.println("Customer #" + i + " " +
"------------");
System.out.print("Name: ");
name = scanner.next();
System.out.print("Address: ");
address = scanner.next();
System.out.print("Telephone: ");
telephone = scanner.next();
System.out.print("Customer number: ");
number = scanner.next();
System.out.print("On mailing list (true or false): ");
>
System.out.print("Amount: ");
amount = scanner.nextInt();
if (amount == 500)
{
discountLevel = 5;
}
else if (amount == 1000)
{
discountLevel = 6;
}
else if (amount == 1500)
{
discountLevel = 7;
}
else if (amount >= 2000)
{
discountLevel = 10;
}
pcustomers.add(new PreferredCustomer(name, address, telephone, number, onMailingList, amount, discountLevel));
System.out.print("Add another preferred customer (true or false): ");
if(!scanner.nextBoolean())
{
break;
}
System.out.println();
}
for(PreferredCustomer pcustomer : pcustomers)
{
System.out.println(" Customer Number " + pcustomer.getNumber() + " " +
"---------------------- " +
"Name: " + pcustomer.getName() + " " +
"Address: " + pcustomer.getAddress() + " " +
"Telephone: " + pcustomer.getTelephone() + " " +
"On mailing list: " + pcustomer.isOnMailingList() + " " +
"Amount: " + pcustomer.getAmount() + " " +
"Discount level: " + pcustomer.getDiscountLevel());
}
}
}
// Output
> javac Person.java
> javac Customer.java
> javac PreferredCustomer.java
> javac Main.java
> java Main
Customer #0
------------
Name: Harish
Address: Vizag
Telephone: 9876543210
Customer number: 123
On mailing list (true or false): true
Amount: 1000
Add another preferred customer (true or false): true
Customer #1
------------
Name: Ram
Address: Pune
Telephone: 7894561230
Customer number: 258
On mailing list (true or false): false
Amount: 2500
Add another preferred customer (true or false): false
Customer Number 123
----------------------
Name: Harish
Address: Vizag
Telephone: 9876543210
On mailing list: true
Amount: 1000
Discount level: 6
Customer Number 258
----------------------
Name: Ram
Address: Pune
Telephone: 7894561230
On mailing list: false
Amount: 2500
Discount level: 10
################## If any doubts please ask me ####################
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.