Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

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