Computer Applications

'Mega Market' has announced festival discounts on the purchase of items, based on the total cost of the items purchased:

Total costDiscount
Up to ₹2,0005%
₹2,001 to ₹5,00010%
₹5,001 to ₹10,00015%
Above ₹10,00020%

Write a program to input the total cost. Display name of the customer, discount and the amount to be paid after discount.

Java

Input in Java

32 Likes

Answer

import java.io.*;

public class KboatDiscount
{
    public static void main(String args[]) throws IOException {
        
        InputStreamReader read = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(read);
        
        System.out.print("Enter customer name: ");
        String name = in.readLine();
        
        System.out.print("Enter total cost: ");
        double c = Double.parseDouble(in.readLine());
        
        int d = 0;
        
        if (c <= 2000)
            d = 5;
        else if (c <= 5000)
            d = 10;
        else if (c <= 10000)
            d = 15;
        else
            d = 20;
            
        double disc = c * d / 100.0;
        double amt = c - disc;
        
        System.out.println("Customer Name: " + name);
        System.out.println("Discount: " + disc);
        System.out.println("Amount to be paid: " + amt);
    }
}

Output

Answered By

15 Likes


Related Questions