There are three type of Customer say Classic, Gold and Platinum.
Each type get different discount
depends of
the purchase amount per below table. Create a project which will
start once and can do this
calculation and number of times user want. Program will terminate
once user press 0(Zero). Make use of
Interface, most of the OOP concepts. One class should not have more
than one responsibility. Project
should be extensible.
If new discount type is to introduce in future then existing core
logic should not break/ not require to
change
Purchase Classic(discount) Gold (discount)
Platinum(discount)
1-10000 10% 20% 30 %
10001-20000 15 % 25% 35 %
20000 above 20 % 30 % 40%
Print
1. Discount
2. Final
Thanks for the question, here is the complete set of files you will be needing.
Discountable.java is the interface
and Gold, Classic and Platinum are the different set of classes that implements the interface.
Finally Main.java is a short program that takes user inputs and prints the discount and final price.
Let me know for any questions or doubts.
///////////////////////////////////////////////////////////////////////////////////////////
public interface Discountable {
public double
calculateDiscount( );
public double
getNetPrice();
}
///////////////////////////////////////////////////////////////////////////////////////////
public class Classic implements Discountable {
private double price;
public Classic(double price) {
this.price = price;
}
@Override
public double calculateDiscount() {
if (1 <= price && price <= 10000) {
return price * 0.1;
} else if (10001 <= price && price <= 20000) {
return price * 0.15;
} else {
return price * 0.20;
}
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double getNetPrice(){
return getPrice() - calculateDiscount();
}
}
///////////////////////////////////////////////////////////////////////////////////////////
public class Gold implements Discountable {
private double price;
public Gold(double price) {
this.price = price;
}
@Override
public double calculateDiscount() {
if (1 <= price && price <= 10000) {
return price * 0.2;
} else if (10001 <= price && price <= 20000) {
return price * 0.25;
} else {
return price * 0.30;
}
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double getNetPrice(){
return getPrice() - calculateDiscount();
}
}
///////////////////////////////////////////////////////////////////////////////////////////
public class Platinum implements Discountable {
private double price;
public Platinum(double price) {
this.price = price;
}
@Override
public double calculateDiscount() {
if (1 <= price && price <= 10000) {
return price * 0.2;
} else if (10001 <= price && price <= 20000) {
return price * 0.25;
} else {
return price * 0.30;
}
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double getNetPrice() {
return getPrice() - calculateDiscount();
}
}
///////////////////////////////////////////////////////////////////////////////////////////
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("[1] Classic");
System.out.println("[2] Gold");
System.out.println("[3] Platinum");
System.out.println("[0] Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
if (choice == 0) break;
System.out.print("Enter price: ");
double price = scanner.nextDouble();
Discountable type = null;
if (choice == 1)
type = new Classic(price);
else if (choice == 2) type = new Gold(price);
else if (choice == 3) type = new Platinum(price);
if (type != null) {
System.out.printf("Discount: $%.2f\n", type.calculateDiscount());
System.out.printf("Final Price: $%.2f\n", type.getNetPrice());
}else{
System.out.println("Error: Invalid choice.");
}
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////
There are three type of Customer say Classic, Gold and Platinum. Each type get different discount...
HELLO, PLEASE TAKE TIME TO ANSWER THIS QUESTION. PLESE ENSURE ITS CORRECT AND SHOW THAT THE PROGRAM RUNS. Task 1: Enforcing const-ness throughout Your first job will be to go through all of the code and decide which functions should be declared const. You should find several places throughout the program where this makes sense. We will also make the id data member in the Customer class const , as once a customer has been created their ID will never...