- 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 9
Conditional Constructs in Java
Class 9 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Programs - Festival Discount Calculator
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.
import java.util.Scanner;
public class FestivalDiscount {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter total cost of items (Rs.): ");
double totalCost = sc.nextDouble();
double discountRate;
if (totalCost < 2000) {
discountRate = 0.05;
} else if (totalCost < 5000) {
discountRate = 0.25;
} else if (totalCost < 10000) {
discountRate = 0.35;
} else {
discountRate = 0.50;
}
double discountAmount = totalCost * discountRate;
double amountToPay = totalCost - discountAmount;
System.out.println("\n--- Bill Details ---");
System.out.println("Total Cost : Rs. " + totalCost);
System.out.println("Discount Amount : Rs. " + discountAmount);
System.out.println("Amount to Pay : Rs. " + amountToPay);
sc.close();
}
}
Output
Output 1 :
SAMPLE INPUT : Enter total cost of items (Rs.): 1800 SAMPLE OUTPUT : --- Bill Details --- Total Cost : Rs. 1800.0 Discount Amount : Rs. 90.0 Amount to Pay : Rs. 1710.0Output 2 :
SAMPLE INPUT : Enter total cost of items (Rs.): 4200 SAMPLE OUTPUT : --- Bill Details --- Total Cost : Rs. 4200.0 Discount Amount : Rs. 1050.0 Amount to Pay : Rs. 3150.0Output 3 :
SAMPLE INPUT : Enter total cost of items (Rs.): 12000 SAMPLE OUTPUT : --- Bill Details --- Total Cost : Rs. 12000.0 Discount Amount : Rs. 6000.0 Amount to Pay : Rs. 6000.0
Explanation
1. Input
- Accepts the total cost of items purchased.
2. Determine Discount Rate
- Uses an if–else ladder to select the correct discount percentage based on the total cost.
3. Discount Calculation
Discount = Total Cost × Discount Rate
4. Final Amount
Amount to Pay = Total Cost − Discount
