- 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: Star Mall Discount Calculator
35. 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% |
import java.util.Scanner;
public class StarMallDiscount {
public static void main(String[] args) {
// Title
System.out.println("STAR MALL DISCOUNT CALCULATOR");
System.out.println("-----------------------------");
Scanner sc = new Scanner(System.in);
double price, discount = 0, amountPayable;
char code;
System.out.print("Enter item price: Rs. ");
price = sc.nextDouble();
System.out.print("Enter item code (L/D/X/P): ");
code = sc.next().charAt(0);
switch (code) {
case 'L':
case 'l':
discount = 0.05 * price;
break;
case 'D':
case 'd':
discount = 0.07 * price;
break;
case 'X':
case 'x':
discount = 0.10 * price;
break;
case 'P':
case 'p':
discount = 0.11 * price;
break;
default:
System.out.println("Invalid Item Code!");
sc.close();
return;
}
amountPayable = price - discount;
System.out.println("Discount Amount : Rs. " + discount);
System.out.println("Amount to Pay : Rs. " + amountPayable);
sc.close();
}
}
Output
Sample Output STAR MALL DISCOUNT CALCULATOR ----------------------------- Enter item price: Rs. 40000 Enter item code (L/D/X/P): X Discount Amount : Rs. 4000.0 Amount to Pay : Rs. 36000.0
📝 Explanation
- Input:
- Item price
- Item code
- switch-case selects the discount rate
- Discount is calculated as:
Discount = Price × Discount Rate
- Final amount payable:
Amount Payable = Price − Discount
