Changes in the economy have determined that for the EZ shipp
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))
I have written out the code and have been able to get it to run but when I added in the 2% for even numbers portion of my code every thing went weird with my outputs. Every thing still compiles and works but I am not recieving the outputs I desire. Any help remedying 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 shipping process
   
 Scanner keyboard = new Scanner(System.in);
 System.out.println(\"Hello, Welcome to EZ Shipping services! \  Please input the important details of your shipment when prompted\");
 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 is increased to 14$
    }
 else if (packages >= 15.1 || packages <= 34 )
    {
 shippingCost= 17;
 // if the package weight is above 15 but less than 34 the cost is increased to 17$
    }
 else if (packages >= 34.1 || packages <= 45)
    {
 shippingCost= 21;
 // if the package weight is above 34 but less than 45 the cost is increased to 21$
 
    }
 else if (packages >= 45.1|| packages <= 60)
    {
 shippingCost= 33;
 // if the package weight is above 45 but less than 60 the cost is increased to 33$
 
    }
 else if (packages > 60)
    {
 shippingCost= 105;
 // if the package weight is above 60 cost is increased to a flat 105$
 
    }
 }
 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 add surcharge 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
    }
 }
 }
Solution
Explanation:
Syntax of IF condition
if(boolean) {
statements;
}
This will executes, entire block. If we have only one statement need of parenthesis( { } ) is optional.
if(boolean)
statement;
But if you give semicolon after if condition, That will ends their only.
That is if(condition); if condition ends with semicolon. It does not contains any statement(s).
Infinity FOR loop: for(;;); is here.
if (zip % 2 == 0 );
 surcharge2 = shippingCost*.02;
Replace your code AS:
if (zip % 2 == 0)
 surcharge2 = shippingCost * .02;
 else
 surcharge2 = 0.d;
__________________________________________________________________________________________________
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 shipping process
           Scanner keyboard = new Scanner(System.in);
            System.out
                    .println(\"Hello, Welcome to EZ Shipping services! \  Please input the important details of your shipment when prompted\");
            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 is increased to 14$
                } else if (packages >= 15.1 || packages <= 34) {
                    shippingCost = 17;
                    // if the package weight is above 15 but less than 34 the
                    // cost is increased to 17$
                } else if (packages >= 34.1 || packages <= 45) {
                    shippingCost = 21;
                    // if the package weight is above 34 but less than 45 the
                    // cost is increased to 21$
               } else if (packages >= 45.1 || packages <= 60) {
                    shippingCost = 33;
                    // if the package weight is above 45 but less than 60 the
                    // cost is increased to 33$
               } else if (packages > 60) {
                    shippingCost = 105;
                    // if the package weight is above 60 cost is increased to a
                    // flat 105$
               }
            }
            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;*/
                if (zip % 2 == 0)
                    surcharge2 = shippingCost * .02;
                else
                    surcharge2 = 0.d;
                // calculation for if package is even zip code or not, if even
                // add surcharge 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
        }
    }
 }
This code working fine. Thank Tou
Let me know any concerns





