Question: 1.Write method that calculates and returns area of rectangle. Call method using user input to pass as arguments. -Method heading: double area (double length, double

1.Write method that calculates and returns area of rectangle. Call method using user input to pass as arguments.

-Method heading: double area (double length, double width)

-Add code that checks for length and width to be positive numbers. Throw IllegalArgumentException if length or width are negative. Add code to the method header thatannounces that the method can throw exceptions in the code.

2. Assume you have a method described in problem 1. Generate 50 pairs of random integers in the range [1, 100], and calculate 50 areas of rectangle, passing a pair ofrandom numbers into the method as arguments on each iteration of the loop. Use Java formatting to output randomly generated length, width, and calculated area incolumns, to create table-like look on the screen. There is no need to catch IllegalArgumentException.

3.Write class Box that represents a 3Dbox.

- The class must have 3 fields that represent dimensions: length, width, height -all of type double

- The class must have two constructors: non-argument constructor and constructor that takes all dimensions as parameters andsets the fields. When setting thedimensionscheck for values to be positive. Throw IllegalArgumentException if they arenegative or 0.

- Accessor and mutator methods for all fields (total of 6). Use exceptions to prevent negative values to be used when setting dimensions.

- getVolume() method that calculates and returns volume of the box.

- getPerimeter() method that returns the sum of all edges of the box.

4.Assume you have Box class described above. Declare an array of 100 boxes and an ArrayList for 5 elements of type Box.

5.Assume you have an array of 100 objects of type Box. Use linear search algorithm to find a box with volume 100.

6.Assume you have an array of 100 objects of type Box. Search the given array for all boxes that have a perimeter of 10. Storeall of those objects in ArrayListnamed"boxes10".

5.Implement the following array algorithms as methods:

-Finding minimum element

-Finding maximum element

-Finding sum of all elements.

-Finding an average of all elements

-Linear search: find given element in array.

-Count occurrences of a number in array.

-Count occurrences of a string in array of strings.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!