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

PreferredCustomer Class A retail store has a preferred customer plan where custo

ID: 3716711 • Letter: P

Question

PreferredCustomer Class

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, he or she gets 5 percent discount on all future purchases.

When a preferred customer spends $1,000, he or she gets 6 percent discount on all future purchases.

When a preferred customer spends $1,500, he or she gets 7 percent discount on all future purchases.

When a preferred customer spends $2,000, he or she gets 10 percent 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 customer’s purchases and customers discounts level. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Demonstrate the class in a simple program.

Explanation / Answer

Please include Customer class and run test program

public class PreferredCustomer extends Customer
{

private double purchases;           
private double discount;   
    public PreferredCustomer()
    {super();
        purchases=0;
        discount=0;
    }
    public PreferredCustomer(String n,String a,String p,String c, boolean m, double amt)
    {super(n,a,p,c,m);
    setDiscount(amt);
    }
   public void setDiscount(double p)
   { purchases = p;
        if (purchases>=2000)
            discount=0.1;       
        else if(purchases>= 1500)
            discount=0.07;   
        else if(purchases>=1000)
            discount=0.06;
        else if(purchases>=500)
            discount=0.05;   
        else
            discount=0;       
   }
   public double getPurchases()
   {return purchases;
   }
   public double getDiscount()
   {return discount;
   }
}

public class PreferredCustomerTest
{
   public static void main(String[] args)
   { PreferredCustomer a=new PreferredCustomer("Big Bird","123 Sesame Street","123-4567","123",true,592.00);
     System.out.println("Name: "+a.getName());
     System.out.println("Address: "+a.getAddress());
     System.out.println("Phone: "+a.getPhone());
     System.out.println("Customer Number: "+a.getNumber());
     System.out.println("Mailing List: "+a.getList());
     System.out.printf("Purchases: $%.2f ",a.getPurchases());
     System.out.println("Discount: "+a.getDiscount()*100+"%");
   }
}