- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
Conditional Constructs in Java
Chapter 8
Conditional Constructs in Java
Class 10 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Program: Cloth Discount Calculator for Dealers and Retailers
37. 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.
import java.util.Scanner;
public class ClothDiscount {
public static void main(String[] args) {
// Title
System.out.println("CLOTH DISCOUNT CALCULATOR");
System.out.println("-------------------------");
Scanner sc = new Scanner(System.in);
double length, amount, discount = 0, payable;
char type;
System.out.print("Enter length of cloth (in meters): ");
length = sc.nextDouble();
System.out.print("Enter total purchase amount (Rs.): ");
amount = sc.nextDouble();
System.out.println("Enter Customer Type:");
System.out.println("D - Dealer");
System.out.println("R - Retailer");
System.out.print("Your choice: ");
type = sc.next().charAt(0);
switch (type) {
case 'D':
case 'd':
if (length <= 1000)
discount = amount * 0.20;
else if (length < 2000)
discount = amount * 0.25;
else
discount = amount * 0.35;
break;
case 'R':
case 'r':
if (length <= 1000)
discount = amount * 0.15;
else if (length < 2000)
discount = amount * 0.20;
else
discount = amount * 0.25;
break;
default:
System.out.println("Invalid customer type!");
sc.close();
return;
}
payable = amount - discount;
System.out.println("Discount Amount : Rs. " + discount);
System.out.println("Amount to Pay : Rs. " + payable);
sc.close();
}
}
Output
Sample Output CLOTH DISCOUNT CALCULATOR ------------------------- Enter length of cloth (in meters): 1500 Enter total purchase amount (Rs.): 80000 Enter Customer Type: D - Dealer R - Retailer Your choice: D Discount Amount : Rs. 20000.0 Amount to Pay : Rs. 60000.0
📝 Explanation
- Inputs taken:
- Length of cloth
- Total purchase amount
- Customer type (Dealer / Retailer)
- switch-case checks customer type
- if-else determines discount based on cloth length
- Final payable amount calculated as:
Amount to Pay = Total Amount − Discount
- Error message shown for invalid choice
