Changes in the economy have determined that for the EZ shipping company, a surcharge will be...

50.1K

Verified Solution

Question

Programming

Changes in the economy have determined that for the EZ shippingcompany, a surcharge will be assessed on all packages that meetcertain criteria. The surcharge is a function of thecharacteristics of the package and the zip code to which it issent.

1. The regular charges for shipping are calculated asfollows:
     For all weights five pounds and under, theshipping cost is $12.00.

     For weights over five pounds, the chargeis calculated as follows:
                      If length * width * height + weight is:

greater than 5 and less than or equal to 15, the shipping costis 14.00

greater than 15 and less than or equal to 34, the shipping costis 17.00

greater than 34 and less than or equal to 45, the shipping costis 21.00

greater than 45 and less than or equal to 60, the shipping costis 33.00

greater than 60, the shipping cost is 105.00

2. The additional charges are calculated as follows:

            Ifthe first digit of the zip code is a \"4\" then there is anadditional surcharge of 5% on the shipping cost.

If the first digit of the zip code is a \"6\" then there is anadditional surcharge of 9% on the shipping cost.

For all other zip codes there is anadditional surcharge of 14% on the shipping cost.

3. Finally, if the zip code is even, then there is anadditional surcharge of 2% of the shipping

           cost.

Write a program that allows the user to input (in thisorder) the zip code, weight, length, width and height ofthe 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))

I have written out the code and have been able to get it to runbut when I added in the 2% for even numbers portion of my codeevery thing went weird with my outputs. Every thing still compilesand works but I am not recieving the outputs I desire. Any helpremedying this would be greatly appreciated.

import java.util.Scanner;
   //allows use of scanner for keyboard inputs
  
public class Shipping
   // Class titling
{


public static void main(String[] args)

   {

{
int zip;
double weight;
double length;
double width;
double height;
double surcharge;
double surcharge2;
double shippingCost;
  
   //Variables that will need defining for the shippingprocess
  
Scanner keyboard = new Scanner(System.in);
System.out.println(\"Hello, Welcome to EZ Shipping services! \nPlease input the important details of your shipment whenprompted\");
System.out.println(\"What is the weight of your package? \");
weight = keyboard.nextDouble();
System.out.println(\"What is the length of your package? \");
length = keyboard.nextDouble();
System.out.println(\"What is the width of your package? \");
width = keyboard.nextDouble();
System.out.println(\"What is the height of youre package? \");
height = keyboard.nextDouble();
  
//Print outs for package detail inputs

double packages=length*width*height+weight;
//Package variables combined and stored
   {
shippingCost = 12;
//Stock sipping cost 12$

   }
  
if (weight >5)
   {
if (packages >=5.1 || packages <= 15)
   {
shippingCost= 14;
// if the package weight is above 5 but less than 15 the cost isincreased to 14$
   }
else if (packages >= 15.1 || packages <= 34 )
   {
shippingCost= 17;
// if the package weight is above 15 but less than 34 the cost isincreased to 17$
   }
else if (packages >= 34.1 || packages <= 45)
   {
shippingCost= 21;
// if the package weight is above 34 but less than 45 the cost isincreased to 21$

   }
else if (packages >= 45.1|| packages <= 60)
   {
shippingCost= 33;
// if the package weight is above 45 but less than 60 the cost isincreased to 33$

   }
else if (packages > 60)
   {
shippingCost= 105;
// if the package weight is above 60 cost is increased to a flat105$

   }
}
System.out.println(\"What is your zip code? \");
zip = keyboard.nextInt();
  
if(zip == 4)
   {
surcharge = shippingCost*0.05;
// if the zip code starts with a 4 a 5% surcharge is added
   }
   else if(zip == 6)
   {
surcharge = shippingCost*0.09;
// if the zip code starts with a 6 a 9% surcharge is added
   }
   else
   {
surcharge = shippingCost*0.14;
// all other zip codes have a 14% surcharge added
   }
  
{
  
   if (zip % 2 == 0 );
surcharge2 = shippingCost*.02;
// calculation for if package is even zip code or not, if even addsurcharge of 2%
}
double cost = shippingCost + surcharge + surcharge2;
// calculation for cost
double total;
total = shippingCost + surcharge + surcharge2 + packages;
// calculation for total

System.out.print(\"The Shipping Cost $\"+ cost);
System.out.print(\" Total with charges $\"+ total);
// Final read out
   }
}
}

Answer & Explanation Solved by verified expert
4.5 Ratings (677 Votes)
Explanation Syntax of IF condition ifboolean statements This will executes entire block If we have only one statement need of parenthesis is optional ifboolean statement But if you give semicolon after if condition That will ends their only That is ifcondition if condition ends with semicolon It does not contains any statements Infinity FOR loop for is here if zip 2 0 surcharge2 shippingCost02 Replace your code AS if zip 2 0 surcharge2 shippingCost 02 else surcharge2    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students