Changes in the economy have determined that for the EZ shipping company, a surch
ID: 3848188 • Letter: C
Question
Changes in the economy have determined that for the EZ shipping company, a surcharge will be assessed on all packages that meet certain criteria. The surcharge is a function of the characteristics of the package and the zip code to which it is sent.
1. The regular charges for shipping are calculated as follows:
For all weights five pounds and under, the shipping cost is $12.00.
For weights over five pounds, the charge is calculated as follows:
If length * width * height + weight is:
greater than 5 and less than or equal to 15, the shipping cost is 14.00
greater than 15 and less than or equal to 34, the shipping cost is 17.00
greater than 34 and less than or equal to 45, the shipping cost is 21.00
greater than 45 and less than or equal to 60, the shipping cost is 33.00
greater than 60, the shipping cost is 105.00
2. The additional charges are calculated as follows:
If the first digit of the zip code is a "4" then there is an additional surcharge of 5% on
the shipping cost.
If the first digit of the zip code is a "6" then there is an additional surcharge of 9% on
the shipping cost.
For all other zip codes there is an additional surcharge of 14% on the shipping cost.
3. Finally, if the zip code is even, then there is an additional surcharge of 2% of the shipping
cost.
Write a program that allows the user to input (in this order) the zip code, weight, length, width and height of the package then prints out the following:
The zip code and dimensions of the package
The shipping cost
The surcharge
The total shipping cost (shipping cost plus surcharge(s))
This program should be well documented (comments for the programmer and user) both internally and externally. For this program, you will need to use Dialog and Message Boxes, and continue to use them for all programs from this point on.
I am using the program jGRASP to complete this assignment, NOT VBA, thank you in advance!
Explanation / Answer
import java.util.Scanner;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class HelloWorld {
public static void main(String []args){
String zipcode;
double weight;
double length;
double width;
double height;
double scost;
double scharge;
Scanner input = new Scanner( System.in );
System.out.println("Enter the Zip Code: ");
zipcode = input.nextLine();
System.out.println("Enter the Weight: ");
weight = input.nextDouble();
System.out.println("Enter the Lenght: ");
length = input.nextDouble();
System.out.println("Enter the Width: ");
width = input.nextDouble();
System.out.println("Enter the Height: ");
height = input.nextDouble();
if (weight <= 5) {
scost = 12;
}else if (length * width * height + weight <= 15) {
scost = 14;
}else if (length * width * height + weight <= 34) {
scost = 17;
}else if (length * width * height + weight <= 45) {
scost = 21;
}else if (length * width * height + weight <= 60) {
scost = 33;
}else{
scost = 105;
}
if (zipcode.substring(0, 1).equals('4')) {
scharge = scost * .05;
}else if (zipcode.substring(0, 1).equals('6')) {
scharge = scost * .09;
}else{
scharge = scost * .14;
}
if (Integer.parseInt(zipcode) % 2 == 0) {
scharge = scost * .02;
}
//System.out.println("zip code: " + zipcode);
//System.out.println("Length: " + length);
//System.out.println("Width: " + width);
//System.out.println("Height: " + height);
//System.out.println("Shipping cost: " + scost);
//System.out.println("Surcharge: " + scharge);
//System.out.println("Total shipping cost : " + (scost + scharge));
JFrame frame = new JFrame("HelloWorld");
JOptionPane.showMessageDialog(frame, "zip code: " + zipcode + " Length: " + length + " Width: " + width + " Height: " + height + " "
+ "Shipping cost: " + scost + " Surcharge: " + scharge + " Total shipping cost : " + (scost + scharge));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.