Question: Add three Java classes to the project: Applications (contains the main method),Rectangle and ArrayPractice. 1. (1pt)The ArrayPractice class has three private data fields, all arrays
Add three Java classes to the project: Applications (contains the main method),Rectangle and ArrayPractice.
1. (1pt)The ArrayPractice class has three private data fields, all arrays are arrays, and an additional constant field baseLength assigned 10. Declare the array fields as -- an array to store integer numbers of type int named numbers -- an array to store Rectangle references (type is Rectangle) named boxes -- an array to store names (type String) , the id is listOfNames Do not instantiate the fields at the declaration!
2. (2pts)Define a constructor for this class such that it takes no parameters, and the constructor instantiates all array fields to length baseLength.
3. (3pts)Add another constructor to this class such that is takes three parameters, an int for the length of the numbers array, another int for the length of the boxes array, and a String type array to initialize the listOfNames array. The constructor instantiates numbers and boxes to the given parameters as lengths, and assigns the third parameter to the String array. Choose your own IDs for the parameters. The constructor calls the loadNumbers() and loadBoxes( ) methods (see below).
4. (3pts)Define the loadNumbers( ) method. The task of this method is to populate the numbers array with randomly selected integer numbers from the range -100 to 100. Decide about the return type and parameters as you see it best. The method must run a for loop to the length of the array and assign a andom number one-by-one to the array entries.
5. (3pts)Define the loadBoxes( ) method. The task of this method is to populate the boxes array with Rectangles. Decide about the return type and parameters as you see it best. The method must run a for loop to the length of the array. For every index k a Rectangle object is instantiated with randomly selected length and width value between 0 and 1. Use the initializer constructor from the Rectangle class and assign the instantiated rectangle to boxes[k].
6. (3pts)Define three more methods displayNumbers, displayBoxes, displayList. The task of each method is to print the corresponding array entries to the console, each array entry in a new line. A rectangle is supposed to be printed as the toString method was defined in the Recrangle class.
7. (5pts)The Application class contains the main method. In the main
Declare and instantiate an ArrayPractice object with the no-arg constructor. Call the display methods one after each other. Comment on the output you see on the console.
Using the initializer list instantiate a String array named list containing names of your choice. The array must contain at least 5 names and it is recommendable not having more than 10 names. Declare and instantiate and ArrayPractice object with the parametrized constructor. For numbers length the parameter is 50, for boxes length the parameter is 6, for the listOfNames pass the list array you defined above.
Call again the display methods one after each other. Comment on the output you see on the console.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
