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 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.0

Output 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.0

Output 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