Learning Objectives: Implementation of linked lists and related operations. Additional practice with classes, to include abstract classes. Practice implementation of generic classes. Students will...

1 answer below »

Learning Objectives: Implementation of linked lists and related operations. Additional practice with classes, to include abstract classes. Practice implementation of generic classes.






Students will create a linked list structure that will be used to store information about supplies for a grocery store. You will create an Inventory abstract class with shared attributes and 2 inventory subclasses (i.e. frozen food, produce, deli..).Instead of using ArrayList for storing inventory data, the new program will use a linked list.Note that you willNOTbe using the existing Java class LinkedList, you will be using the provided linked list code and modifying it.Demonstrating your code for two subclasses is required.The program will use the linked list structure to do the following functions;


1) add to the front


2) add to the end


3) remove from end.The program must throw an exception if the program attempts to remove an item from an empty list.


4) remove from the front


5) search for an item by index number (the number of its position in the list) and display the information for that library item.The code must validate that the index number is within bounds and throw an appropriate exception if not.


6) print all items in the library (print out both lists) and the total number of items






You are provided with a generic program called "MyList" which provides some of the required capabilities and prints the list contents (remember that you must override the ToString in each subclass in order for this print method to display the contents as a string).Note that the provided code uses a loop to traverse the list in order to print.A similar traversal loop can be used to search for a specific index. Once a specific index is found it can be used to display the contents of the node.A “size” method is also included as an enabler for your additional methods.






You will add the additional functions to the MyList program.In addition, you will create your own InventoryTest program that creates 2 inventory item lists (one for each subclass) and demonstrates all of the required program functions. Make sure to include all your program files and execution screenshots demonstrating all requirements. To demonstrate the add and remove operations, you should display the list before the operation and just after to show the operation was successfully completed. The display of the list should include the total number of items.To display item 5) "search for an item" you can add a label to the item display, for example, "item at index 1 is “. Don’t forget to include demonstrating the exception and related message for attempting to remove an item from an empty list.






Please make sure to add some single-line comments/explanations of the program.

Answered 1 days AfterNov 01, 2021

Answer To: Learning Objectives: Implementation of linked lists and related operations. Additional practice with...

Kondalarao answered on Nov 03 2021
128 Votes
MyInventoryTest.java
MyInventoryTest.java
public class MyInventoryTest {
    public static void main(String[] args) {
        //creating and printing lists
        Mylist frozenFoods=new Mylist("frozenFoods");
        Mylist deliFoo
ds=new Mylist("deliFoods");

        frozenFoods.insertAtFront(new FrozenFoods("pizza", "kg",50, 10));
        frozenFoods.insertAtBack(new FrozenFoods("waffles", "kg",60, 11));
        frozenFoods.insertAtFront(new FrozenFoods("sausage", "kg",70, 12));

        deliFoods.insertAtFront(new Deli("meat", "kg",80, 15));
        deliFoods.insertAtBack(new Deli("sandwich", "kg",90, 20));
        System.out.println();
        frozenFoods.print();
        deliFoods.print();

        //InsertAtFront
        System.out.println("printing list before insertAtFront operation");
        deliFoods.print();
        deliFoods.insertAtFront(new Deli("bread", "kg",100, 25));
        System.out.println("printing list after insertAtFront operation");
        deliFoods.print();

        //InsertAtEnd 
        System.out.println("printing list before insertAtBack operation");
        deliFoods.print();
        deliFoods.insertAtBack(new Deli("salad", "kg",120, 30));
        System.out.println("printing list after insertAtBack operation");
        deliFoods.print();

      //RemoveAtFront
        System.out.println("printing list before removeAtFront operation");
        deliFoods.print();
        deliFoods.removeAtFront();
        System.out.println("printing list after removeAtFront operation");
        deliFoods.print();

        //RemoveAtEnd
        System.out.println("printing list before removeAtend operation");
        deliFoods.print();
        deliFoods.removeAtend();
        System.out.println("printing list after removeAtend operation");
        deliFoods.print();

        //SearchItemByIndex
        System.out.println("printing list before searchItemByIndex operation");
        deliFoods.print();
        System.out.println("Searching item at index 1");
        deliFoods.searchItemByIndex(1);

        //Exceptions Demonstration
        //searching element at index -1
        /*
         * System.out.println("\nprinting list before searchItemByIndex operation");
         * deliFoods.print(); System.out.println("Searching item at index -1");
         * deliFoods.searchItemByIndex(-1);
         */

        //removing item on empty list
         System.out.println("\nperforming remove operation on emptyList");
         Mylist foods=new Mylist("empt...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here