Question: Need help quick need to pass junit for this program due soon. A shipping company uses the following function to calculate the cost (in dollars)

Need help quick need to pass junit for this program due soon.

A shipping company uses the following function to calculate the cost (in dollars) of shipping based on the weight of the package (in pounds). () = {$3.50 0 < 1 $5.50 1 < 3 $8.50 3 < 10 $10.50 10 < 20 Write a program that prompts the user to enter the weight of the package and displays the resulting shipping cost. If the weight is outside the valid bounds, display an error message (supplied as a constant). For example: Enter package weight: 3.6 It will cost $8.50 to ship this package. Enter package weight: 0.4 It will cost $3.50 to ship this package. Enter package weight: 20.1 The package cannot be shipped! To begin, first implement the shippingCost method to convert weight to cost then you MUST use this in your main, where you will perform all user input/output.

package edu.wit.cs.comp1050; import java.util.Scanner; //TODO: document this class public class PA1d { /** * Error message to display for negative amount */ public static final String ERR_MSG = "The package cannot be shipped!"; /** * Method to compute shipping cost * * @param weight, assumed to be in (0, 20] * @return cost to ship */ public static double shippingCost(double weight) { return 0.0; // TODO: replace with your method implementation }

// TODO: document this method public static void main(String[] args) { // TODO: write your code here System.out.print("Enter the weight of the package: "); double weight = input.nextDouble();

// Calculate cost of shipping if (weight > 50) System.out.println("The package cannot be shipped."); else { double costPerPound; if (weight > 0 && weight <= 1) costPerPound = 3.5; else if (weight <= 3) costPerPound = 5.5; else if (weight <= 10) costPerPound = 8.5; else //if (weight <= 20) costPerPound = 10.5; System.out.println("Shipping cost of package is $" + costPerPound * weight); } } }

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!