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 payment | Discount for Dealer | Discount for Retailer |
---|---|---|
Within 30 days | 15% | 10% |
31 to 45 days | 12% | 8% |
46 to 60 days | 10% | 5% |
More than 60 days | No discount | No 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

Answered By
2 Likes
Related Questions
Distinguish between:
Finite loop and Infinite loop
Distinguish between:
Exit controlled loop and Entry controlled loop
Write a menu driven program using switch case statement to find the Arithmetic mean, Geometric mean and Harmonic mean which are calculated as:
(a) Arithmetic mean = (a + b) / 2
(b) Geometric mean = √ab
(c) Harmonic mean = 2ab / (a + b)
Write a menu driven program using switch case statement to perform the given tasks as stated.
Task 1:
A Fibonacci series is given as:
0, 1, 1, 2, 3, 5, 8, 13, ………. and so on.
Display all the prime Fibonacci numbers in the range from 1 to 1000.
For example, 2, 3, 5, 13 are prime fibonacci numbers.
Task 2:
Prime factors are the factors of a number which are prime numbers. Display all the prime factors of a number.
Sample Input: 24
Sample Output: The prime factors of 24 are: 2, 2, 2, 3