Ex No: 1 Program To Generate Electricity Bill AIM
Ex No: 1 Program To Generate Electricity Bill AIM
class customerdata
AIM {
Scanner in = new Scanner(System.in);
To develop a Java application to generate Electricity bill. Scanner ins = new Scanner (System.in);
String cname,type;
PROCEDURE int bn;
double current,previous,tbill,units;
1.Create a class with the following members void getdata()
Consumer no., consumer name, previous month reading, current month reading, type { of EB
connection (i.e domestic or commercial) System.out.print ("\n\t Enter consumer number ");
2. Compute the bill amount using the following tariff. bn = in.nextInt();
If the type of the EB connection is domestic, calculate the amount to be paid as follows:
System.out.print ("\n\t Enter Type of connection (D for Domestic or C for
First 100 units - Rs. 1 per unit Commercial) ");
101-200 units - Rs. 2.50 per unit type = ins.nextLine();
201 -500 units - Rs. 4 per unit System.out.print ("\n\t Enter consumer name ");
> 501 units - Rs. 6 per unit cname = ins.nextLine();
If the type of the EB connection is commercial, calculate the amount to be paid as follows:
System.out.print ("\n\t Enter previous month reading ");
First 100 units - Rs. 2 per unit previous= in.nextDouble();
101-200 units - Rs. 4.50 per unit System.out.print ("\n\t Enter current month reading ");
201 -500 units - Rs. 6 per unit current= in.nextDouble();
> 501 units - Rs. 7 per unit }
3. Create the object for the created class .Invoke the methods to get the void calc()
input from the consumer and display the consumer information with the {
generated electricity bill. units=current-previous;
if(type.equals("D"))
PROGRAM {
import java.util.*; if (units<=100)
class ebill tbill=1 * units;
{ else if (units>100 && units<=200)
public static void main (String args[]) tbill=2.50*units;
{ else if(units>200 && units<=500)
customerdata ob = new customerdata(); tbill= 4*units;
ob.getdata(); else
ob.calc(); tbill= 6*units;
ob.display(); }
} else
{
if (units<=100) OUTPUT
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 type of connection = COMMERCIAL ");
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);
}
}