Open Eclipse. Create a New -> Java project. Name it ParkersPackages and click Finish and OK. Next, create a New -> Class. Name it ParkersPackages and be sure to check the first checkbox under "Which method stubs would you like to create?" and click Finish. Delete the green comment text in the file "ParkersPackages.java" Add a comment at the top // (your name) Add another comment at the top // Project 3 Add code to the file "ParkersPackages.java" to create a program that will compute how much it will cost to ship a package based on the package weight and number of miles to the destination. The details of the shipping costs are provided in the table below. Your program should ask the user to enter the weight of the package and store it as a double. Next, your program should ask the user to enter the distance to the destination and store it as an integer. Valid package weights are 1.0 - 50.0 pounds and valid shipping distances are 1 - 3000 miles, so if the weight is not between 1.0 - 50.0 pounds or the distance is not between 1 - 3000 miles, your program should print a message: "Sorry, you have entered invalid data - program terminated", else, your program should determine the costPer200Miles according to the table below. Then, your program should use this value to calculate the cost to ship the package the desired distance. *Requirement 1: Use an if-else statement to check for invalid input and an if-else-if statement to determine the costPer200Miles. *Requirement 2: If the distance goes over 200 miles (even by 1 mile), the customer is charged for another 200 miles (see sample output below) *Requirement 3: Use the printf statement to format your monetary values to 2 decimal places. (see Chapter 3 for help as needed) *Requirement 4: Test your program with both valid and invalid input. *Hint: Use the division & modulus operators in your calculations to determine how much to charge for shipping. *Check your code against the checklist before submission Weight Cost per 200 miles up to 5.0 pounds $10.00 up to 10.0 pounds $20.00 up to 15.0 pounds $30.00 up to 20.0 pounds $40.00 up to 30.0 pounds $50.00 up to 40.0 pounds $60.00 up to 50.0 pounds $70.00 Here are 4 individual sample runs of what your program output should look like: ******Welcome to ParkersPackages****** ***We are a low-cost, secure shipping company that ships packages that weigh up to 50 pounds for up to 3000 miles*** Enter the weight of the package (1.0 - 50.0 pounds): 60.0 Enter the distance to the destination (1 - 3000 miles): 2000 Sorry, you have entered invalid data - program terminated ******Welcome to ParkersPackages****** ***We are a low-cost, secure shipping company that ships packages that weigh up to 50 pounds for up to 3000 miles*** Enter the weight of the package (1.0 - 50.0 pounds): 40.0 Enter the distance to the destination (1 - 3000 miles): 3001 Sorry, you have entered invalid data - program terminated ******Welcome to ParkersPackages****** ***We are a low-cost, secure shipping company that ships packages that weigh up to 50 pounds for up to 3000 miles*** Enter the weight of the package (1.0 - 50.0 pounds): 10.0 Enter the distance to the destination (1 - 3000 miles): 1000 The cost to ship this package is: $100.00 ******Welcome to ParkersPackages****** ***We are a low-cost, secure shipping company that ships packages that weigh up to 50 pounds for up to 3000 miles*** Enter the weight of the package (1.0 - 50.0 pounds): 20.0 Enter the distance to the destination (1 - 3000 miles): 1001 *goes over, so charge for another 200 miles The cost to ship this package is: $240.00
-
-
- Open Eclipse.
- Create a New -> Java project. Name it ParkersPackages and click Finish and OK.
- Next, create a New -> Class. Name it ParkersPackages and be sure to check the first checkbox under "Which method stubs would you like to create?" and click Finish.
- Delete the green comment text in the file "ParkersPackages.java"
- Add a comment at the top // (your name)
- Add another comment at the top // Project 3
- Add code to the file "ParkersPackages.java" to create a
program that will compute how much it will cost to ship a package based on the package weight and number of miles to the destination. The details of the shipping costs are provided in the table below. Your program should ask the user to enter the weight of the package and store it as a double. Next, your program should ask the user to enter the distance to the destination and store it as an integer. - Valid package weights are 1.0 - 50.0 pounds and valid shipping distances are 1 - 3000 miles, so if the weight is not between 1.0 - 50.0 pounds or the distance is not between 1 - 3000 miles, your program should print a message: "Sorry, you have entered invalid data - program terminated", else, your program should determine the costPer200Miles according to the table below. Then, your program should use this value to calculate the cost to ship the package the desired distance.
-
*Requirement 1: Use an if-else statement to check for invalid input and an if-else-if statement to determine the costPer200Miles.
*Requirement 2: If the distance goes over 200 miles (even by 1 mile), the customer is charged for another 200 miles (see sample output below)
*Requirement 3: Use the printf statement to format your monetary values to 2 decimal places. (see Chapter 3 for help as needed)
*Requirement 4: Test your program with both valid and invalid input.
*Hint: Use the division & modulus operators in your calculations to determine how much to charge for shipping.
*Check your code against the checklist before submission
Weight | Cost per 200 miles |
up to 5.0 pounds | $10.00 |
up to 10.0 pounds | $20.00 |
up to 15.0 pounds | $30.00 |
up to 20.0 pounds | $40.00 |
up to 30.0 pounds | $50.00 |
up to 40.0 pounds | $60.00 |
up to 50.0 pounds | $70.00 |
Here are 4 individual sample runs of what your program output should look like:
******Welcome to ParkersPackages******
***We are a low-cost, secure shipping company that ships packages that weigh up to 50 pounds for up to 3000 miles***
Enter the weight of the package (1.0 - 50.0 pounds): 60.0
Enter the distance to the destination (1 - 3000 miles): 2000
Sorry, you have entered invalid data - program terminated
******Welcome to ParkersPackages******
***We are a low-cost, secure shipping company that ships packages that weigh up to 50 pounds for up to 3000 miles***
Enter the weight of the package (1.0 - 50.0 pounds): 40.0
Enter the distance to the destination (1 - 3000 miles): 3001
Sorry, you have entered invalid data - program terminated
******Welcome to ParkersPackages******
***We are a low-cost, secure shipping company that ships packages that weigh up to 50 pounds for up to 3000 miles***
Enter the weight of the package (1.0 - 50.0 pounds): 10.0
Enter the distance to the destination (1 - 3000 miles): 1000
The cost to ship this package is: $100.00
******Welcome to ParkersPackages******
***We are a low-cost, secure shipping company that ships packages that weigh up to 50 pounds for up to 3000 miles***
Enter the weight of the package (1.0 - 50.0 pounds): 20.0
Enter the distance to the destination (1 - 3000 miles): 1001 *goes over, so charge for another 200 miles
The cost to ship this package is: $240.00
- Display a welcome message to the user.
- Prompt the user to enter the weight of the package.
- Validate the weight of the package. If the weight is not between 1.0 and 50.0 pounds, display an error message and terminate the program.
- Prompt the user to enter the distance to the destination.
- Validate the distance. If the distance is not between 1 and 3000 miles, display an error message and terminate the program.
- Determine the cost per 200 miles based on the weight of the package using an if-else-if statement.
- Calculate the cost to ship the package to the desired distance, accounting for additional 200-mile increments.
- Display the total cost to the user, formatted with two decimal places.
- End the program.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images