Computer Science, asked by vatsalsavaliya, 10 months ago

import java.io.*;
public class ElectricityBill
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter Your Name : ");
String nm=br.readLine();

System.out.print("Enter the units consumed : ");
int units=Integer.parseInt(br.readLine());

double charges=0,fbill=0;

if(units<=100)
charges=units*1.50;
else if(units<=200)
charges=(100*1.50)+(units-100)*2;
else if(units<=250)
charges=(100*1.50)+(100*2)+(units-200)*2.50;
else
charges=(100*1.50)+(100*2)+(50*2.50)+(units-250)*4;

fbill=charges+250;
System.out.print("\f");
//printing the bill
System.out.println("Your Electricity Bill");
System.out.println("*********************");
System.out.println();
System.out.println("Costumers Name : "+nm);
System.out.println("Units Consumed : "+units);
System.out.println("Charges : "+charges);
System.out.println("Rent Charges : 250 Rs.");
System.out.println("Total Bill : "+fbill);
}
}


please answer what is the output of this java program..​

Answers

Answered by Vintage
5

Your output will look like this

Your electricity bill

******************

Consumer Name : (the name entered)

Units Consumed : (entered by user)

Charges : (calculated)

Rent charges : 250 Rs.

Total Bill : (calculated above)

Hope it helps you...

Good luck and don't forget to select brainliest

Answered by QGP
2

Runtime Output - Java

First of all, the code won't compile, because of the capital I in import java.io*

Ignoring and correcting that, the program would compile, but then it would throw a Runtime Error:

Error: Main method not found in class ElectricityBill, please define the main method as:

  public static void main(String[] args)

or a JavaFX application class must extend javafx.application.Application

This error occurs because the main function does not have String[] args mentioned inside it. The parameters of the main function were missing.

Adding that and recompiling, the code would run now.

The Program takes User Input for Name and Units Consumed. After this calculations are performed and the resulting bill is printed.

The Program Output would be like this:

 \rule{300}{1}

Output

Enter Your Name : <enter name>

Enter the units consumed : <enter units>

Your Electricity Bill

*********************

Costumers Name : <name>

Units Consumed : <units>

Charges : <calculated charges>

Rent Charges : 250 Rs.

Total Bill : <total calculated bill>

 \rule{300}{1}

I am attaching a screenshot of a Powershell terminal where I compiled and executed the code. I made very small spelling corrections, and ran the code twice.

For the name, I used your name: Vatsal, from your username Vatsalsavaliya

Another screenshot of final code is attached too.

Attachments:
Similar questions