KnowledgeBoat Logo

Computer Science

A company deals with two types of customers (i.e. dealer and retailer) for selling its goods. The company also offers discount to the dealer and retailer at the time of purchasing goods for paying the bill, as per the tariff given below:

Days of paymentDiscount for DealerDiscount for Retailer
Within 30 days15%10%
31 to 45 days12%8%
46 to 60 days10%5%
More than 60 daysNo discountNo discount

Write a program in Java to accept:
(a) The number of days within which the bill is to be paid.
(b) The type of customer 'D' for dealer and 'R' for retailer.
(c) The amount of purchase.

The program displays the details to the customer at the time of paying the bill.

Java

Java Conditional Stmts

6 Likes

Answer

import java.util.Scanner;

public class KboatCompany
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter No. of days: ");
        int days = in.nextInt();
        System.out.print("Enter Type('D' - Dealer & 'R' - Retailer): ");
        char type = in.next().charAt(0);
        System.out.print("Enter Purchase Amount: ");
        double amt = in.nextDouble();
        int discPercent = 0;
        
        //Check if Customer Type is valid
        if (type != 'D' && type != 'R') {
            System.out.println("ERROR!!!Incorrect Customer Type.");
            return;
        }
        
        if (days <= 30)
            discPercent = type == 'D' ? 15 : 10;
        else if (days <= 45)
            discPercent = type == 'D' ? 12 : 8;
        else if (days <= 60)
            discPercent = type == 'D' ? 10 : 5;
        else
            discPercent = 0;
            
        double disc = amt * discPercent / 100;
        double billAmt = amt - disc;
        
        System.out.println("No. of days for bill payment = " + days);
        System.out.println("Customer Type = " + type);
        System.out.println("Purchase Amount = " + amt);
        System.out.println("Discount Amount = " + disc);
        System.out.println("Bill Amount = " + billAmt);
    }
}

Output

BlueJ output of A company deals with two types of customers (i.e. dealer and retailer) for selling its goods. The company also offers discount to the dealer and retailer at the time of purchasing goods for paying the bill, as per the tariff given below: Write a program in Java to accept: (a) The number of days within which the bill is to be paid. (b) The type of customer 'D' for dealer and 'R' for retailer. (c) The amount of purchase. The program displays the details to the customer at the time of paying the bill.

Answered By

2 Likes


Related Questions