-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProcessCustomerReport.java
68 lines (47 loc) · 1.97 KB
/
ProcessCustomerReport.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
import javax.swing.JOptionPane;
public class ProcessCustomerReport {
public static void main (String[] args){
double minKilowatt = 0.0;
double maxKilowatt = 1000.0;
double lowRateKilowattMin = 200.0;
double lowRate = 0.08;
double highRate = 0.11;
double totalOwed = 0.0;
String customerNumber = "";
int numCustomers = 0;
double kilowattUsed = 0;
String report = "";
double amountOwed = 0;
report += "Monthly Billing Report\n";
report += "Customer Number | Customer Name | Kilowatts Used | Amount Owed\n";
customerNumber = JOptionPane.showInputDialog("Please enter the customer number");
while (!customerNumber.equalsIgnoreCase("QUIT")){
String name = JOptionPane.showInputDialog("Please enter you name");
do{
try {
kilowattUsed= Double.parseDouble(JOptionPane.showInputDialog("Please enter the number of kilo watt used"));
}
catch (NumberFormatException e){
JOptionPane.showMessageDialog(null, "Error");
}
if ((kilowattUsed < minKilowatt) || (kilowattUsed >= maxKilowatt)) {
JOptionPane.showMessageDialog(null,"Error!Please enter a valid number of kilowatts");
}
}while (!(kilowattUsed >= minKilowatt && kilowattUsed < maxKilowatt));
if (kilowattUsed < lowRateKilowattMin){
amountOwed = kilowattUsed*highRate;
}
else {
amountOwed = kilowattUsed*lowRate;
}
totalOwed = totalOwed + amountOwed;
numCustomers = numCustomers + 1;
report += customerNumber +"|"+ name + "|" + amountOwed + "\n";
customerNumber = JOptionPane.showInputDialog("Please enter the customer number");
}
if (numCustomers > 0) {
report +="Number of Customers"+ numCustomers + "\nTotal Owed: " + String.format("$%.2f",totalOwed);
}
JOptionPane.showMessageDialog(null, report);
}
}