ELECTRICITY BILL GENERATION
AIM:
To develop a Java
application to generate Electricity bill. Create a class with the following
members: Consumer no., consumer name, previous
month reading, current month
reading, type of EB connection (i.e domestic or commercial). Compute the bill
amount using the following tariff.
If the type of the EB connection is domestic,
calculate the amount to be paid as follows:
Ø First 100 units - Rs. 1 per unit
Ø
101-200 units - Rs. 2.50 per unit
Ø 201 -500 units - Rs. 4 per unit
Ø > 501 units - Rs. 6 per unit
If the type of the EB connection is commercial,
calculate the amount to be paid as follows:
Ø First 100 units - Rs. 2 per unit
Ø
101-200 units - Rs. 4.50 per unit
Ø 201 -500 units - Rs. 6 per unit
Ø
> 501 units - Rs. 7 per unit
ALGORITHM:
1. Start
2. Create a class Ebill with three member functions: getdata(), calc(), display() and object
ob is created for another class Customerdata.
3. Create another class
Customerdata which defines the above functions.
4. Using getdata() function get
the consumed units for current and previous month .
5. Using calc()function
calculate the amount depending on the type of EB connection and no. of units
consumed.
6. Using display() function
display the bill.
7. Stop.
PROGRAM:
import java.util.*; class Ebill
{
public static
void main (String args[])
{
Customerdata ob = new Customerdata(); ob.getdata();
ob.calc();
ob.display();
}
}
class Customerdata
{
Scanner in = new Scanner(System.in); Scanner ins =
new Scanner(System.in); String cname,type;
int bn;
double current,previous,tbill,units; void getdata()
{
System.out.print ("\n\t Enter consumer number
"); bn = in.nextInt();
System.out.print ("\n\t Enter Type of
connection (D for Domestic or C for Commercial) "); type = ins.nextLine();
System.out.print ("\n\t Enter consumer name
"); cname = ins.nextLine();
System.out.print ("\n\t Enter previous month
reading "); previous= in.nextDouble();
System.out.print ("\n\t Enter current month reading ");
current= in.nextDouble();
}
void calc()
{
units=current-previous; if(type.equals("D"))
{
if
(units<=100)
tbill=1 * units;
else if (units>100
&& units<=200) tbill=2.50*units;
else if(units>200
&& units<=500) tbill= 4*units;
}
else
{
else
tbill= 6*units;
if (units<=100)
tbill= 2 * units;
else if(units>100
&& units<=200) tbill=4.50*units;
else if(units>200 && units<=500)
tbill= 6*units;
else
tbill= 7*units;
}
}void display()
{
System.out.println("\n\t Consumer number = "+bn); System.out.println ("\n\t Consumer name = "+cname);
if(type.equals("D"))
System.out.println ("\n\t type of connection = DOMESTIC ");
else
System.out.println ("\n\t Current Month Reading = "+current);
System.out.println ("\n\t Previous Month Reading = "+previous);
System.out.println ("\n\t Total units = "+units);
System.out.println ("\n\t Total bill = RS "+tbill);
}
}
OUTPUT:
D:\ >javac Ebill.java
D:\ >java Ebill
Comments
Post a Comment