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

***JAVA Program*** A retail store has a preferred customer plan where customers

ID: 3790628 • Letter: #

Question

***JAVA Program***

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 all
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.)

Create all of the classes in the same file by not delcaring any of them public.

SAMPLE RUN #1: java Driver

Expected outcome results:

Explanation / Answer

//Customer.java

public class Customer { // Customer Class

   String cName,cAddress,cPhone,cNo; // Attributes
   boolean email;
   double amount;
  

//Constructor with all parameters
   public Customer(String cName,String cAddress,String cPhone,String cNo,boolean email,double amount){
       this.cName = cName; // this accessing the current value
       this.cAddress = cAddress;
       this.cPhone = cPhone;
       this.email = email;
       this.amount = amount;
   }

//Setters and getters

   public String getcName() {
       return cName;
   }

   public void setcName(String cName) {
       this.cName = cName;
   }

   public String getcAddress() {
       return cAddress;
   }

   public void setcAddress(String cAddress) {
       this.cAddress = cAddress;
   }

   public String getcPhone() {
       return cPhone;
   }

   public void setcPhone(String cPhone) {
       this.cPhone = cPhone;
   }

   public String getcNo() {
       return cNo;
   }

   public void setcNo(String cNo) {
       this.cNo = cNo;
   }

   public boolean isEmail() {
       return email;
   }

   public void setEmail(boolean email) {
       this.email = email;
   }

   public double getAmount() {
       return amount;
   }

   public void setAmount(double amount) {
       this.amount = amount;
   }
  
  
}

//PreferredCustomer.java

import java.util.Scanner;


public class PrefferedCustomer extends Customer{ // Inheritance relationship

   public PrefferedCustomer(String cName, String cAddress, String cPhone,
           String cNo, boolean email, double amount) {
       super(cName, cAddress, cPhone, cNo, email, amount); // Calling Super class Constructor
   }

   public static void main(String[] args) {
  
       String cName,cAddress,cNo,cPhone; // Local Variables
       boolean email;
       double amount;
       String discount;
      
       Scanner s = new Scanner(System.in); // Reading Values
      
       System.out.println("Enter Customer Name");
       cName = s.next();
       System.out.println("Enter Customer Address");
       cAddress = s.next();
       System.out.println("Enter Customer Phone");
       cPhone = s.next();
       System.out.println("Enter Customer No");
       cNo = s.next();
       System.out.println("Does Customer has Email:(TRUE/FALSE)");
       email = s.nextBoolean();
       System.out.println("Enter the amount purchased:");
       amount = s.nextDouble();
      
       PrefferedCustomer pc = new PrefferedCustomer(cName, cAddress, cPhone, cNo, email, amount);
// Conditional Statement
       if(amount==500){
           discount = "5%";
       }else if(amount==1000){
           discount = "6%";
       }else if(amount==1500){
           discount = "7%";
       }else {
           discount = "10%";
       }
       System.out.println("*****************************");
       System.out.println("Customer Name:"+pc.getcName());
       System.out.println("Customer Address:"+pc.getcAddress());
       System.out.println("Customer Phone:"+pc.getcPhone());
       System.out.println("Customer Number:"+pc.getcNo());
       System.out.println("Customer Email:"+pc.isEmail());
       System.out.println("Purchased Amount is:"+pc.getAmount());
       System.out.println("Percent Offer:"+discount);
   }

}

OUTPUT-1

Enter Customer Name
James
Enter Customer Address
Chicago
Enter Customer Phone
24567892
Enter Customer No
C248
Does Customer has Email:(TRUE/FALSE)
TRUE
Enter the amount purchased:
2000

*****************************
Customer Name:James
Customer Address:Chicago
Customer Phone:24567892
Customer Number:C248
Customer Email:true
Purchased Amount is:2000.0
Percent Offer:10%

OUTPUT-2

Enter Customer Name
Peter
Enter Customer Address
USA
Enter Customer Phone
456278923
Enter Customer No
C567
Does Customer has Email:(TRUE/FALSE)
FALSE
Enter the amount purchased:
500
*****************************
Customer Name:Peter
Customer Address:USA
Customer Phone:456278923
Customer Number:null
Customer Email:false
Purchased Amount is:500.0
Percent Offer:5%