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: 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