Answer to Question #271234 in Java | JSP | JSF for ahs

Question #271234

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’s 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-25T20:15:05-0500
public class PreferredCustomer extends CustomerData {
    private double purchasesAmount;
    private double discountLevel;

    public PreferredCustomer() {
        purchasesAmount = 0;
        discountLevel = 0;
    }

    public void addAmount(double amount) {
        purchasesAmount += amount;
        if (purchasesAmount >= 2000) {
            discountLevel = 0.1;
        } else if (purchasesAmount >= 1500) {
            discountLevel = 0.07;
        } else if (purchasesAmount >= 1000) {
            discountLevel = 0.06;
        } else if (purchasesAmount >= 500) {
            discountLevel = 0.05;
        }
    }

    public double discountAmount(double amount) {
        return amount * discountLevel;
    }

    @Override
    public String toString() {
        return purchasesAmount + " " + discountLevel;
    }
}


import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        ArrayList<PreferredCustomer> preferredCustomers = new ArrayList<>();
        preferredCustomers.add(new PreferredCustomer());
        preferredCustomers.add(new PreferredCustomer());
        preferredCustomers.add(new PreferredCustomer());
        preferredCustomers.forEach(System.out::println);
    }
}

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