-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathElectricBill.java
More file actions
49 lines (47 loc) · 1.18 KB
/
ElectricBill.java
File metadata and controls
49 lines (47 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.io.*;
class ElectricBill
{
String n;
int units;
double bill;
public void accept()throws IOException
{
BufferedReader y= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Input name of the customer");
n=y.readLine();
System.out.println("Input number of units consumed");
units=Integer.parseInt(y.readLine());
}
public void calculate()
{
double rent=0.00;
if(units<=100)
{
bill= bill+(units*2);
}
else if((units>100)&&(units<=300))
{
bill=bill+(100*2)+(units-100)*3;
}
else
{
rent=rent+200+600+(units-300)*5;
bill=bill+rent*(2.5/100);
}
}
public void print()
{
System.out.println(" NAME OF THE CUSTOMER - "+n);
System.out.println(" NUMBER OF UNITS CONSUMED - "+units);
System.out.println(" BILL AMOUNT - "+bill);
}
public static void main(String args[])throws IOException
{
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader y = new BufferedReader(in);
ElectricBill obj= new ElectricBill();
obj.accept();
obj.calculate();
obj.print();
}
}