Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lab 4 - Advanced Java Programming: Exceptions Be able to: 1. Write try, catch blocks in Java. 2. Handle common types of exceptions which may
Lab 4 - Advanced Java Programming: Exceptions Be able to: 1. Write try, catch blocks in Java. 2. Handle common types of exceptions which may occur when inputting values. 3. Prevent software from blowing up by providing user-friendly" responses to input values 4. Define and use exceptions to solve specific program needs 5. Insure that all needed inputs have appropriate values at the close of the program 6. Use input values for arithmetic calculations. Setup: You work for a company that builds cylinders and ships them in boxes. It is your job to write software that creates a cylinder, allows for input of box data, compares the input to given cylinder data, and determines whether the box is acceptable to ship the given cylinder. Make sure that you are familiar with the example programs. You will find it helpful to enter, compile, and run the example classes for a more complete understanding of the data flow. To accomplish this task you will need to: 1. Create 2 exception classes that will throw errors (see the lecture notes class Integer NotGreaterThan 10Exception) a. VolumeException b. DimensionException 2. Write an executable class called CylinderBoxClient (This is the tester program.) a. Using the Random class generate a random radius between 1 and 24 inclusive. (Note: this is the radius ...the width will be twice the radius.) b. Using the Random class generate a random length between 3 and 38 inclusive. c. Instantiate a cylinder object using the radius and length... give it the color of your choice. d. INPUT i. You will need to create at least one public static void method in the tester class that will test the data and throw the correct exception. (You may use other methods as well.) 1. Public static void checkForDimensionException(String myField, int box Value, int cylinderValue) throws DimensionException a. myField is the current field that is attempting to be input, POST IN THE PROGRAMMING FORUM... ISSUEE.QUERITOs:lengthOST!! b. box Value is the width or length of the box c. cylinder Value is the width or length of the cylinder Lab 4 - Advanced Java Programming: Exceptions d. will throw a Dimension exception if the boxValue is not greater than the cylinder cylinder Value ii. Prompt the user to enter a width that is greater than the cylinder width. iii. Invoke checkForDimensionException iv. If the user's data causes an exception your program should respond by explaining the error and asking the user to reenter the inappropriate value. v. Handle any exceptions which might occur. Your program should not blow up" or crash but continue to run until both width and length have acceptable values. vi. Do not use generic exception handling. Set up a catch block for each specific exception you encounter a. DimensionException: thrown if box value is not greater than the corresponding cylinder value b. InputMismatchException: thrown if not integer data is entered vii. Once valid data is entered for the width then repeat the above steps for the length variable viii. Width should not need to be reentered if length throws an exception. e. Once both values are entered a. Create a box object using the data entered... the color is your choice but must be different than cylinder b. Print the data from the cylinder toString and the box toString...make sure it is readable. See samples. c. Check the box volume against the cylinder volume i. If the box / volume ratio is greater than 2.345 1. throw a Volume Exception 2. Print a message that says the box might be too large...that the data will need to be reviewed... print the box and cylinder volume with labels...print the ratio to 3 decimals ... print that the product SHOULD NOT SHIP ii. If the ratio is less than or equal to 2.345 then 1. State that the container calculations are complete...print the Box / Cylinder ratio...print that the product may PROCEED TO SHIPPING POST IN THE PROGRAMMING FORUM... ISSUES...QUESTION...JUST LOST!! Lab 4 - Advanced Java Programming: Exceptions Be able to: 1. Write try, catch blocks in Java. 2. Handle common types of exceptions which may occur when inputting values. 3. Prevent software from blowing up by providing user-friendly" responses to input values 4. Define and use exceptions to solve specific program needs 5. Insure that all needed inputs have appropriate values at the close of the program 6. Use input values for arithmetic calculations. Setup: You work for a company that builds cylinders and ships them in boxes. It is your job to write software that creates a cylinder, allows for input of box data, compares the input to given cylinder data, and determines whether the box is acceptable to ship the given cylinder. Make sure that you are familiar with the example programs. You will find it helpful to enter, compile, and run the example classes for a more complete understanding of the data flow. To accomplish this task you will need to: 1. Create 2 exception classes that will throw errors (see the lecture notes class Integer NotGreaterThan 10Exception) a. VolumeException b. DimensionException 2. Write an executable class called CylinderBoxClient (This is the tester program.) a. Using the Random class generate a random radius between 1 and 24 inclusive. (Note: this is the radius ...the width will be twice the radius.) b. Using the Random class generate a random length between 3 and 38 inclusive. c. Instantiate a cylinder object using the radius and length... give it the color of your choice. d. INPUT i. You will need to create at least one public static void method in the tester class that will test the data and throw the correct exception. (You may use other methods as well.) 1. Public static void checkForDimensionException(String myField, int box Value, int cylinderValue) throws DimensionException a. myField is the current field that is attempting to be input, POST IN THE PROGRAMMING FORUM... ISSUEE.QUERITOs:lengthOST!! b. box Value is the width or length of the box c. cylinder Value is the width or length of the cylinder Lab 4 - Advanced Java Programming: Exceptions d. will throw a Dimension exception if the boxValue is not greater than the cylinder cylinder Value ii. Prompt the user to enter a width that is greater than the cylinder width. iii. Invoke checkForDimensionException iv. If the user's data causes an exception your program should respond by explaining the error and asking the user to reenter the inappropriate value. v. Handle any exceptions which might occur. Your program should not blow up" or crash but continue to run until both width and length have acceptable values. vi. Do not use generic exception handling. Set up a catch block for each specific exception you encounter a. DimensionException: thrown if box value is not greater than the corresponding cylinder value b. InputMismatchException: thrown if not integer data is entered vii. Once valid data is entered for the width then repeat the above steps for the length variable viii. Width should not need to be reentered if length throws an exception. e. Once both values are entered a. Create a box object using the data entered... the color is your choice but must be different than cylinder b. Print the data from the cylinder toString and the box toString...make sure it is readable. See samples. c. Check the box volume against the cylinder volume i. If the box / volume ratio is greater than 2.345 1. throw a Volume Exception 2. Print a message that says the box might be too large...that the data will need to be reviewed... print the box and cylinder volume with labels...print the ratio to 3 decimals ... print that the product SHOULD NOT SHIP ii. If the ratio is less than or equal to 2.345 then 1. State that the container calculations are complete...print the Box / Cylinder ratio...print that the product may PROCEED TO SHIPPING POST IN THE PROGRAMMING FORUM... ISSUES...QUESTION...JUST LOST
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started