You have to generate electricity bill for a customer with the details as give below: Customer ID, Customer Name, Customer Address, Contact No, Units Consumed, Total payable amount. Following are the norms to calculate the unit amount:
a) for initial 100 units it will cost 6 rupees per unit
b) for next 100 units it will cost 8 rupees per unit
c) for next all units it will cost 10 rupees per unit
Hint:-
-get user input of customer name, id, address, contact no, units consumed
-give output as customer details and total payable amount but the payable amount wil be based on the unit consumed (if the total unit 300 it will be like 100*6= 600 as per first 100 units and 100*8= 800 as per second 100 units rest 100*10= 1000. so total will be 600+800+1000=2400).
import java.util.Scanner;
class App {
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
System.out.print("Enter Customer ID: ");
String ID = keyBoard.nextLine();
System.out.print("Enter Customer Name: ");
String Name = keyBoard.nextLine();
System.out.print("Enter Customer Address: ");
String Address = keyBoard.nextLine();
System.out.print("Enter Customer Contact No: ");
String ContactNo = keyBoard.nextLine();
System.out.print("Enter Customer Units Consumed: ");
int UnitsConsumed = keyBoard.nextInt();
double TotalPayableAmount = 0;
// a) for initial 100 units it will cost 6 rupees per unit
if (UnitsConsumed < 100) {
TotalPayableAmount += 6 * UnitsConsumed;
} else if (UnitsConsumed > 100 && UnitsConsumed < 200) {
// b) for next 100 units it will cost 8 rupees per unit
TotalPayableAmount = 6 * 100 + (UnitsConsumed - 100) * 8;
} else {
// c) for next all units it will cost 10 rupees per unit
TotalPayableAmount = 6 * 100 + 100 * 8 + 10 * (UnitsConsumed - 200);
}
System.out.println("ID: " + ID);
System.out.println("Name: " + Name);
System.out.println("Address: " + Address);
System.out.println("Contact No: " + ContactNo);
System.out.println("Units Consumed: " + UnitsConsumed);
System.out.println("Total payable amount: " + TotalPayableAmount);
keyBoard.close();
}
}
Comments
Leave a comment