-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathShippingCharges.java
More file actions
52 lines (42 loc) · 1.42 KB
/
Copy pathShippingCharges.java
File metadata and controls
52 lines (42 loc) · 1.42 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
import javax.swing.JOptionPane;
/**@author Lemuel M. Uhuru
* @Date June 12, 2013
* Book Title: From Control Structures through Objects by Tony Gaddis
* Page: 189 Problem 9: Shipping Charges
*
* @Description Write a program that asks the user to
* enter the weight of a package and then displays the
* shipping charges rated per 500 miles.
*/
public class ShippingCharges {
public static void main(String[] args) {
// Declare String variable for user input.
String input;
// Declare Int variable to store weight of package.
double weight;
// Prompt user for weight of package.
input = JOptionPane.showInputDialog("Enter weight of package in pounds");
// Convert String input to data-type double
weight = Double.parseDouble(input);
// Design decision structure to determine shipping charges
// corresponding to the weight of the package.
if (weight <= 10){
if (weight > 6){
JOptionPane.showMessageDialog(null, " Weight (Pounds): " + weight +
"\n Shipping Charges: $3.70");
}
else if (weight > 2){
JOptionPane.showMessageDialog(null, " Weight (Pounds): " + weight +
"\n Shipping Charges: $2.20");
}
else{
JOptionPane.showMessageDialog(null, " Weight (Pounds): " + weight +
"\n Shipping Charges: $1.10");
}
}
else{
JOptionPane.showMessageDialog(null, " Weight (Pounds): " + weight +
"\n Shipping Charges: 3.80");
}
}
}