A retail store has a preferred customer plan where customers can earn discounts
ID: 3779315 • Letter: A
Question
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, they get a 5% discount on all future purchases When a preferred customer spends $1,000, they get a 6% discount on a future purchases When a preferred customer spends $1,5000, they get a 7% discount on all future purchases When a preferred customer spends $2,000, they get a 10% discount on all future purchases Design a class named PreferredCustomer, which inherits from the Customer class you created in Exercise 7. The preferredCustomer class should have int fields for the amount of the customer's purchases and the customer's discount level Write a constructor that initializes these fields as well as accessor and mutator methods. Desmonstrate the class in a program that prompts the user to input the customer's name address, phone number, customer number, whether they want to recieve mail, and the amount they've spent, and then uses that information to create a PreferredCustomer object and print its information. (Use string formatting to print the amount spent.)Explanation / Answer
class Class
{
String name,address,mobile,cid,email;
Scanner in=new Scanner(System.in);
}
class preferredCustomer extends Class
{
int amount,discount;
preferredCustomer()
{
amount=0;
discount=0;
}
void setDetails()
{
System.out.println("Enter-name-of -the-customer:");
name=in.nextLine();
System.out.println("Enter-address-of-the-customer:");
address=in.nextLine();
System.out.println("Enter-phone-number-of-the-customer:");
mobile=in.nextLine();
System.out.println("Enter-customer-number");
cid=in.nextLine();
System.out.println("Enter-yes/no-------does-the-customer-want-to-receive-mail?-:");
email=in.nextLine();
}
void setAmount()
{
System.out.println("Enter_amount_customer_has_spend: ");
amount=in.nextInt();
}
void setDiscount()
{
if(amount>2000)
discount=10;
else if(amount>1500)
discount=7;
else if(amount>1000)
discount=6;
else if(amount>500)
discount=5;
}
void getAmount()
{
System.out.println("amount-purchased: "+amount);
}
void getDiscount()
{
System.out.println("Percent off: "+discount+"%");
}
void getDetails()
{ int i;
System.out.println("Customer:-");
i=in.nextInt();//this is just to wait until user presses enter and then display next line of output
System.out.println("name:"+name);
i=in.nextInt();
System.out.println("Address:"+address);
i=in.nextInt();
System.out.println("Phone_number:"+mobile);
i=in.nextInt();
System.out.println("Customer-number"+cid);
i=in.nextInt();
System.out.println("Receive-mail?:");
if(email.equals("yes"))
System.out.print("true");
if(email.equals("no"))
System.out.print("false");
i=in.nextInt();
System.out.println("Amount-purchased:$"+amount);
i=in.nextInt();
System.out.println("Percent-off:"+discount+"%");
}
}
class mainClass
{
public static void main(String args)
{
preferredCustomer p=new preferredCustomer();
p.setDetails();
p.setAmount();
p.setDiscount();
p.getDetails();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.