Question: Please code using Java NetBeans boolean contains ( int num ) method that Tests whether Scores class contains the number num. Returns true when the
Please code using Java NetBeans
boolean contains int num method that Tests whether Scores class
contains the number num. Returns true when the num is contained in Scores class.
This is an individual assignment.
void add int num method that always adds to the "next available" slot in
the array.
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 LabLastFM
Create a class named Scores that has the following properties:
an instance variable list 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
Provide an overloaded constructor that will take an int value as parameter and
initialize list to a new array of that length.
Implement the following methods:
int size method that returns a count of numbers in Scores class
boolean is Empty method that checks if Scores class is empty, returns true
when empty
void clear method that removes all the numbers from Scores class
This method should add a new number to the end of the list ie the next open
slot in list
If the array list is full when the count equals the length 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 null.
o Add the new number to the end of the list.
void 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 ie 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 ie 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 ie fill in the hole
int get int i method that returns the number at the index position in
the list. This method does not remove the number from the list, it just returns the value
at the position. If the index 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 ie same numbers in the same order
int getFrequencyOf int num method that returns a count the number
of times the number num exists in Scores class
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
