Write a java program to calculate the EB-Bill based on the usage
a)No charge, if usage is less than or equal to 20 units.
b)Rs.3.50 per unit, if usage is greater than 20 units and less than 100 units.
c)Rs.5.00 per unit, if usage is greater than or equal to 100 units.
Sample Input 1:
Enter the units consumed
19
Write it in Java
Answers
Program:
import java.util.*;
public class MyClass
{
public static void main(String args[])
{
Scanner Sc = new Scanner(System.in);
int units;
System.out.print("Enter the units consumed : ");
units = Sc.nextInt();
double charge;
if(units <= 20)
{
charge = 0;
}
else if(units > 20 && units < 100)
{
charge = 3.50 * units;
}
else
{
charge = 5 * units;
}
System.out.print("Bill = " + charge);
}
}
Output 1:
Enter the units consumed : 19
Bill = 0.0
Output 2:
Enter the units consumed : 200
Bill = 1000.0
Answer:
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int unit;
System.out.println("Enter the units consumed");
unit=sc.nextInt();
double charge;
if(unit<=20)
{
charge=0;
System.out.println("No charge");
}
else if(unit>20 && unit<100)
{
charge=3.50*unit;
System.out.println("You have to pay Rs."+charge);
}
else
{
charge=5.00*unit;
System.out.println("You have to pay Rs."+charge);
}
}
}
Explanation:
Input - 19
Output - No Charge
Input - 200
Output - You have to pay Rs. 1000.0