Question: provide in Java Programming: ShippingCharges Class The Fast Freight Shipping Company charges the following rates: Weight of Package (in kilograms) Rate per 500 Miles Shipped

provide in Java Programming: ShippingCharges Class The Fast Freight Shipping Company charges the following rates: Weight of Package (in kilograms) Rate per 500 Miles Shipped 2 kg or less $1.10 Over 2 kg but not more than 6 kg $2.20 Over 6 kg but not more than 10 kg $3.70 Over 10 kg $4.80 The shipping charges per 500 miles are not prorated.

For example, if a 2 kg package is shipped 550 miles, the charges would be $2.20. Design a class that stores the weight of a package, and has a method that returns the shipping charges.

complete with this files :

ShippingCharges.java class ShippingCharges { public static final double RATE_UNDER_2KGS = 1.1; public static final double RATE_UNDER_6KGS = 2.2; public static final double RATE_UNDER_10KGS = 3.7; public static final double RATE_OVER_10KGS = 4.8;

private void go() {

// Input weight double weight = 0.0; double shippingCharges = computeShippingCharges(weight); System.out.printf("$%.2f Shipping Charges for %.2f KGs", shippingCharges, weight); }

double computeShippingCharges(double weight) { // logic to determine shipping charges using constants above return 0.00; }

public static void main(String[] args) { new ShippingCharges().go(); } }

we need scanner too

ShippingChargeTest.java

import org.junit.Before; import org.junit.Test; import java.text.DecimalFormat;

import static junit.framework.TestCase.assertEquals;

/** * Created by Bill on 5/1/2017. */ public class ShippingChargesTest { ShippingCharges shippingCharges = new ShippingCharges(); DecimalFormat df = new DecimalFormat("0.00");; @Before public void setUp() throws Exception { }

@Test public void computeShippingChargesTest1() throws Exception { double two = 2.0; System.out.println(two + " KGs $" + df.format(shippingCharges.computeShippingCharges(two))); assertEquals(two * shippingCharges.RATE_UNDER_2KGS, shippingCharges.computeShippingCharges(two), .1); } @Test public void computeShippingChargesTest2() throws Exception { double six = 6.0; System.out.println(six + " KGs $" + df.format(shippingCharges.computeShippingCharges(six))); assertEquals(six * shippingCharges.RATE_UNDER_6KGS, shippingCharges.computeShippingCharges(six), .1); } @Test public void computeShippingChargesTest3() throws Exception { double ten = 10.0; System.out.println(ten + " KGs $" + df.format(shippingCharges.computeShippingCharges(ten))); assertEquals(ten * shippingCharges.RATE_UNDER_10KGS, shippingCharges.computeShippingCharges(ten), .1); } @Test public void computeShippingChargesTest4() throws Exception { double overTen = 10.01; System.out.println(overTen + " KGs $" + df.format(shippingCharges.computeShippingCharges(overTen))); assertEquals(overTen * shippingCharges.RATE_OVER_10KGS, shippingCharges.computeShippingCharges(overTen), .1); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!