-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bill.java
74 lines (71 loc) · 1.68 KB
/
Bill.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.util.Scanner;
class Elec_bill
{
String consumer_no,consumer_name;
double pmr,cmr,s;
char type;
void unit()
{
s=cmr-pmr;
}
void domestic()
{
double total=0;
if(s<=100)
total=s*1;
else if(s>100 && s<=200)
total=(100*1)+((s-100)*2.50);
else if(s>200 && s<=500)
total=(100*1)+(100*2.50)+((s-200)*4);
else if(s>500)
total=(100*1)+(100*2.50)+(300*4)+((s-500)*6);
System.out.print("The bill amount is "+total);
}
void commerical()
{
double total=0;
if(s<=100)
total=s*2;
else if(s>100 && s<=200)
total=(100*1)+((s-100)*4.50);
else if(s>200 && s<=500)
total=(100*1)+(100*4.50)+((s-200)*6);
else if(s>500)
total=(100*1)+(100*4.50)+(300*6)+((s-500)*7);
System.out.print("The bill amount is "+total);
}
void display()
{
System.out.println("The consumer no : "+consumer_no);
System.out.println("The consumer name: "+consumer_name);
}
}
public class Bill
{
public static void main(String[] arg)
{
Scanner reader= new Scanner(System.in);
Elec_bill obj = new Elec_bill();
System.out.print("Enter the consumer no: ");
obj.consumer_no=reader.nextLine();
System.out.print("Enter the consumer name: ");
obj.consumer_name=reader.nextLine();
System.out.print("Enter type of eb: <d- domestic and c-commerical> ");
obj.type=reader.next().charAt(0);
System.out.print("Enter the perivous month reading: ");
obj.pmr=reader.nextDouble();
System.out.print("Enter the next month reading: ");
obj.cmr=reader.nextDouble();
obj.unit();
System.out.println("Electric billing");
switch(obj.type)
{
case 'd':
obj.domestic();
break;
case 'c':
obj.commerical();
break;
}
}
}