Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please do this in Java Due Date: Tuesday, 01/31@11:59pm Points: 100 This is an individual assignment. Restrictions: Unless directed otherwise, you cannot use any Java
Please do this in Java
Due Date: Tuesday, 01/31@11:59pm Points: 100 This is an individual assignment. Restrictions: Unless directed otherwise, you cannot use any Java class libraries in this assignment. In particular, you cannot use the ArrayList class nor can you use any methods from the Arrays class. If needed: - you may create and use one or more instances of an array and access the length instance variable for each array. - you may NOT access any other methods from the Arrays class. - you MAY use the Java Random class. - you may NOT use the Math.Random class - Of course, you may use the System.print, println, and printf methods. In this project you will be doing the following: Create a NetBeans project using the naming convention Lab102-LastFM Create a class named Scores that has the following properties: - an instance variable 7ist - an array of int type: This structure will hold the numbers. - an instance variable count of int type: This will provide the count of numbers currently stored in Scores class. This count will increment when a new number is added to the list and decrement when a number is removed from the list - Provide a default constructor that will initialize the instance variable list to a new array of length 2. - Provide an overloaded constructor that will take an int value as parameter and initialize list to a new array of that length. plement the following methods: - int size() method that returns a count of numbers in Scores class - boolean isEmpty ( ) method that checks if Scores class is empty, returns true when empty - Void clear() method that removes all the numbers from Scores class - int getrrequencyof (int num) method that returns a count the number of times the number num exists in Scores class - boolean contains (int num) method that Tests whether Scores class contains the number num. Returns true when the num is contained in Scores class. - Void add (int num) method that always adds to the "next available" slot in the array. - This method should add a new number to the end of the list (i.e. the next open slot in list). - If the array list is full (when the count equals the 7 ength of the array) then, create a new bigger array - temp that is double the length of list array. - Copy the contents from list to temp so the contents are in the same order. - Assign the reference of temp to list and then set temp to nul1. - Add the new number to the end of the list. - int remove (int num) method that removes the first occurrence of the number num from list. - If the number num does not exist then the method does not do anything. - If remove is successful and the number removed is not the last entry in list, then shift the elements that are in the slots to the right of the number being removed by one place to the left in the list (i.e. fill in the hole). In this structure, we never want any gaps in list. - int remove( ) method that removes a random number from the list array, - If Scores class is empty, the method should throw an IllegalStateException with the message: "The remove( ) method cannot be called on an empty list". - Use the Random class from java.util package to generate pseudorandom index. This index should be based on the number of items in list, not the length of the list array (i.e. we don't want to try and remove from an empty cell). - After the number is removed shift the elements by one place to the left in the list (i.e. fill in the hole). - int get (int i ) method that returns the number at the ith index position in the list. This method does not remove the number from the list, it just returns the value at the ith position. If the index i is outside the bounds of the array, it generates (throws) an ArrayIndexOutofBoundsException. Note in this case we are considering the logical bounds of the array that are determined by the number of items currently in the array and not by the length of the array. - String tostring( ) method that returns a String of the contents of Scores class - boolean equals (Object o) method that returns a true if the parameter o exactly matches the contents of Scores class (i.e. same numbers in the same order) More on next page. Finally design a java class Client with the main() method that does the following: - Create an Object of Type Scores using the overloaded constructor and pass the value 16. - Use a for loop to populate the list in Scores object with 32 random numbers between 10 and +10 inclusive. (Use the Random class from java . util package to generate pseudorandom numbers). - Call toString() to print the contents of the Scores object. - Call the add( ) method to add the number 6 to Scores object. - Print the current size of the list in the Scores object. - Call the remove( ) method to randomly remove a number from Scores class - Get the number at the 20th index position - Print the frequency of the number returned by the previous step occurs in Scores class - Call the appropriate overloaded remove method to remove the first occurrence of number at the 20th index position from Scores class - Print the frequency that this number now occurs in Scores class - Call tostring() to print the contents of the Scores object an ensure that the correct number was removed. - Check whether the array in Scores object contains the number 7 Use JavaDoc commenting styles in the Scores class and the Client (Review Section 1.9.4 in the textbook). Make sure to provide a block comment at the top that provides description of each class and a JavaDoc comment for each method. Use in line commenting as neededStep 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