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

Using Java 1. Create an enumeration named CustomerType. This enumeration should

ID: 3788052 • Letter: U

Question

Using Java

1. Create an enumeration named CustomerType. This enumeration should contain constants that represent three types of customers: retail, trade, and college.

2. Using the CustomerTypeApp class (listed below) add a method to this class that returns a discount percent (.10 for retail, .30 for trade, and .20 for college) depending on the CustomerType variable that's passed to it.

3. Add code to the main method that declares a CustomerType variable, assigns one of the customer types to it, gets the discount percent for that customer type, and displays the discount percent.

4. Add a statement to the main method that displays the string returned by the toString method of the customer type.

5. Add a toString method to the CustomerType enumeration which should return a string that contains "Retail customer," "Trade customer," or "College customer" depending om th customer type.

Using this Java formatted file:

public class CustomerTypeApp
{
public static void main(String[] args)
{
// display a welcome message
System.out.println("Welcome to the Customer Type Test application ");

// get and display the discount percent for a customer type

// display the value of the toString method of a customer type

// a method that accepts a CustomerType enumeration

Explanation / Answer

public class CustomerTypeApp {

   enum CustomerType{
       RETAIL(0.10), TRADE(0.30), COLLEGE(0.20);

       private double value;
       private CustomerType(double value){
           this.value=value;
       }
      
       //Redefining the toString method
      
       @Override
       public String toString() {
           switch(this){
           case RETAIL : return "Retail customer";
           case TRADE: return "Trade customer";
           case COLLEGE : return "College customer";
           default : return "Invalid customer type";
           }
       }
   }

   // a method that accepts a CustomerType enumeration
   public double returnDiscountPercentage(CustomerType customerType){
       double discountPercent=0;
       discountPercent = customerType.value;
       return discountPercent;
   }

   public static void main(String[] args)
   {
       // display a welcome message
       System.out.println("Welcome to the Customer Type Test application ");

       // get and display the discount percent for a customer type
       CustomerTypeApp customerTypeApp = new CustomerTypeApp();
       CustomerType customerType;
       double discountPercent=0;
       customerType = CustomerType.TRADE;
       discountPercent = customerTypeApp.returnDiscountPercentage(customerType);
       System.out.println("Discount percentage for "+customerType+" is : "+discountPercent);

       // display the value of the toString method of a customer type
       System.out.println(customerType.toString());

   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote