-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathInternetServiceProvider.java
More file actions
65 lines (53 loc) · 2.17 KB
/
Copy pathInternetServiceProvider.java
File metadata and controls
65 lines (53 loc) · 2.17 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
import javax.swing.JOptionPane;
/**@author Lemuel M. Uhuru
* @Date June 16, 2013
* Book Title: From Control Structures through Objects by Tony Gaddis
* Page: 191 Problem 13: Internet Service Provider
*
* @Description Write a program that calculates a customer's monthly bill.
* It should ask the user to the letter of the package the customer has purchased
* (A,B,or C) and the number of hours that were used. It should then display
* the total charges.
*/
public class InternetServiceProvider {
public static void main(String[] args) {
// Declare variables for package prices
double priceA = 9.95;
double priceB = 13.95;
double priceC = 19.95;
// Declare variable to hold user package
char userPackage;
// Declare variable to hold hours used
int hours;
// Prompt user for package type
String input = JOptionPane.showInputDialog("Enter your package letter (A/B/C)").toUpperCase();
// Prompt user for the amount of hours used
String input2 = JOptionPane.showInputDialog("Enter the amount of hours used");
// Convert input2 to data-type int
hours = Integer.parseInt(input2);
// Convert input1 to data-type char using the charAt string method
// which returns the first element within a given string.
userPackage = input.charAt(0);
// Calculate total charges for package A and B
double totalChargesA = ((hours-10) * 2) + priceA;
double totalChargesB = ((hours-20) * 1) + priceB;
// Design switch statement with nested if-else structures
// to display the appropriate total charges.
switch (userPackage){
case 'A':
if(hours > 10)
JOptionPane.showMessageDialog(null, "Package: " + userPackage + "\nTotal Charges: $" + totalChargesA);
else
JOptionPane.showMessageDialog(null, "Package: " + userPackage + "\nTotal Charges: $" + priceA);
break;
case 'B':
if(hours > 20)
JOptionPane.showMessageDialog(null, "Package: " + userPackage + "\nTotal Charges: $" + totalChargesB);
else
JOptionPane.showMessageDialog(null, "Package: " + userPackage + "\nTotal Charges: $" + priceB);
break;
case 'C':
JOptionPane.showMessageDialog(null, "Package: " + userPackage + "\nTotal Charges: $" + priceC);
}
}
}