Wednesday
September 2, 2015

Homework Help: Computer Science Computer Programming

Posted by AB on Monday, May 21, 2012 at 9:01pm.

Please help! I cannot figure out what I am doing wrong. I cannot get the correct output when I run the system.

Here is what I have entered in to Netbeans IDE:

package shippingcharges;

public class ShippingCharges
{
private double weight;
private int miles;

public ShippingCharges (double w, int m)
{
weight = w;
miles = m;
}

public double getShippingCharges()
{

double charges;

if (weight <=2.0);
{
charges = 1.10 * (miles/500);
}
if ((weight >2.0) && (weight <= 6.0))
{
charges = 2.20 * (miles/ 500);
}
else if ((weight >6.0) && (weight <= 10.0))
{
charges = 3.70 * (miles/ 500);
}
else
{
charges = 3.80 * (miles/ 500);
}

return charges;

}
}


Next one is:

package shippingcharges;

import java.text.DecimalFormat;
import java.util.Scanner;

public class charges
{
public static void main(String[] args)
{
double weight;
int miles;

Scanner keyboard = new Scanner(System.in);

DecimalFormat money = new DecimalFormat("0.00");

System.out.print("Enter the package weight: ");
weight = keyboard.nextDouble();
System.out.print("Enter the miles shipped: ");
miles = keyboard.nextInt();

ShippingCharges myPackage = new ShippingCharges (weight, miles);

System.out.println("Total charges will be $" +
money.format(myPackage.getShippingCharges()));
}
}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

More Related Questions

Members