Computer Applications

'Kumar Electronics' has announced the following seasonal discounts on purchase of certain items.

Purchase AmountDiscount on LaptopDiscount on Desktop PC
Up to ₹ 250000.0%5.0%
₹ 25,001 to ₹ 50,0005%7.5%
₹ 50,001 to ₹ 1,00,0007.5%10.0%
More than ₹ 1,00,00010.0%15.0%

Write a program to input name, amount of purchase and the type of purchase (`L' for Laptop and 'D' for Desktop) by a customer. Compute and print the net amount to be paid by a customer along with his name.
(Net amount = Amount of purchase - discount)

Java

Java Conditional Stmts

ICSE 2009

154 Likes

Answer

import java.util.Scanner;

public class KboatElectronicsSale
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Name: ");
        String name = in.nextLine();
        System.out.print("Enter Amount of Purchase: ");
        double amt = in.nextDouble();
        System.out.println("Enter Type of Purchase");
        System.out.print("'L'- Laptop or 'D'- Desktop: ");
        char type = in.next().charAt(0);
        type = Character.toUpperCase(type);
        double disc = 0.0;
        
        if (amt <= 25000)
            disc = type == 'L' ? 0.0 : 5.0;
        else if (amt <= 50000)
            disc = type == 'L' ? 5.0 : 7.0;
        else if (amt <= 100000)
            disc = type == 'L' ? 7.5 : 10.0;
        else
            disc = type == 'L' ? 10.0 : 15.0;
            
        double netAmt = amt - (disc * amt / 100);
        
        System.out.println("Name: " + name);
        System.out.println("Net Amount: " + netAmt);
    }
}

Variable Description Table

Program Explanation

Output

Answered By

57 Likes


Related Questions