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

Design a Customer class to handle a customer loyalty marketing campaign. After a

ID: 3546479 • Letter: D

Question

Design a Customer class to handle a customer loyalty marketing campaign. After accumulating $100 in purchases, the customer receives a $10 discount on the next purchase. Provide methods


void makePurchase(double amount)

Boolean discountReached()


Provide a test program and test a scenario in which a customer has earned a discount and then made over $90, but less than $100 in purchases. This should not result in a second discount. Then add another that results in the second discount.



the wording in this question has me rather confused


please provide thorough comments


thanks

Explanation / Answer

class Customer
{
   double amount = 0;
   static double total = 0, discountTally = 0;
  
   public static void makePurchase(double amount)
   {
       if (discountReached())
       {
          
           total = total + amount - 10;
           discountTally = amount - 10;
           System.out.println("You got $10 discount.");
       }
       else
       {
           total = total + amount;
           discountTally = discountTally + amount;
       }
      
   }
   public static Boolean discountReached()
   {      
       if ((int)(discountTally/100) >= 1)
           return true;
       else
           return false;
   }
}

//test class to test the Customer class
public class TestCustomer
{
   public static void main(String[] args)
   {
       double pAmount;
       char ch = 'Y';
       Scanner in = new Scanner(System.in);
       Customer customer = new Customer();
       while (ch == 'Y' ||ch == 'y')
       {
           System.out.print("Enter the amount of purchase : $");
           pAmount = in.nextDouble();  
           customer.makePurchase(pAmount);
           //prompt the user that he has any more purchase details
           System.out.print(" Do you want to enter next purchase details (Y/N): ");
           //read user choice
           ch = in.next().charAt(0);
       }
       in.close();
   }
}


I did't understand exactly what are your requirements. I tried to give the solution as you said.

Hope this helps you.