Question

In: Computer Science

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

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! \n 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
   }
}
}

Solutions

Expert 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! \n 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


Related Solutions

Discuss the various factors of productivity, how it is determined and changes that have occurred over...
Discuss the various factors of productivity, how it is determined and changes that have occurred over time that have increased productivity. Use the production function - Y = AF(L,K,H,
Have you ever wondered how the health of the economy is determined without a thermometer? In...
Have you ever wondered how the health of the economy is determined without a thermometer? In this activity, you will select a country and explore the concepts of nominal and real GDP to measure the economic health of your country. As part of your research, you will also explore these key economic factors. Key Economic Factors Gross domestic product (GDP) Unemployment Poverty rates Housing Starts Key Economic Factors GDP per capita Inflation Human development index Standard & Poor's 500 Key...
What are the four factors that determined the current modern economy? • How have these factors...
What are the four factors that determined the current modern economy? • How have these factors changed over the course of the 30 years? • How do the shifts manifest in the world economy? Give at least five examples. • What are the implications for business in North America? Great Britain? Hong Kong? • Initiate a discussion based upon your country of choice and the state of the economy there. • Look at the history of your country’s economy basis,...
81) You are a engineer in a shipping company and you have identified some corrosion on...
81) You are a engineer in a shipping company and you have identified some corrosion on one of your ocean freighters that is occurring below the water line, around rivets that have some kind of green slime covering them. What’s happening and what can you do to mitigate the problem? . Please answer in clear words NO guessing!!! Thanks
EZ Clean-Up Inc. (EZ Clean-Up or the “Company”) provides various set-up, tear-down, and clean-up services to...
EZ Clean-Up Inc. (EZ Clean-Up or the “Company”) provides various set-up, tear-down, and clean-up services to party-planning businesses as well as various third-party customers. The Company entered into a contract with The Function Junction LLC to be the sole provider of its services for all its events for a period of three years. The Function Junction holds weekly events, with EZ Clean-Up providing its services for every event. After the initial three-year period, the contract is renewable in one-year increments....
EZ Clean-Up Inc. (EZ Clean-Up or the “Company”) provides various set-up, tear-down, and clean-up services to...
EZ Clean-Up Inc. (EZ Clean-Up or the “Company”) provides various set-up, tear-down, and clean-up services to party-planning businesses as well as various third-party customers. The Company entered into a contract with The Function Junction LLC to be the sole provider of its services for all its events for a period of three years. The Function Junction holds weekly events, with EZ Clean-Up providing its services for every event. After the initial three-year period, the contract is renewable in one-year increments....
What is meant by a ‘global city’? How have ‘changes in production’ and the ‘global economy’...
What is meant by a ‘global city’? How have ‘changes in production’ and the ‘global economy’ contributed to the emergence of global cities? What spatial structure and features characterize global cities? What is their typical social structure? How do they differ from other cities linked into the global economy?
Do you agree that the changes in the economy will have a long-term effect after the...
Do you agree that the changes in the economy will have a long-term effect after the covid 19 pandemic?
Evaluate Grade for Shipping Company - Code in Java There are many Shipping companies emerging in...
Evaluate Grade for Shipping Company - Code in Java There are many Shipping companies emerging in the market now. 'SaySo' online survey panel has come up with the strategy to choose the best Shipping Company for your shipping needs. The survey panel has taken into consideration two factors of the companies namely the number of countries a shipping Company offers its services (country coverage) and number of shipments done per month. The survey panel has graded the companies based on...
Assume the Zambian economy is determined by following functions:
Assume the Zambian economy is determined by following functions:Y = Real GDP or national incomeT = Taxes = 0.3YC = Consumption = K140 + 0.9(Y – T)I = Investment = K400G = Government spending = K800X = Exports = K600M = Imports = 0.15YFind the equilibrium level of income.                                                             Fill in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT