A showroom announces the discount (on the total cost of the items purchased) as per slabs provided below:
Total Cost and Discount in percentage :
Less than Rs. 3000 = No Discount
Rs. 3001 to Rs. 6000 = 10%
Rs. 6001 to Rs.10000 = 25%
Above Rs. 10,000 = 40%
Write a program to input the total cost from the user in main function and calculate and display the total amount to be paid by the customer after availing the discount. Implement the program using Class and Object.
import java.util.Scanner;
public class Main {
private int totalCost;
public Main(int totalCost) {
this.totalCost = totalCost;
}
public double getTotalAmount() {
if (totalCost <= 3000) {
return totalCost;
} else if (totalCost <= 6000) {
return totalCost * 0.9;
} else if (totalCost <= 10000) {
return totalCost * 0.75;
} else {
return totalCost * 0.6;
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the total cost:");
Main main = new Main(in.nextInt());
System.out.println("The total amount to be paid: " + main.getTotalAmount());
}
}
Comments
Leave a comment