Design a solution that has following features:
Develop two classes Bill and Cash, where Cash inherits Bill. Sample input and output are shown below:
Sample Input 1:
1000 //item_price
100 //qty
4 //notes of 2000
0 //notes of 500
0 //notes of 100
0 //notes of 50
10 //notes of 10
Sample Output 1:
Need to pay: 91900
Constraints: notes should be of Rs 2000, Rs 500, Rs 100, Rs 50, and Rs 10.
Formula Used: Bill = price of item * quantity
import java.util.Scanner;
// Class Bill
class Bill {
public int itemPrice;
public int qty;
}
// Class Cash inherits Bill
class Cash extends Bill {
private int a, b, c, d, e;
// Method to get cash input
void get_cash() {
Scanner sc = new Scanner(System.in);
// Input for item price and quantity
itemPrice = sc.nextInt();
qty = sc.nextInt();
// Input for notes of Rs 2000, Rs 500, Rs 100, Rs 50, Rs 10
a = sc.nextInt(); // Rs 2000 notes
b = sc.nextInt(); // Rs 500 notes
c = sc.nextInt(); // Rs 100 notes
d = sc.nextInt(); // Rs 50 notes
e = sc.nextInt(); // Rs 10 notes
sc.close();
}
// Method to display the result
void display() {
// Total cash provided
int total = 2000 * a + 500 * b + 100 * c + 50 * d + 10 * e;
// Calculate the bill
int bill = itemPrice * qty;
// Remaining amount to pay
int pay = bill - total;
// Output whether the bill is cleared or needs more payment
if (total >= bill) {
System.out.println("Clear");
} else {
System.out.println("Need to pay: " + pay);
}
}
}