Question
8. PreferredCustomer Class A retail store has a preferred customer plan where customers can earn discounts on all their purchases. The amount of a customers
8. PreferredCustomer Class A retail store has a preferred customer plan where customers can earn discounts on all their purchases. The amount of a customers discount 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 gets a 7% discount 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 you created in Programming Challenge 7.
The PreferredCustomer class should have fields for the amount of the customers purchases and the customers discount level. Write one or more constructors and the appropriate mutator and accessor methods for the classs fields. Demonstrate the class in a simple program.
// chapter 7 code
import java.io.*;
import java.util.Scanner;
class Person {
// fields
private String person_name;
private String person_address;
private String person_telnum;
// Constructors
public Person(String person_name, String person_address, String person_telnum)
{
setName(person_name);
setAddress(person_address);
setTelephoneNumber(person_telnum);
}
// accessors function--
public String getName()
{
return person_name;
}
public String getAddress()
{
return person_address;
}
public String getTelephoneNumber()
{
return person_telnum;
}
// mutator function
public void setName(String n)
{
person_name = n;
}
public void setTelephoneNumber(String a)
{
person_telnum = a;
}
public void setAddress(String a)
{
person_address = a;
}
}
// customer class
class Customer extends Person
{
private static final String Cust_number = null;
private int cust_number;
private boolean cust_mailingList;
// Constructors
public Customer(String person_name, String person_address, String person_telnum, int cust_number,
boolean mailingList)
{
super(person_name, person_address, person_telnum);
setCusNumber(cust_number);
setMailList(mailingList);
}
public int getCusNumber() {
return cust_number;
}
public boolean getMailList()
{
return cust_mailingList;
}
public void setCusNumber(int n)
{
cust_number = n;
}
public void setMailList(boolean l)
{
cust_mailingList = l;
}
public String toString()
{
return "Cust Name: " + getName() + " Cust ID:" + Cust_number + " Tlelephone Number: " + getTelephoneNumber()
+ " Mail List:" + cust_mailingList;
}
}// end customer class
// personCustomer class
public class personCustomer
{
public static void main(String[] args)
{
String name, addr, tel;
int id;
// create scanner object
Scanner Keyboard = new Scanner(System.in);
// inputting date
System.out.println("Enter customer Name: ");
name = Keyboard.nextLine();
System.out.println("Enter customer Address: ");
addr = Keyboard.nextLine();
System.out.println("Enter customer Telephone: ");
tel = Keyboard.nextLine();
System.out.println("Enter custID: ");
id = Keyboard.nextInt();
boolean val = true;
Customer c = new Customer(name, addr, tel, id, val);
System.out.println(c);
}
}
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