title: I need help understanding the programming challenge called Shipping Charges
body: <p>The question says The Fast Freight Shipping Company charges the following rates: </p>
  
  <pre><code>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
  </code></pre>
  
  <p>The shipping charge per 500 miles are not prorated. For example, if a 2-pound package is shipped 550 miles, the charges would be $2.20. Write a program that asks the user to enter the weight of a package and then displays the shipping charges.</p>
  
  <p>My problem is that I keep receiving two different answers everytime I put in a weight and distance. For example when I enter the weight as 2 pounds and the distance as 500 miles I get the answers $0.0 and $3.8 which are both incorrect answers. It looks like some weights that I enter are correct answers and others I enter give me incorrect answers. Heres my program:</p>
  
  <pre><code>//import java utilities for scanner class
  import java.util.Scanner;           
  
  
  
  public class ShippingCharge
  
  {
  
  public static void main (String[] args)
  
  {
  
  
  //Declare and initialize variable to hold the entered weight.
  int weight = 0;                                        
  
  //Declare and initialize variable to hold the entered distance.
  double distance = 0.0;                                
  
  //This variable will hold the calculated rate.
  double rate; 
  
  //This will decide if the shipping charge will advance up one level.
  int distanceMultiplier = (int)distance / 500;  
  
  //This will hold the increments of the shipping charge.
  int distanceRemainder;                                  
  
  //Create a Scanner object for the input.
  Scanner input = new Scanner(System.in);        
  
  //Get the weight of the package.
  System.out.println("What is the weight of the package (in pounds)?");
  
  weight = input.nextInt();
  
  //Get the shipping distance of the package.
  System.out.println("What is the shipping distance (in miles)?");
  
  distance = input.nextDouble();
  
  distanceRemainder = (int)distance % 500;
  if (distanceRemainder == 0)
  {
  if (weight &lt;= 2)
      System.out.println("Total Shipping Cost is: $" + (distanceMultiplier * 1.10));
      }
  else if (weight &gt; 2 &amp;&amp; weight &lt;= 6)
  {
      System.out.println("Total Shipping Cost is: $" + (distanceMultiplier * 2.20));
      }
  else if (weight &gt; 6 &amp;&amp; weight &lt;= 10)
  {
      System.out.println("Total Shipping Cost is: $" + (distanceMultiplier * 3.70));
      }
  else
  {
      System.out.println("Total Shipping Cost is: $" + (distanceMultiplier * 3.80));
      }
  
  if (distanceRemainder != 0)
  {
      if (weight &lt;= 2)
      System.out.println("Total Shipping Cost is: $" +(distanceMultiplier + 1) * 1.10);
      }
  else if (weight &gt; 2 &amp;&amp; weight &lt;= 6)
  {
      System.out.println("Total Shipping Cost is: $" +(distanceMultiplier + 1) * 2.20);
      }
  else if (weight &gt; 6 &amp;&amp; weight &lt;= 10)
  {
  
      System.out.println("Total Shipping Cost is: $" +(distanceMultiplier + 1) * 3.70);
  
      }
  else
  {
      System.out.println("Total Shipping Cost is: $" +(distanceMultiplier + 1) * 3.80);
  
      }
  
   //end program
   System.exit(0);
  
   }//end main
   }//end class
  </code></pre>