Answer to Question #271636 in Java | JSP | JSF for bbb

Question #271636


Retail store has preferred Customer plan. The amount of customer discount is determined by amount of customercumulative purchases in store. When preferred customer spends $500, he gets 5% discount on future purchases. When preferred customer spends $1,000, he gets 6% discount on future purchases. When preferred customer spends $1,500, he gets 7% discount on future purchases. When preferred customer spends $2,000, he gets 10% discount on all future purchases. Design class named PreferredCustomer which is derived from CustomerData class. PreferredCustomer class have:purchasesAmount (a double) ,discountLevel (a double).The purchasesAmount variable holds total of customer’s purchases to date. The discountLevel variable should be set to correct discount percentage according to store preferred customer plan. Also calculate discount Amount based on discount. Now in Main class create ArrayList and add customers into it and display the customers details purchase of each customer along with discount he gets


1
Expert's answer
2021-11-26T07:08:25-0500


SOLUTION CODE


package com.company;
import java.util.*;



class CustomerData {

    String name;



    public CustomerData(String name) {
        this.name = name;
    }

    public CustomerData() {

    }

    public String toString() {
        return "Customer name = " + name ;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


}

class PreferredCustomer extends CustomerData{
    double purchasesAmount;
    double discountLevel;
    public PreferredCustomer(String name, double purchasesAmount) {
        super(name);
        this.purchasesAmount = purchasesAmount;
        
    }
    

    public double getPurchasesAmount() {
        return purchasesAmount;
    }

    public void setPurchasesAmount(double purchasesAmount) {
        this.purchasesAmount = purchasesAmount;
    }

    public double getdiscountLevel() {
        return discountLevel;
    }

    public void setdiscountLevel(double purchasesAmount) {
        if(this.purchasesAmount > 2000)
        {
            this.discountLevel = 10;
        }
        else if(this.purchasesAmount > 1500)
        {
            this.discountLevel = 7;
        }
        else if(this.purchasesAmount > 1000)
        {
            this.discountLevel = 6;
        }
        else{
            this.discountLevel = 5;
        }

    }
    
    //calculate discount amount
    public double discountAmount()
    {
        return (purchasesAmount * discountLevel)/100;
    }

    public String toString() {
        return "Customer purchases Amount = " + purchasesAmount+"Customer discount Level = "
                + discountLevel+" Discount Amount = "+discountAmount();
    }

}

public class Main{

    public static void main(String[] args) {

        
        List<PreferredCustomer> listOfCustomers= new ArrayList<PreferredCustomer>();
        PreferredCustomer customer1 = new PreferredCustomer("Kelly",2200);
        PreferredCustomer customer2 = new PreferredCustomer("sarah", 700);

        listOfCustomers.add(customer1);

        listOfCustomers.add(customer2);

        System.out.println(" Customer 1 = " + customer1);
        System.out.println(" Customer 2 = " + customer2);
        



    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS