-
Notifications
You must be signed in to change notification settings - Fork 0
/
mgwright_Shipping.java
85 lines (73 loc) · 1.91 KB
/
mgwright_Shipping.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Name : Matthew Wright
// Class : 1400-005
// Program # : 10
// Due Date : Monday, March 9, 2009 @ 11:59 PM
//
// Honor Pledge : On my honor as a student of the University
// of Nebraska at Omaha, I have neither given nor received
// unauthorized help on this homework assignment.
//
// NAME: Matthew Wright
// NUID: 832
// EMAIL: [email protected]
// Partners: NONE
// Description: This program accepts a distance and a weight and calculates the cost for shipping.
import java.util.Scanner;
public class mgwright_Shipping
{
public static void main( String args[] )
{
//initialize variables and Scanner
int weight = 0;
int distance = 0;
double rate = 0.0;
double totalCost = 0.0;
Scanner in = new Scanner(System.in);
System.out.println("Welcome to Matt's Magical World of Shipping Wonderfullness!");
//accept and validate user input and store into appropriate variables
do
{
System.out.print("How far will you be shipping the package in miles? ");
distance = in.nextInt();
} while(distance < 1);
do
{
System.out.print("How heavy is your package in pounds (1-65)? ");
weight = in.nextInt();
} while(weight < 1 || weight > 65);
//Calculate and process shipping rate
if(weight >= 1 && weight <= 4)
{
rate = 2.34;
}
else if(weight >= 5 && weight <= 12)
{
rate = 4.31;
}
else if(weight >= 13 && weight <= 22)
{
rate = 6.01;
}
else if(weight >= 23 && weight <= 45)
{
rate = 6.27;
}
else if(weight >= 46 && weight <= 65)
{
rate = 7.01;
}
if(distance >= 1 && distance <= 25)
{
totalCost = rate;
}
else if(distance > 25)
{
totalCost = rate * (distance / 25);
if(distance % 25 != 0)
totalCost += rate;
}
//output shipping and cost information
System.out.printf("The shipping rate is $%f per 25 miles.\n", rate);
System.out.printf("Your total shipping cost for %d mile(s) is $%f\n", distance, totalCost);
}
}