0% found this document useful (0 votes)
829 views2 pages

Ex No: 1 Program To Generate Electricity Bill AIM

The document describes a Java program to generate electricity bills. It defines a CustomerData class with fields like name, readings and connection type. The calc() method calculates the bill amount based on slab rates for domestic and commercial connections. Units consumed are slabbed and charged different rates. The display() method prints the customer details and generated bill. The main() method creates a CustomerData object, calls its methods to get input, calculate and display the output.

Uploaded by

VVCET - CSE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
829 views2 pages

Ex No: 1 Program To Generate Electricity Bill AIM

The document describes a Java program to generate electricity bills. It defines a CustomerData class with fields like name, readings and connection type. The calc() method calculates the bill amount based on slab rates for domestic and commercial connections. Units consumed are slabbed and charged different rates. The display() method prints the customer details and generated bill. The main() method creates a CustomerData object, calls its methods to get input, calculate and display the output.

Uploaded by

VVCET - CSE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

EX NO : 1 PROGRAM TO GENERATE ELECTRICITY BILL }

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);
}
}

You might also like