Skip to content

Commit 673e6ca

Browse files
authored
Merge pull request MukulCode#197 from rokingshubham1/patch-1
Electricity billl
2 parents ef1dc97 + 424287d commit 673e6ca

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

ElectBill

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import java.util.*;
2+
public class ElectBill
3+
{ //Creating Global Variables*/
4+
int ConsumerNo; /* to store consumer no. globally*/
5+
String ConsumerName; /* to store the name of the person*/
6+
int PrevReading; /* to store previous reading globally*/
7+
int CReading; /* to store current reading globally*/
8+
String EBConn; /* to get the type of user*/
9+
double Bill; /*to generate bill*/
10+
11+
void input_data() /*void function to take inputs from the user*/
12+
{
13+
Scanner sc = new Scanner(System.in);
14+
System.out.println("Enter Consumer Number: ");
15+
ConsumerNo = sc.nextInt(); /*take input of consumer no.*/
16+
System.out.println("Enter Consumer Name: ");
17+
ConsumerName = sc.next(); /*take input of consumer name*/
18+
System.out.println("Enter Previous Units: ");
19+
PrevReading = sc.nextInt(); /*take input of previous reading*/
20+
System.out.println("Enter Current Units:");
21+
CReading = sc.nextInt(); /* take input of current reading*/
22+
System.out.println("Enter the types of EB Connection(domestic or commercial)");
23+
EBConn = sc.next(); /*take input of type of user*/
24+
}
25+
26+
double calculate_bill() /* this is a return type double function for calculation of bill*/
27+
{
28+
int CurrReading; /* to take the diffrence between the previous reading and the current reading*/
29+
CurrReading=CReading - PrevReading;
30+
switch(EBConn) /* to charge according to choice */
31+
{
32+
case "domestic":
33+
{if(CurrReading>=0 && CurrReading<=100) /*charge 1Rs if less than 100 units*/
34+
Bill=CurrReading*1;
35+
else if(CurrReading>100 && CurrReading <= 200) /*charge 2.50Rs if less than 200 units*/
36+
Bill=(100*1)+((CurrReading-100)*2.50);
37+
else if(CurrReading>200 && CurrReading <= 500) /* charge 4rs if less than 500 units*/
38+
Bill=(100*1)+(100*2.50)+((CurrReading-200)*4);
39+
else
40+
Bill=(100*1)+(100*2.50)+(300*4)+((CurrReading-500)*6); /*charge 6rs if more than 500 units*/
41+
break; }
42+
case "commercial":
43+
{ if(CurrReading>=0 && CurrReading<=100) /*charge 2Rs if less than 100 units*/
44+
Bill=CurrReading*2;
45+
else if(CurrReading>100 && CurrReading <= 200) /*charge 4.50Rs if less than 200 units*/
46+
Bill=(100*2)+((CurrReading-100)*4.50);
47+
else if(CurrReading>200 && CurrReading <= 500) /*charge 6rs if less than 500 units*/
48+
Bill=(100*2)+(100*4.50)+((CurrReading-200)*6);
49+
else
50+
Bill=(100*2)+(100*4.50)+(300*6)+((CurrReading-500)*7); /*charge 7rs if less than 100 units*/
51+
break; }
52+
default: System.out.println("Wrong Entry Please Check!");
53+
}
54+
return Bill; /* will return the calculated to the global variable bill*/
55+
}
56+
void display() /* printing the outputs */
57+
{
58+
System.out.println("----------------------------------");
59+
System.out.println("ELCTRICITY BILL");
60+
System.out.println("----------------------------------");
61+
System.out.println("Consumer Number: "+ConsumerNo);
62+
System.out.println("Consumer Name: "+ConsumerName);
63+
System.out.println("Consumer Previous Units: "+PrevReading);
64+
System.out.println("Consumer Current Units: "+CReading);
65+
System.out.println("Type of EBConnection: "+EBConn);
66+
System.out.println("----------------------------------");
67+
System.out.println("Total Amount(Rs.): "+Bill);
68+
}
69+
}
70+
class ElectBillGen extends ElectBill /* class to call functions of another class */
71+
{
72+
public static void main (String[] args) /* main function to call the other member functions*/
73+
{
74+
ElectBill b=new ElectBill(); /* object created*/
75+
b.input_data(); /* calling input function*/
76+
b.calculate_bill(); /* calling this for bill calculation*/
77+
b.display(); /* calling display function*/
78+
}
79+
}

0 commit comments

Comments
 (0)