Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a Part 1 subpackage p1 under the ca6 package. In the p1 subpackage, create a public class Division. In the class, write a public
Create a Part 1 subpackage p1 under the ca6 package. In the p1 subpackage, create a public class Division. In the class, write a public static method public static int divide (int dividend, int divisor) that returns the (integer part of the) quotient dividend/divisor if divisor =0, and throws an ArithmeticException with the error message "The divisor cannot be zero". In the Division class, write a main method that 1. Attempts to read integers x and y from the console using a Scanner object, invoke the divide method to divide x by y, and print the result to the console. 2. If the divide method throws an ArithmeticException, the main method should print the error message from the exception thrown by the divide method. 3. If the nextInt method of the Scanner object throws an InputMismatchException, (i.e., if at least one of the inputs is not an integer), the main method should print the error message "Inputs must be integers". 4. Whenever either of the above two exceptions occurs, the main method should prompt the user to enter x and y again, read the inputs, and repeat Step 1 until both inputs are valid and Step 1 is successful. Part 2 Create a Part 2 subpackage 2 under the ca6 package and copy here the Shape and Circle classes from Class Assignment 5. In the p2 subpackage, in the constructor of the Circle class, before setting the radius, check whether the radius is negative and if so, throw an IllegalArgumentException with the error message "Invalid input __: the radius of a circle cannot be negative" where should be replaced with the actual radius in the argument. 1 In the p2 subpackage, create a new class named CircleTest. In the main method of the CircleTest class: - Create an Array List of integers named radii. - Create an Array List of Circle objects named circles. - Create a Random object named rand using 2150 as the seed. - Use rand to generate 20 random integers from 10 to 9 (including 10 and 9 ) and add them to the radii list. Print the radii list. Your code should print [7,9,6,5,8,1,4,8,3,2] - Attempt to create a Circle object for each radius in the radii list, using any color of your choice, and add the resulting Circle object to the circles list. Print the error message whenever the constructor of the Circle class throws an IllegalArgumentException. You should see four such exceptions thrown, one for each of the four negative elements of the radii list. - Print the circles list. The list should consist of six Circle objects, one for each of the six nonnegative elements of the radii list
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