-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject2Coursework.java
More file actions
143 lines (87 loc) · 3.55 KB
/
Copy pathProject2Coursework.java
File metadata and controls
143 lines (87 loc) · 3.55 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package project2coursework;
import java.util.Scanner;
public class Project2Coursework {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double typePricing;
double totalPrice;
System.out.println("---------------------------------------------------");
System.out.println("====== Electricity Calculator ======");
System.out.println(" ");
System.out.println("Pricing : 1) 0 - 250: 0.10/kWh");
System.out.println ( " 251 - 500: 0.12/kWh");
System.out.println(" 500+ - 0.15/kWh");
System.out.println("---------------------------------------------------");
while (true)
{
System.out.println("Input how much Kw of electricity you consumed ");
if (scanner.hasNextDouble())
{
double input = scanner.nextDouble();
if (input <= 0)
{
System.out.println("Kw cannot be negative number or 0 ");
}
if (input > 0 && input <= 250)
{
typePricing = type();
totalPrice = input * 0.1 + typePricing;
System.out.println("Fixed expenses = "+typePricing);
System.out.println("Scale 1 pricing = "+input * 0.1);
System.out.println("The total price of your bill is "+totalPrice);
break;
}
else if (input > 250 && input <= 500)
{
typePricing = type();
totalPrice = (input - 250) * 0.12 + (250*0.1) + typePricing;
System.out.println("Fixed expenses = "+typePricing);
System.out.println("Scale 1 pricing = "+250 * 0.1);
System.out.println("Scale 2 pricing = "+(input - 250)*0.12);
System.out.println("The total price of your bill is "+totalPrice);
break;
}
else if (input > 500 )
{
typePricing = type();
totalPrice = (input - 500)*0.15 + typePricing + 250 * 0.1 +250 * 0.12;
System.out.println("Fixed expenses = "+typePricing);
System.out.println("Scale 1 pricing = "+250 * 0.1);
System.out.println("Scale 2 pricing = "+250*0.12);
System.out.println("Scale 3 pricing = "+(input - 500)*0.15);
System.out.println("The total price of your bill is "+totalPrice);
break;
}
}
else
{
System.out.println("Wrong input,try again");
scanner.next();
}
}
}
public static int type()
{while (true)
{
Scanner scanner1 = new Scanner(System.in);
System.out.println("Press 1 or 2 (1 for residential/2 for commercial) ");
if (scanner1.hasNextInt())
{
int type = scanner1.nextInt();
if (type == 1)
{
return 5;
}
else if (type == 2)
{
return 12;
}
}
else
{
System.out.println("Wrong input ") ;
scanner1.next();
}
}
}
}