2. The Electricity board charges from their consumers according to units
consumed per month. The amount is calculated as per the tariff given
below.
Units consumed
charges
Rs.5.50/unit
up to 100 units
for next 200 units
Rs.6.50/unit
for next 300 units
Rs.7.50/unit
more than 600 units
Rs.8.50/unit
Write a program to input consumer's name, consumer's number and the
units consumed. The program displays the following information after
calculating the amount.
MONEY RECEIPT
Consumer's Number
Consumer's Name
WEIN LITE
MASININ
Units consumed
Amount to be paid
Answers
Answer:
import java.util.Scanner;
public class ElectricBill
{
public static void main(String args[])
{
String n;
int unit;
int number;
double bill;
Scanner sc = new Scanner(System.in);
System.out.println("Please enter your name");
n = sc.next();
System.out.println("Please enter your number");
number = sc.nextInt();
System.out.println("Please enter the amount of units ");
unit = sc.nextInt();
if(unit>=100)
{
bill = unit*5.50;
}
else if(unit>100 && unit<=300)
{
bill = unit*6.50;
}
else if(unit>300 && unit<=600)
{
bill = unit*7.50;
}
else
bill=unit*8.50;
System.out.println("Name: "+n);
System.out.println("Number: "+number);
System.out.println("Units consumed: "+unit);
System.out.println("Bill amount: "+bill);
}//method ends hare
}//class ends here
Explanation:
I hope it will help you
Answer:
import java.util.*;
public class Program
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double a=0.0;
System.out.println("Enter your name");
String n=sc.next();
System.out.println("Enter consumer number");
long c=sc.nextLong();
System.out.println("Enter units consumed");
int u=sc.nextInt();
if(u<=100)
{
a=u*5.50;
}
else if(u>100&&u<=300)
{
a=(100*5.50)+(300-u)*6.50;
}
else if(u>300&&u<=600)
{
a=(100*5.50)+(200*6.50)+(600-u)*7.50;
}
else if(u>600)
{
a=(100*5.50)+(200*6.50)+(300*7.50)+(u-600)*8.50;
}
System.out.println("Consumer name: "+n);
System.out.println("Consumer number: "+c);
System.out.println("Units consumed: "+u);
System.out.println("Amount to be paid: "+a);
}
}
Explanation:
Since in the question it is said "up to" in such a case we write a program like this. Hope it helps