Computer Applications
Star mall is offering discount on various types of products purchased by its customers. Following table shows different type of products and their respective code along with the discount offered. Based on the code entered, the mall is calculating the total amount after deducting the availed discount. Create a program to calculate total amount to be paid by the customer.
Item | Item Code | Discount |
---|---|---|
Laptop | L | 5% |
LCD | D | 7% |
XBox | X | 10% |
Printer | P | 11% |
Java
Java Conditional Stmts
10 Likes
Answer
import java.util.Scanner;
public class KboatStarMall
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter purchase amount: ");
double amt = in.nextDouble();
System.out.print("Enter item code: ");
char code = in.next().charAt(0);
int d = 0;
switch (code) {
case 'L':
d = 5;
break;
case 'D':
d = 7;
break;
case 'X':
d = 10;
break;
case 'P':
d = 11;
break;
default:
System.out.println("Invalid Item Code");
}
double disc = amt * d / 100.0;
double total = amt - disc;
System.out.println("Total amount payable = " + total);
}
}
Output
Answered By
4 Likes
Related Questions
Using switch case, write a program to convert temperature from Fahrenheit to Celsius and Celsius to Fahrenheit.
Fahrenheit to Celsius formula: (32°F - 32) x 5/9
Celsius to Fahrenheit formula: (0°C x 9/5) + 32Write a program in Java to accept three numbers and check whether they are Pythagorean Triplet or not. The program must display the message accordingly. [Hint: h2=p2+b2]
A cloth showroom has announced the following festival discounts on the purchase of items based on the total cost of the items purchased:
Total Cost Discount Rate Less than Rs. 2000 5% Rs. 2000 to less than Rs. 5000 25% Rs. 5000 to less than Rs. 10,000 35% Rs. 10,000 and above 50% Write a program to input the total cost and to compute and display the amount to be paid by the customer availing the the discount.
A cloth manufacturing company offers discounts to the dealers and retailers. The discount is computed using the length of the cloth as per the following table:
Length of cloth Dealer's Discount Retailer's Discount Up to 1000 meters 20% 15% Above 1000 meters but less than 2000 meters 25% 20% More than 2000 meters 35% 25% Write a program in Java to input the length of the cloth and the total amount of purchase. The program should display a menu to accept type of customer — Dealer (D) or Retailer (R) and print the amount to be paid. Display a suitable error message for a wrong choice.