Question: Develop Java program for each of the following problems. Please name the programs as indicated and add proper program headers and output labels as shown

Develop Java program for each of the following problems. Please name the programs as indicated and add proper program headers and output labels as shown below.

Use only concepts and programming constructs/syntax we discussed in class.

Write your Java Class named LinkedListYourName as follows.

Choose one of the given files (LinkedListGGGG.java or LinkedListOOOO.java)

  • LinkedListGGGG.java is a LinkedList Class with Generic
  • LinkedListOOOO.java is a LinkedList Class with Object element type

Change the filename and Class name with yours LinkedListYourName

Implement all class methods.

  • add, addFirst, addLast, getFirst, getLast, remove, removeFirst, removeLast

You cannot change the name of methods, parameter type, return type.

Remove all written comments from the code, then write your comments.

Using code from outside sources receives NO credit. You must write and document your own code to meet the assignment requirements. Some methods are not in the slides.

Second, you must create your own test program named ListTestYourName

Your test program will runs with sentinal loop with user input.

-------Linked List Test Program------

0 Exit Program

1 Add First Node

2 Add Last Node

3 Add at Index

4 Remove First Node

5 Remove Last Node

6 Remove at Index

7 Print List Size

Select Option: user input here

The main menu will be similar as follows.

Test each method at least one execution for each, then show the status before & after execution with proper label.

Except for options 0 and 7 above, when calling a method on the list make sure the method prints the list content before and after executing the called method, For example, the output of testing method removeLast() would be displayed like this

(assuming the list has 10, 20, 30, 40, 50):

Testing method removeLastNode()

List content before removing last node is: 10 20 30 40 50

List content after removing last node is: 10 20 30 40

List is Empty now.

User choose remove option but there is no element in the List, you need to show the message like this

Again, you cannot change method names, return type and parameter types.

PLEASE SEE CODE BELOW:

public class LinkedListOOOO{ private Node head = null; private Node tail = null;

public class Node { Object data; Node next; //Node constructor public Node(Object element) { data = element; next = null; } //Node toString method to print Node element public String toString() { return String.valueOf(this.data); } }

public void add(int index, Object element) { /////////////////////////// // Write your code here! // /////////////////////////// // add an element(as a node) at given index } public void addFirst(Object element) { /////////////////////////// // Write your code here! // /////////////////////////// // add an element(as a node) at the first of the list } public void addLast(Object element) { /////////////////////////// // Write your code here! // /////////////////////////// // add an element(as a node) at the last of current list } public Object getFirst() { /////////////////////////// // Write your code here! // /////////////////////////// // Return the element value of first node } public Object getLast() { /////////////////////////// // Write your code here! // /////////////////////////// // Return the element value of first node } public void remove(int index) { /////////////////////////// // Write your code here! // /////////////////////////// // Remove an element(a node) at given index }

public Object removeFirst() { /////////////////////////// // Write your code here! // /////////////////////////// // Return the element value of first node // Remove an element(a node) at given index } public Object removeLast() { /////////////////////////// // Write your code here! // /////////////////////////// // Return the element value of first node // Remove an element(a node) at given index } public int size() { /////////////////////////// // Write your code here! // /////////////////////////// // Return how many elements in current list // Don't keep the size value, when size() method called, // retrieve whole list and count the number of element and return it } public String toString() { Node temp = head; String str = "["; while(temp.next != null) { str = str + temp.data + ", "; temp = temp.next; } str = str + temp.data; return str + "]"; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!