KnowledgeBoat Logo

Computer Applications

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 clothDealer's DiscountRetailer's Discount
Up to 1000 meters20%15%
Above 1000 meters but less than 2000 meters25%20%
More than 2000 meters35%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.

Java

Java Conditional Stmts

17 Likes

Answer

import java.util.Scanner;

public class KboatDiscount
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Cloth length: ");
        int l = in.nextInt();
        System.out.print("Enter Total Amount of purchase: ");
        double a = in.nextDouble();
        System.out.println("Enter D for Dealer: ");
        System.out.println("Enter R for Retailer: ");
        System.out.print("Enter customer type: ");
        char type = in.next().charAt(0);
        type = Character.toUpperCase(type);
        int d = 0;
        switch (type) {
            case 'D':
            if (l <= 1000)
                d = 20;
            else if (l <= 2000)
                d = 25;
            else
                d = 35;
            break;
            
            case 'R':
            if (l <= 1000)
                d = 15;
            else if (l <= 2000)
                d = 20;
            else
                d = 25;
            break;
            
            default:
            System.out.println("Wrong choice");
        }
        
        double disc = a * d / 100.0;
        double amt = a - disc;
        
        System.out.println("Amount to be paid = " + amt);
    }
}

Output

BlueJ output of 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: 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.

Answered By

7 Likes


Related Questions