Answer to Question #299980 in Java | JSP | JSF for Kamalesh

Question #299980

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).

1
Expert's answer
2022-02-20T14:40:51-0500


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();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS