The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
this code runs properly but the shipping charge cost show 0.Â
can someone help me to find what's wrong with this codeÂ
Â
Â
import java.util.Scanner;
/**
The Fast Freight Shipping company charges the following rates:
*
* Weight of Package
Rate per 500 Miles
Shipped
*
*
2 pounds or less
$1.10
*
Over 2 pounds but not more than 6 pounds
$2.20
*
Over 6 pounds but not more than 10 pounds
$3.70
*
Over 10 pounds
$3.80
*
* The shipping charges per 500 miles are not prorated. For example, if a 2pound package
* is shipped 550 miles, the charge would be $2.20. Write a program that asks
the user to enter
* the weight of a package and then displays the shipping charges.
*/
public class ShippingCharges
{
public static void main (String args) {
int weight = 0;
double distance = 0.0;
double rate;
int distanceMultiplier = (int)distance / 500;
//int distance;
Scanner input = new Scanner(System.in);
System.out.println("What is the weight of the package");
weight = input.nextInt();
System.out.println("What is the shipping distance");
distance = input.nextDouble();
distance = (int)distance % 500;
if (distance == 0)
{
if (weight <= 2)
System.out.println("Total Shipping Cost
(distanceMultiplier * 1.10));
}
else if (weight > 2 && weight <= 6)
{
System.out.println("Total Shipping Cost is:
(distanceMultiplier * 2.20));
}
else if (weight > 6 && weight <= 10)
{
System.out.println("Total Shipping Cost is:
(distanceMultiplier * 3.70));
}
else
{
System.out.println("Total Shipping Cost is:
(distanceMultiplier * 3.80));
} is: $ " + $ " + $ " + $ " + if (distance != 0)
{
if (weight <= 2)
System.out.println("Total Shipping Cost is: $ " + (distanceMultiplier + 1) * 1.10);
}
else if (weight > 2 && weight
{
System.out.println("Total
+ 1) * 2.20);
}
else if (weight > 6 && weight
{
System.out.println("Total
+ 1) * 3.70);
}
else
{
System.out.println("Total
+ 1) * 3.80);
System.exit(0);
}
} } <= 6)
Shipping Cost is: $ " +(distanceMultiplier
<= 10)
Shipping Cost is: $ " +(distanceMultiplier Shipping Cost is: $ " +(distanceMultiplier