Write a program (In java) to input cost of purchased item.calculate and print discount on the cost based
on following criteria
COST
DISCOUNTin percentage)
Less than or equal to Rs 10000
5%
More than Rs 10000 and less than or equalto 20000
10%
More than Rs 20000 and less than or equal to 35000
15%
More than 35000
20%
Answers
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the total cost: ");
double amt = sc.nextDouble();
if (amt<=10000) {
System.out.println("Discount: 5% Final Amount after discount: "+(amt-(amt/100*5)));
System.out.println("Discount amount: "+amt/100*5);
}
else if (amt>10000 && amt<=20000) {
System.out.println("Discount: 10% Final Amount after discount: "+(amt-(amt/100*10)));
System.out.println("Discount amount: "+amt/100*10);
}
else if (amt>20000 && amt<=35000) {
System.out.println("Discount: 15% Final Amount after discount: "+(amt-(amt/100*15)));
System.out.println("Discount amount: "+amt/100*15);
}
else if (amt>35000) {
System.out.println("Discount: 20% Final Amount after discount: "+(amt-(amt/100*20)));
System.out.println("Discount amount: "+amt/100*20);
}
}
}