Question: HELP!!!! Restrictions: Unless directed otherwise, you cannot use any Java class libraries in this assignment. In particular, you cannot use the ArrayList class nor can
HELP!!!! 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. This means it is necessary for you to write your own code to copy or otherwise process any arrays that you use. 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 use the Java Random class. In this project you will be doing the following: Develop a java interface named Bag that can store a certain number of whole numbers in it. A bag in java is a kind of collection that does not do much more than contain its items. It does not order the items in any particular order and nor does it prevent duplicates. Provide the following methods in the interface: ? public int getCurrentSize( ) - returns a count as of numbers in the bag ? public boolean isEmpty( ) - checks if the bag is empty, returns true when empty ? public void add (int num) - adds a new number num to the bag ? public void remove (int num) - removes the first occurrence of the number num from the bag ? public void remove( ) - removes a randomly selected entry from the bag ? public void clear( ) - removes all the numbers from the bag ? public int getFrequencyOf(int num) - returns a count the number of times the number num exists in the bag ? public boolean contains(int num) - returns whether the bag contains the number num Design a java class called Scores that implements the Bag interface and provides implementation for all the methods inherited from the Bag interface. Do the following in the Scores class: 1) Declare an instance variable list an array of int type: This structure will hold the numbers in the bag. 2) Declare another instance variable count of int type: This will provide the count of numbers currently stored in the bag. This count will increment when a new number is added to the list and decrement when a number is removed from the list 3) Provide a default constructor that will initialize the instance variable list to a new array of length 50. 4) Provide an overloaded constructor that will take an int value as parameter and initialize list to a new array of that length. 5) Implement the getCurrentSize( ), isEmpty( ) and Clear( ) methods using the descriptions provided in the Bag interface 6) Implement the add (int num) method using the specification provided in the Bag interface. This method should be able to add a new number to the end of the list ONLY IF the array is not full. o If the array list is full (when the count equals the length of the array) then, create a new bigger array - temp with double the length of list array. o Copy the contents from list to temp array in the same order. o Assign the reference of temp to list and set temp to null. o Add the new number to the end of the list. 7) Implement getFrequencyOf(int num) and contains(int num) methods using the descriptions from the Bag interface 8) Implement remove(int num) method that removes the first occurrence of the number num in the list array. If the number num does not exist then the method does not do anything. o If removal is successful and the number removed is not the last number in the list, then shift the elements by one place to the left in the list (i.e. fill in the hole). 9) Implement remove ( ) method that removes a random number from the list array, o Use the Random class from java.util package to generate pseudorandom index. o After the number is removed shift the elements by one place to the left in the list (i.e. fill in the hole). 10) Implement a new method called, get(int i) 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 is outside the bounds of the array, it generates (throws) an ArrayIndexOutOfBoundsException. Note in this case that the bounds of the array are determined by the number of items currently in the array and not by the length of the array. 11) Override the toString and equals methods for the Scores class. Two Score objects are consider equal if they have the same values in the same order. Finally design a java class called Client with the main method that does the following: 1) Create an Object of Type Scores using the overloaded constructor and pass the value 100. 2) Use a for loop to populate the list in Scores object with 100 random numbers between -100 and +100 inclusive. 3) Call toString( ) to print the contents of the Scores object. 4) Call the add( ) method to add the number 86 to the Bag 5) Print the current size of the list in the Scores object. 6) Call the remove( ) method to randomly remove a number from the Bag 7) Get the number at the 75th index position 8) Print the frequency that the number returned by the previous step occurs in the Bag 9) Call the appropriate overloaded remove method to remove the first occurrence of number at the 75th index position from the Bag 10) Print the frequency that this number now occurs in the Bag 11) Print the frequency of the number 86 12) Check whether the array in Scores object contains the number 86. Use JavaDoc commenting styles in Bag interface and Scores class. Make sure to provide a block comment at the top that provides description of each interface or class and a JavaDoc comment for each method.Use single line commenting style as needed. Next you will be creating a generic version of the Bag interface called GenericBag. You should include the following methods in the interface: ? public int getCurrentSize( ) - returns a count as of numbers in the bag ? public boolean isEmpty( ) - checks if the bag is empty, returns true when empty ? public void add (T value) - adds a new item value to the bag ? public void remove (T value) - removes the first occurrence of the value value from the bag ? public void remove( ) - removes a randomly selected entry from the bag ? public void clear( ) - removes all the entries from the bag ? public int getFrequencyOf(T value) - returns a count the number of times the entry value exists in the bag ? public boolean contains(T value) - returns whether the bag contains the entry value Design a Generic class called ArrayBag that implements the Generic Bag Interface created earlier. This class will include a Type Parameter as part of class declaration. A client class using ArrayBag will specify the actual type. 1) Declare an instance variable list an array of Generic type: This structure will hold the items in the bag. o Note: Internally list will need to be type Object[] due to limitations of Javas abilities to create generic arrays: T[] list = (T[]) new Object[50]; 2) Declare another instance variable count: This will provide the count of items currently stored in the bag. This count will increment as a new item is added to the bag and decrement as an item is removed from the bag. 3) Provide a default constructor that will initialize the instance variable bag to a new array of length 50. 4) Provide an overloaded constructor that allows the client to specify the initial capacity of the bag. 5) Implement the methods received from the interface. 6) The method that adds an item to the bag should check if the bag is full. When the bag is full it should automatically double the capacity of the bag and adds the item. 7) The method that removes a specific item which is passed as a parameter should use the objects equals( )method to compare the contents of object in the bag with the contents of the parameter. If there is an object in the bag with the same contents then, it removes that item from the bag and returns true, and returns false if there is no item with the same contents. The methods that remove items (randomly or specified item) should automatically shift the remaining items left to fill in the hole left by the removed item. Create a user-defined class called Player. Each Player object will have the following attributes (instance variables): name, position played, and jersey number. Use appropriate data types to define these instance variables and use recommended naming conventions for the variable names. Provide a constructor, implement the accessor and mutator methods for each of the instance variables, and include the toString( ) and equals( ) methods. Finally, create a Client Program NDSU-BasketBall with the main( ) method. Inside the main method do the following: Create an object of ArrayBag called team to store all players information of NDSU Men/Women Basket Ball team. Run a for loop to prompt the user for each Players information, create the Player object and finally add the player to the team. Remove a random player from the team. Add a new Player with some made up information. Display the current count of players in the team. Remove the Player that you just added earlier with made up information from the team using appropriate method. Display the current count of players in the team. To demonstrate that your generic class can support objects of different types: o Create an object of ArrayBag called courses to store the course ids of the courses that you are taking next semester as Strings. o Populate the bag with the course ids. o Remove a random course id from the Bag. o Use a for loop to print the course ids from the bag. Comment your Bag interface, ArrayBag and Player classes with Java Doc commenting style. Use single line or block style comments for the client program.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
