Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please create a unique and unused resolution. Also take into the account the restrictions and follow all prompts. Thank you. Also the code prompted for

Please create a unique and unused resolution. Also take into the account the restrictions and follow all prompts. Thank you. Also the code prompted for 3.14 & 3.15 are below ( Beginning of task 1): image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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. - You cannot use the SinglyLinkedList class defined by Java nor can you use any other collection class from the Java library. 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, the String class, Scanner class and the print methods. Task 0: Create a NetBeans project for the Lab103 assignment. Use the naming convention Lab103-LastFM Task 1: Duplicate the SinglyLinkedList class from the textbook (code fragments 3.14&3.15). Do not add any additional methods to this class. Do not modify any methods in this class. Add a comment header to this class (example shown in Task 7) that: - briefly describes what the class does - gives credit the textbook authors and lists the Code Fragments used - includes your name as the transcribing author Task 2: Create a generic version of a Bag interface. This Bag interface will be a Generic interface with a Generic TYpe Placeholder. Include the following methods in this Bag interface: - int size( ) - returns a count of items in the bag - boolean isEmpty( ) - checks if the bag is empty, returns true when empty - void clear( )-removes all the items from the bag - int getFrequencyof (E e) - returns a count the number of times an item, e, exists in the bag - boolean contains (E e) - Tests whether the bag contains the item e. Returns true when the e is contained in the bag. - void add (E e)-adds item, e, to the "next available" position in the bag. - E remove (E e) - removes the first occurrence of the item e in the bag. Returns null if e is not in the bag or if called on a empty bag. - E remove ( ) method that removes a random entry from the bag. Returns the removed entry. Returns null if bag is empty. - Eget(int i) that returns the element at the ith position in the bag. Throws an index out of bounds entry if passed an invalid index. - string tostring ( ) - returns a String of the contents of the bag. - boolean equals(Object o) - returns a true if the parameter o exactly matches the contents of the bag (i.e. same elements in the same order) Note that the above methods are similar to the methods that you implemented in the Lab102 assignment. Task 3 (very similar to Lab102 but generic): - Copy the Scores class from your Lab102 assignment into your Lab103 assignment. - Rename this copy of the Scores class to ArrayBag - Modify the ArrayBag class so that it: - implements the Bag interface created in Task 2 - is a generic class. - Make appropriate adjustments to the methods so that they match the interface. Import Note: - You cannot directly create an array of a generic type. - To crate an array of a generic type you must - Create an array of Object type - Cast the Object array to the generic type, e.g. E[ list = (E[]) new Object[ capacity ]; Task 4: Design a new Generic class called LinkedBag that implements the Generic Bag Interface created earlier. This class will include a generic type Parameter as part of class declaration. When a client class uses the IinkedBag the client will specify the actual type. - For the instance variable Iist use the SinglyLinkedList of Generic type from Task 1. This structure will hold the items placed in the bag. - You should not declare an instance variable for size in this L inkedBag class. - When you need to know how many items are in the list you can call the size () method from the SinglyLinkedList class. - Let the SinglyLinkedList class keep track of the number of items in the LinkedBag, i.e. let the data structure do the work. - Adding a separate size variable to the LinkedBag class will require you to do unnecessary work to maintain the value of the size variable, and if you incorrectly maintain a size variable in the LinkedBag class you may run into the situation where the two sizes variables are not equal. - Provide a default constructor that will initialize the list instance variable with an empty Singly Linked list. - Provide and overload constructor that allows the client to specify the initial capacity of the bag. - This constructor can ignore the parameter and just call the default constructor. - This constructor allows the LinkedBag to provide the Client with the same functionality as the ArrayBag. - Your Client should not care if it uses an ArrayBag or a LinkedBag, they should work exactly the same from the Client's perspective. - Implement the methods specified in the interface. - The method that removes a specific item which is passed as a parameter should use the object's 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 the first occurrence of that item from the bag and returns a reference to the object removed. It returns a null of there is no item with equal contents. - The method that removes a random item should return a reference to the object being removed. If the list is empty it should return null. TASK 5: 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. TASK 6: Create a client class named Client with the main method. Inside the main method do the following: - Create an instance of ArrayBag called mensTeam to store players' information of NDSU's Men's football team using the overload constructor to make the initial length of the list array equal to 2 . - Add eight players to mensTeam by hardcoding eight calls to the add method (one for each player). - Display the contents of mensTeam. - Remove a random player from mensTeam. - Display the contents of mensTeam. - Get but do not remove a reference to the 5th item in the bag. - Display the contents of the reference you "got" it step 5. - Add another Player with another hardcoded add method call. - Display the contents of mensTeam. - Remove the Player that you "got" in step 5 using a call to the remove (E e) method. - Display the contents of mensTeam. - To demonstrate that your generic class can support objects of different types: - Create an instance of an ArrayBag called courses to store the course ids of the courses that you are taking this semester (CSci 161,..)as Strings. - Populate courses with each of your courses. - Display the contents of courses. - Remove a random course id from courses. - Display the contents of courses. - Create an instance of LinkedBag called womensTeam to store the players' information of NDSU's Women's basketball team. - Repeat steps 1 through 9 above for the womensTeam that uses an instance of the LinkedBag class. TASK 7: Make sure that each of your classes is correctly documented. - The interface should have a Javadocs header - Each class should have a Javadocs header - Each method should have a Javadocs header - For the SinglyLinkedList class - the documentation (headers and inline comments) should match what is in the textbook. - You may add additional documentation for your own benefit if you wish. - You must add a Javadocs header to the class that gives credit to the authors of the code. - See example on next page. / * SinglyLinkedList Class * Code Fragments 3.14, 3.15 * from * Data Structures \& Algorithms, 6th edition * by Michael T. Goodrich, Roberto Tamassia \& Michael H. Goldwasser * Wiley 2014 * Transcribed by *@author joseph.latimer

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

What are some of the possible scenes from our future?

Answered: 1 week ago