Question

In: Computer Science

A shipping company uses the following function to calculate the cost (in dollars) of shipping based...

A shipping company uses the following function to calculate the cost (in dollars) of shipping based on the weight of the package in pounds:

Weight Cost
0 < w <= 1 3.5
1 < w <= 3 5.5
3 < w <= 10 8.5
10 < w <= 20 10.5

Your program, named  Shipping.java should ask for the weight of the package and display the shipping cost. If the weight is negative or zero, display a message “Invalid input.” If the weight is greater than 20, display a message “The package cannot be shipped.”

Here is an example of the output of the program. Your output does not have to look exactly like this, but it must reflect the same information. User input is shown in bold.

Enter weight of package in pounds: 5.7
Cost: $8.50

Enter weight of package in pounds: 25.2
The package cannot be shipped.

What I did:

import java.util.Scanner;

public class Shipping
{
public static void main(String[]args)
{
Scanner input = new Scanner(System.in);

System.out.println("Enter weight of package in pounds"+" ");

double weight = input.nextDouble();

double cost;
  

if(weight<=1&&weight>0)
{
cost=3.5;
System.out.println("Cost:"+" "+"$"+cost);
  
  
}
else if(weight<=3&&weight>1)
{
cost=5.5;
  
System.out.println("Cost:"+" "+"$"+cost);
}
else if(weight<=10&&weight>3)
{
cost =8.5;
System.out.println("Cost:"+" "+"$"+cost);

}
else if(weight<=20&&weight>10)
{
cost=10.5;
System.out.println("Cost:"+" "+"$"+cost);
}
else if(weight==0||weight<0)
{
  
System.out.println( "Invalid input.");
  
  
}
else
{
  
System.out.println( "The package cannot be shipped.");

}
}   
}

Is this correct?

Solutions

Expert Solution

Yes, It is absolutely correct as it is giving good results for every possbile inputs.

Sample run screenshots:


Related Solutions

This quiz is based on the following information: Calculate the cost of capital for company with...
This quiz is based on the following information: Calculate the cost of capital for company with the following capital structure >1,500,000 ordinary shares, market price R4 per share. Last dividend was 93c per share. Dividend growth was 14% for past 5 years >1,000,000 12%, R1 preference shares with market value of R3 per share >R1,000,000 9% debenture due in 7 year and the current YTM is 10% >R1,300,000 15% bank loan, due in June 2024 >Company tax rate is 30%
A vegetable canning company uses 730 shipping crates a month, which it purchases at a cost...
A vegetable canning company uses 730 shipping crates a month, which it purchases at a cost of $10 each. The manager has assigned an annual carrying cost of 35 percent of the purchase price per crate. Ordering costs are $28. Currently the manager orders once a month. (Round intermediate calculations and final answer to 2 decimal places. ) a. What is the EOQ? EOQ = ____ crates b. How much could the firm save annually in ordering and carrying costs...
Assuming that the company uses the CAPM to calculate its cost of equity. Calculate its weighted average cost of capital.
Royta Ltd, operates in the commercial painting industry. They have reluctantly come to the conclusion that some of their older equipment is reaching the end of its productive life and will need to be replaced sooner or later. They have asked for your assistance in determining their cost of capital in order to make this decision. Their present capital structure is as follows: 1 200 000 R2 ordinary shares now trading at R2,20 per share.  80 000 preference shares...
A shipping company believes that the variation in the cost of a customer’s shipment can be...
A shipping company believes that the variation in the cost of a customer’s shipment can be explained by differences in the weight of the package being shipped. To investigate whether this relationship is useful, a random sample of 20 customer shipments was selected, and the weight (in lb.) and the cost (in dollars, rounded) for each shipment were recorded. The following results were obtained: Weight (lbs.) Cost (Dollars) 8 11 6 8 5 11 7 11 12 17 9 11...
Python 3 Calculate factorial Create a function that uses a loop to calculate the factorial of...
Python 3 Calculate factorial Create a function that uses a loop to calculate the factorial of a number. * function name: get_fact * parameters: num (int) * returns: int * operation: Must use a loop here. Essentially calculate and return the factorial of whatever number is provided. but: - If num is less than 1 or greater than 20, print "num is out of range" and exit the function - If num is not an int, print "invalid num parameter"...
1. Quiz Company uses activity-based costing to determine product cost. The accounting department identified the following...
1. Quiz Company uses activity-based costing to determine product cost. The accounting department identified the following overhead activities, costs, and activity drivers for the coming year. Activity Estimated cost Activity driver Activity capacity Setting up equipment $120,000 Number of setups 300 Ordering materials 90,000 Number of orders 9,000 Maintaining machines      210,000 Machine hours 21,000      Total overhead $420,000 The following actual results were collected for the production of Model X and Model Y during the year. Model X Model...
Company uses activity-based costing to determine product cost. The accounting department identified the following overhead activities,...
Company uses activity-based costing to determine product cost. The accounting department identified the following overhead activities, costs, and activity drivers for the coming year. Activity Estimated cost Activity driver Activity capacity Setting up equipment $120,000 Number of setups 300 Ordering materials 90,000 Number of orders 9,000 Maintaining machines 210,000 Machine hours 21,000 Total overhead $420,000 The following actual results were collected for the production of Model X and Model Y during the year. Model X Model Y Units produced 8,000...
Using High-Low to Calculate Fixed Cost, Calculate the Variable Rate, and Construct a Cost Function Pizza...
Using High-Low to Calculate Fixed Cost, Calculate the Variable Rate, and Construct a Cost Function Pizza Vesuvio makes specialty pizzas. Data for the past 8 months were collected: Month Labor Cost Employee Hours January $7,000   360 February 8,140 550 March 9,899 630 April 9,787 610 May 8,490 480 June 7,450 350 July 9,490 570 August 7,531 310 Pizza Vesuvio's controller wants to calculate the fixed and variable costs associated with labor used in the restaurant. In your calculations, round the...
Based on the following information, calculate the cost of goods sold and ending inventory using FIFO,...
Based on the following information, calculate the cost of goods sold and ending inventory using FIFO, LIFO, and weighted average assuming a perpetual inventory system is in place. Beginning Balance - 90 units at $11 March 3 - Purchase 300 units for $15 April 4 - Sell 240 units for $28 June 30 - Purchase 250 units for $18 August 16 - Sell 180 units for $30
Calculate net income based on the following information. Sales are $250, cost of goods sold is...
Calculate net income based on the following information. Sales are $250, cost of goods sold is $160, depreciation expense is $35, interest paid is $20, and the tax rate is 34%.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT