vendredi 26 février 2016

Shipping Charges Calculator miss calculation

The assignment has 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 charge per 500 miles are not prorated. For example, if a 2 pound package is shipped 502 miles, the charge would be $2.20. Write a program that ask the user to enter the weight of a package and then display the shipping charges.

My issue is that im getting wrong answers. This is what i got so far:

import java.util.Scanner;
public class ShippingCharges
{
public static void main (String [] args)
{
    double mDrive, rMiles, wPound;

    Scanner keyboard = new Scanner (System.in);

    System.out.print ("Enter Weight of Package: ");
    wPound = keyboard.nextDouble();
    System.out.println("");

    System.out.print ("Enter Miles Driven: ");
    mDrive = keyboard.nextDouble();
    System.out.println("");

    rMiles = mDrive / 500;

    if (wPound <2)
    {
        System.out.println ("You will be charged "+ "$" + Math.ceil(rMiles)*1.10);
    }

    if (wPound >=2 && wPound <6)
    {
        System.out.println ("You will be charged "+ "$" + Math.ceil(rMiles)*2.20);
    }

    if (wPound >=6 && wPound <10)
    {
        System.out.println ("You will be charged "+ "$" + Math.ceil(rMiles)*3.70);
    }

    if (wPound >= 10)
    {
        System.out.println ("You will be charged "+ "$" + Math.ceil(rMiles)*3.80);
    }

}
}

Following the example, the program should do 502/500 *2.2 which is 2.2 and the program is showing 4.4. Any suggestion?

Aucun commentaire:

Enregistrer un commentaire