Computer Applications
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.
Java
Java Conditional Stmts
17 Likes
Answer
import java.util.Scanner;
public class KboatDiscount
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Cloth length: ");
int l = in.nextInt();
System.out.print("Enter Total Amount of purchase: ");
double a = in.nextDouble();
System.out.println("Enter D for Dealer: ");
System.out.println("Enter R for Retailer: ");
System.out.print("Enter customer type: ");
char type = in.next().charAt(0);
type = Character.toUpperCase(type);
int d = 0;
switch (type) {
case 'D':
if (l <= 1000)
d = 20;
else if (l <= 2000)
d = 25;
else
d = 35;
break;
case 'R':
if (l <= 1000)
d = 15;
else if (l <= 2000)
d = 20;
else
d = 25;
break;
default:
System.out.println("Wrong choice");
}
double disc = a * d / 100.0;
double amt = a - disc;
System.out.println("Amount to be paid = " + amt);
}
}
Output
Answered By
7 Likes
Related Questions
Using switch case statement in Java, create a program to convert rupee into dollar and dollar into rupee according to the user's choice. Assume conversion price: 1 Dollar = Rs.77.
A box of cookies can hold 24 cookies, and a container can hold 75 boxes of cookies. Write a program that prompts the user to enter the total number of cookies, the number of cookies in each box, and the number of cookies boxes in a container. The program then outputs the number of boxes and the number of containers required to ship the cookies.
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% 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.