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
Write a program in Java to enter a natural number, where N>100 and N<1000, the natural number must not contain zeros. Print all the combinations of digits of the number including the number itself. Each new combination should appear on a new line. The program displays a message "Invalid Number", if N <100 or contains zeros.
Sample Input: Enter a number: 465
Sample Output:
456
465
546
564
645
654Sample Input: Enter a number: -712
Sample Output: Invalid NumberSample Input: Enter a number: 960
Sample Output: Invalid NumberA triangular number is formed by the addition of consecutive integers starting with 1. For example,
1 + 2 = 3
1 + 2 + 3 = 6
1 + 2 + 3 + 4 = 10
1 + 2 + 3 + 4 + 5 = 15
Thus, 3, 6, 10, 15, are triangular numbers.
Write a program in Java to display all the triangular numbers from 3 to n, taking the value of n as an input.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