Computer Science, asked by mokshaa1502, 1 month ago

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 Retailer's
Discount Discount
Upto 1000 meters
20%
15%
Above 1000 meters but less than 2000 25%
20
meters
More than 2000 meters
35%
25%
Write a program 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.

Answers

Answered by Equestriadash
5

The following cσdes have been written using Python.

while True:

 print("1. Compute the net amount.")

 print("2. Exit.")

 print()

 c = int(input("Enter your choice: "))

 print()

 if c == 1:

   l = float(input("Enter the length of the cloth [in meters]: "))

   a = float(input("Enter the total amount of purchase: "))

   print()

   print("Dealer [D]")

   print("Customer [C]")

   print()

   tc = input("Enter the type of customer: ")

   print()

   if tc == 'D' or tc == 'd':

       if l < 1000:

           d = 0.20

           ta = a - (a*d)

           print(ta, "is your total amount to be paid.")

           print()

       elif l > 1000 and l < 2000:

           d = 0.25

           ta = a - (a*d)

           print(ta, "is your total amount to be paid.")

           print()

       elif l > 2000:

           d = 0.35

           ta = a -(a*d)

           print(ta, "is your total amount to be paid.")

           print()

   elif tc == 'C' or tc == 'c':

       if l < 1000:

           d = 0.15

           ta = a - (a*d)

           print(ta, "is your total amount to be paid.")

           print()

       elif l > 1000 and l < 2000:

           d = 0.20

           ta = a - (a*d)

           print(ta, "is your total amount to be paid.")

           print()

       elif l > 2000:

           d = 0.25

           ta = a - (a*d)

           print(ta, "is your total amount to be paid.")

           print()

   elif tc not in 'DdCc':

       print("Wrong input.")

       print()

 elif c == 2:

       break

Answered by eaglegamming46
1

Explanation:

import java.util.Scanner;

public class ClothPurchase {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter cloth length (in meters): ");

int clothLength = scanner.nextInt();

System.out.print("Enter total amount of purchase: ");

double totalAmount = scanner.nextDouble();

System.out.print("Enter customer type (Dealer or Retailer): ");

String customerType = scanner.next();

double discountPercentage = 0;

if (customerType.equalsIgnoreCase("Dealer")) {

discountPercentage = clothLength <= 1000 ? 20 : clothLength <= 2000 ? 25 : 35;

} else if (customerType.equalsIgnoreCase("Retailer")) {

discountPercentage = clothLength <= 1000 ? 15 : clothLength <= 2000 ? 20 : 25;

} else {

System.out.println("Invalid customer type entered!");

System.exit(0);

}

double amountToBePaid = totalAmount * (100 - discountPercentage) / 100;

System.out.println("Amount to be paid: " + amountToBePaid);

}

}

Similar questions