-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCellPhoneBillReport.java
More file actions
125 lines (100 loc) · 3.37 KB
/
CellPhoneBillReport.java
File metadata and controls
125 lines (100 loc) · 3.37 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
//Program Name: CellPhoneBillReport
//Author: Patricia Baker and Joshua Decker
//Class: CSC110
//Date Written: 3/5/2022
//Brief Description: Program displays a report that includes the customer name, year, highest bill, the number of bills over a set amount, lowest bill,
//and the total annual bill for a cell phone customer,
package ch6;
import java.text.NumberFormat;
import java.util.Scanner;
public class CellPhoneBillReport {
public static void main(String[] args)
{
Scanner scnr = new Scanner(System.in);
NumberFormat cFmt = NumberFormat.getCurrencyInstance();
String name= "";
String year = "";
//Monthly cell phone bills in dollars
double[] cellPhoneBill = {45.24, 54.67, 43.66, 55.32, 67.19, 44.61,
65.29, 49.75, 43.21, 44.67, 56.99, 64.34};
//corresponding months
String[] month = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
double highestBill = cellPhoneBill[0];
double lowestBill = cellPhoneBill[0];
double totalBill = 0;
int countHigh = 0;
double highMark = 50.00;
System.out.println("Welcome Valued Customer");
System.out.print("Please enter your name: ");
name = scnr.next();
System.out.print("Please enter the year: ");
year = scnr.next();
//find the highest bill
for (int i = 0; i < month.length; i++) {
if (cellPhoneBill[i] > highestBill) {
highestBill = cellPhoneBill[i];
}
}
//find the lowest bill
for (int i = 0; i < month.length; i++) {
if (lowestBill > cellPhoneBill[i]) {
lowestBill = cellPhoneBill[i];
}
}
//find the number of monthly bills above the highMark
for (int i = 0; i < month.length; i++) {
if(cellPhoneBill[i] >= highMark) {
countHigh++;
}
}
//determine annual total bill
for (int i = 0; i < month.length; i++) {
totalBill = totalBill + cellPhoneBill[i];
}
//display report title and dashes (adjusts based on name)
System.out.println("\nAnnual Cell Phone Report for " + name);
for(int x = 0; x < name.length() + 29; x++)
System.out.print("-");
System.out.println();
//display month and corresponding bill amounts
for (int i = 0; i < month.length; i++) {
System.out.println(month[i] + ": \t" + cFmt.format(cellPhoneBill[i]));
}
System.out.println();
//display results - see example in assignment
System.out.println("Monthly bills >$50.00: " + countHigh);
System.out.println("Highest monthly bill : " + cFmt.format(highestBill));
System.out.println("Lowest monthly bill : " + cFmt.format(lowestBill));
System.out.println("Annual bill for " + year + " : " + cFmt.format(totalBill));
//display dashes
for(int x = 0; x < name.length() + 29; x++)
System.out.print("-");
System.out.println();
scnr.close();
}
}
/*
Welcome Valued Customer
Please enter your name: Josh
Please enter the year: 2022
Annual Cell Phone Report for Josh
---------------------------------
JAN: $45.24
FEB: $54.67
MAR: $43.66
APR: $55.32
MAY: $67.19
JUN: $44.61
JUL: $65.29
AUG: $49.75
SEP: $43.21
OCT: $44.67
NOV: $56.99
DEC: $64.34
Monthly bills >$50.00: 6
Highest monthly bill : $67.19
Lowest monthly bill : $67.19
Annual bill for 2022 : $634.94
---------------------------------
*/