-
Notifications
You must be signed in to change notification settings - Fork 1
/
EBBillpay.java
87 lines (82 loc) · 2.41 KB
/
EBBillpay.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
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.util.Scanner;
class EBBillpay
{
int cno;
String cname;
int pm_reading;
int cm_reading;
String EBCon;
double Billpay;
void input_data ()
{
Scanner sc = new Scanner (System.in);
System.out.println ("\n Enter Consumer Number: ");
cno = sc.nextInt ();
System.out.println ("\n Enter Consumer Name: ");
cname = sc.next ();
System.out.println ("\n Enter Previous Units: ");
pm_reading = sc.nextInt ();
System.out.println ("Enter Current Units consumed:");
cm_reading = sc.nextInt ();
System.out.
println ("Enter the types of EB Connection(domestic or commercial)");
EBCon = sc.next ();
}
double calculate_Billpay ()
{
int choice;
if (EBCon == "domenstic")
choice = 1;
else
choice = 2;
switch (choice)
{
case 1:
if (cm_reading >= 0 && cm_reading <= 100)
Billpay = cm_reading * 1;
else if (cm_reading > 100 && cm_reading <= 200)
Billpay = (100 * 1) + ((cm_reading - 100) * 2.50);
else if (cm_reading > 200 && cm_reading <= 500)
Billpay = (100 * 1) + (100 * 2.50) + ((cm_reading - 200) * 4);
else
Billpay =
(100 * 1) + (100 * 2.50) + (300 * 4) + ((cm_reading - 500) * 6);
break;
case 2:
if (cm_reading >= 0 && cm_reading <= 100)
Billpay = cm_reading * 2;
else if (cm_reading > 100 && cm_reading <= 200)
Billpay = (100 * 1) + ((cm_reading - 100) * 4.50);
else if (cm_reading > 200 && cm_reading <= 500)
Billpay = (100 * 1) + (100 * 2.50) + ((cm_reading - 200) * 6);
else
Billpay =
(100 * 1) + (100 * 2.50) + (300 * 4) + ((cm_reading - 500) * 7);
break;
}
return Billpay;
}
void display ()
{
System.out.println ("----------------------------------");
System.out.println ("ELCTRICITY Billpay");
System.out.println ("----------------------------------");
System.out.println ("Consumer Number: " + cno);
System.out.println ("Consumer Name: " + cname);
System.out.println ("Consumer Previous Units: " + pm_reading);
System.out.println ("Consumer Current Units: " + cm_reading);
System.out.println ("Type of EBConection: " + EBCon);
System.out.println ("----------------------------------");
System.out.println ("Total Amount(Rs.): " + Billpay);
}
}
class Main
{
public static void main (String[]args)
{
EBBillpay b = new EBBillpay ();
b.input_data ();
b.calculate_Billpay ();
b.display ();
}
}