Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program will not require any IF statements, loops, or custom classes. Instead, it will check inputted data for two kinds of mistakes: Wrong

imageimageimage

This program will not require any IF statements, loops, or custom classes. Instead, it will check inputted data for two kinds of mistakes: Wrong data type (entering text instead of numbers), and math errors (division by zero). The program is intended to be used by an employee to calculate the number of routes a driver will need to follow to deliver all of their packages. Create the following variables for use by the program. Data Entry Requirements: Number of packages (int) Number of destinations (int) Number of routes to be driven (int) Tip: When working with Try/Catch blocks, all variables must be initialized by setting each one equal to zero when it is declared, like this: Normal: int someVariable; Initialized: int someVariable = 0; User prompts, output messages, and error messages: 1. "Please enter the number of packages:" (inputs to the variable containing the number of packages) 2. "Please enter the number of destinations:" (inputs to the variable containing the number of destinations) 3. "Calculating routes..." (displayed after the program receives the second input) 4. "Number of routes:" (final output message) 5. "Error! Please enter only numbers." (error message for both data entry handlers) 6. "Error! Cannot have zero destinations." (error message for route calculation) Note: The specific wording shown above is required by the customer and must be followed precisely, including punctuation. 1. Prompt the user to enter the number of packages. 2. Check to ensure that the user enters a number and not another character. (use Try) 3. Provide an error message in case they entered a character that's not a number. (use Catch with InputMismatchException) 4. Repeat the above steps to have the user enter the number of destinations. 5. Calculate the number of routes by setting the last variable equal to the number of packages divided by the number of destinations. (Try) 6. Provide an error message in case the user entered a zero for the number of destinations, which would cause a divide-by-zero error. (Catch with ArithmeticException) 7. Output the number of routes to the screen. (Will display as zero if an error message is thrown.) Suggested input values for Debug mode (no errors): 6 2 Expected output for above sample: Please enter the number of packages: 6 Please enter the number of destinations: 2 Calculating routes.... Number of routes: 3 Suggested input values for testing error messages: 6 0 Expected output for above sample: Please enter the number of packages: 6 Please enter the number of destinations: 2 Calculating routes... Number of routes: 3 412926.1696728.qx3zqy7 LAB ACTIVITY 10.1.1: Unit 5 Lab Assignment LabProgram.java 1 import java.util.*; 2 3 public class LabProgram { public static void main(String[] args) { /* Type your code below this line. Create additional lines as needed. */ 4 5 6 7 8 } // do not delete this line 9 // do not delete this line 10 0/7 Load default template...

Step by Step Solution

There are 3 Steps involved in it

Step: 1

To write the Java program as described we need to handle user input and exceptions appropriately Below is the Java code for the program based on the g... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practicing Statistics Guided Investigations For The Second Course

Authors: Shonda Kuiper, Jeff Sklar

1st Edition

321586018, 978-0321586018

More Books

Students also viewed these Programming questions

Question

b. What is the fundamental difficulty in the situation?

Answered: 1 week ago

Question

d. What does not occur that could help resolve the problem?

Answered: 1 week ago