SlideShare a Scribd company logo
1 of 8
Download to read offline
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

More Related Content

More from fckindswear

Describe two ecological roles of fungi. Related concepts decomposer.pdf
Describe two ecological roles of fungi. Related concepts decomposer.pdfDescribe two ecological roles of fungi. Related concepts decomposer.pdf
Describe two ecological roles of fungi. Related concepts decomposer.pdf
fckindswear
 
Differential equations using phase plane analysis. Task 1 (Romeo .pdf
Differential equations using phase plane analysis. Task 1 (Romeo .pdfDifferential equations using phase plane analysis. Task 1 (Romeo .pdf
Differential equations using phase plane analysis. Task 1 (Romeo .pdf
fckindswear
 
Develop a stack in c with dynamic memory allocation. Use the followi.pdf
Develop a stack in c with dynamic memory allocation. Use the followi.pdfDevelop a stack in c with dynamic memory allocation. Use the followi.pdf
Develop a stack in c with dynamic memory allocation. Use the followi.pdf
fckindswear
 
2. July 01 Record the dividend received from the foreign subsidiary..pdf
2. July 01 Record the dividend received from the foreign subsidiary..pdf2. July 01 Record the dividend received from the foreign subsidiary..pdf
2. July 01 Record the dividend received from the foreign subsidiary..pdf
fckindswear
 
You have isolated a new virus, determined it has a lipid envelope,.pdf
You have isolated a new virus, determined it has a lipid envelope,.pdfYou have isolated a new virus, determined it has a lipid envelope,.pdf
You have isolated a new virus, determined it has a lipid envelope,.pdf
fckindswear
 
Write the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdfWrite the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdf
fckindswear
 
Why is agrobacterium tumfaciens useful to Kant biologists Describ.pdf
Why is agrobacterium tumfaciens useful to Kant biologists Describ.pdfWhy is agrobacterium tumfaciens useful to Kant biologists Describ.pdf
Why is agrobacterium tumfaciens useful to Kant biologists Describ.pdf
fckindswear
 
What are socioecology and sociobiology What can they tell us about .pdf
What are socioecology and sociobiology What can they tell us about .pdfWhat are socioecology and sociobiology What can they tell us about .pdf
What are socioecology and sociobiology What can they tell us about .pdf
fckindswear
 

More from fckindswear (20)

Explain the kinds of information that must be maintained in fixed as.pdf
Explain the kinds of information that must be maintained in fixed as.pdfExplain the kinds of information that must be maintained in fixed as.pdf
Explain the kinds of information that must be maintained in fixed as.pdf
 
Dr. P has a culture of stem cells and she wants them to specialize i.pdf
Dr. P has a culture of stem cells and she wants them to specialize i.pdfDr. P has a culture of stem cells and she wants them to specialize i.pdf
Dr. P has a culture of stem cells and she wants them to specialize i.pdf
 
Describe two ecological roles of fungi. Related concepts decomposer.pdf
Describe two ecological roles of fungi. Related concepts decomposer.pdfDescribe two ecological roles of fungi. Related concepts decomposer.pdf
Describe two ecological roles of fungi. Related concepts decomposer.pdf
 
Differential equations using phase plane analysis. Task 1 (Romeo .pdf
Differential equations using phase plane analysis. Task 1 (Romeo .pdfDifferential equations using phase plane analysis. Task 1 (Romeo .pdf
Differential equations using phase plane analysis. Task 1 (Romeo .pdf
 
Develop a stack in c with dynamic memory allocation. Use the followi.pdf
Develop a stack in c with dynamic memory allocation. Use the followi.pdfDevelop a stack in c with dynamic memory allocation. Use the followi.pdf
Develop a stack in c with dynamic memory allocation. Use the followi.pdf
 
Define a struct type that represents a smartphone. The struct should.pdf
Define a struct type that represents a smartphone. The struct should.pdfDefine a struct type that represents a smartphone. The struct should.pdf
Define a struct type that represents a smartphone. The struct should.pdf
 
Broadly speaking, the economy consists of households, firms, governm.pdf
Broadly speaking, the economy consists of households, firms, governm.pdfBroadly speaking, the economy consists of households, firms, governm.pdf
Broadly speaking, the economy consists of households, firms, governm.pdf
 
A committee consists of 13 Republicans and 16 Democrats. How many dif.pdf
A committee consists of 13 Republicans and 16 Democrats. How many dif.pdfA committee consists of 13 Republicans and 16 Democrats. How many dif.pdf
A committee consists of 13 Republicans and 16 Democrats. How many dif.pdf
 
2. July 01 Record the dividend received from the foreign subsidiary..pdf
2. July 01 Record the dividend received from the foreign subsidiary..pdf2. July 01 Record the dividend received from the foreign subsidiary..pdf
2. July 01 Record the dividend received from the foreign subsidiary..pdf
 
You have isolated a new virus, determined it has a lipid envelope,.pdf
You have isolated a new virus, determined it has a lipid envelope,.pdfYou have isolated a new virus, determined it has a lipid envelope,.pdf
You have isolated a new virus, determined it has a lipid envelope,.pdf
 
Write the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdfWrite the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdf
 
Why is agrobacterium tumfaciens useful to Kant biologists Describ.pdf
Why is agrobacterium tumfaciens useful to Kant biologists Describ.pdfWhy is agrobacterium tumfaciens useful to Kant biologists Describ.pdf
Why is agrobacterium tumfaciens useful to Kant biologists Describ.pdf
 
Why are the payback and Accounting or Average Rate of Return sometim.pdf
Why are the payback and Accounting or Average Rate of Return sometim.pdfWhy are the payback and Accounting or Average Rate of Return sometim.pdf
Why are the payback and Accounting or Average Rate of Return sometim.pdf
 
Which of the following are potential differences between the Prokary.pdf
Which of the following are potential differences between the Prokary.pdfWhich of the following are potential differences between the Prokary.pdf
Which of the following are potential differences between the Prokary.pdf
 
When dividing, do we need to report remainder Why When dividi.pdf
When dividing, do we need to report remainder Why When dividi.pdfWhen dividing, do we need to report remainder Why When dividi.pdf
When dividing, do we need to report remainder Why When dividi.pdf
 
What are socioecology and sociobiology What can they tell us about .pdf
What are socioecology and sociobiology What can they tell us about .pdfWhat are socioecology and sociobiology What can they tell us about .pdf
What are socioecology and sociobiology What can they tell us about .pdf
 
Using the code below, answer the questionsFor the toolbar, press AL.pdf
Using the code below, answer the questionsFor the toolbar, press AL.pdfUsing the code below, answer the questionsFor the toolbar, press AL.pdf
Using the code below, answer the questionsFor the toolbar, press AL.pdf
 
true or false Strategy formulation and execution is a sequential pr.pdf
true or false Strategy formulation and execution is a sequential pr.pdftrue or false Strategy formulation and execution is a sequential pr.pdf
true or false Strategy formulation and execution is a sequential pr.pdf
 
The symptoms of depression that occur in a person diagnosed with bip.pdf
The symptoms of depression that occur in a person diagnosed with bip.pdfThe symptoms of depression that occur in a person diagnosed with bip.pdf
The symptoms of depression that occur in a person diagnosed with bip.pdf
 
The first signs of niacin deficiency are all of the following EXCEPT.pdf
The first signs of niacin deficiency are all of the following EXCEPT.pdfThe first signs of niacin deficiency are all of the following EXCEPT.pdf
The first signs of niacin deficiency are all of the following EXCEPT.pdf
 

Recently uploaded

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Recently uploaded (20)

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 

Changes in the economy have determined that for the EZ shipping comp.pdf

  • 1. 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
  • 2. // 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
  • 3. { 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$ }
  • 4. } 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 }
  • 5. } } 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;
  • 6. 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) {
  • 7. 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% }
  • 8. 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