C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Electronic Shop Discount Program - Java Programs

An electronics shop has announced the following seasonal discounts on the purchase of certain items:

Purchase amount in Rs. Discount on Laptop Discount on Desktop PC
0 – 25000 0.0% 5.0%
25001 – 57000 5.0% 7.6%
57001 – 100000 7.5% 10%
More than 100000 10.0% 15.0%

Write a program based on the above criteria to input name, address, 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 and address.
(Hint: Discount = (discount rate / 100) * amount of purchase,
Net amount = amount of purchase – discount)

import java.util.Scanner; class Shop{ public static void main(String args[]){ Scanner in = new Scanner(System.in); System.out.print("Name: "); String n = in.nextLine(); System.out.print("Address: "); String a = in.nextLine(); System.out.print("Amount of purchase: "); int amt = Integer.parseInt(in.nextLine()); System.out.print("Type of purchase: "); char type = in.nextLine().charAt(0); double dp = 0.0; switch(type){ case 'L': case 'l': if(amt <= 25000) dp = 0.0; else if(amt <= 57000) dp = 5.0; else if(amt <= 100000) dp = 7.5; else dp = 10.0; break; case 'D': case 'd': if(amt <= 25000) dp = 5.0; else if(amt <= 57000) dp = 7.6; else if(amt <= 100000) dp = 10.0; else dp = 15.0; } double da = dp / 100 * amt; double net = amt - da; System.out.println("Name: " + n); System.out.println("Address: " + a); System.out.println("Net amount: " + net); } }

Output

 
 OUTPUT : 
Name: Ricky
Address: Kolkata
Amount of purchase: 65000
Type of purchase: L
Name: Ricky
Address: Kolkata
Net amount: 60125.0