Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

you are going to be implementing a linked list, while setting up a team roster. Most of the linked list has already been implemented, inlcluding

you are going to be implementing a linked list, while setting up a team roster. Most of the linked list has already been implemented, inlcluding a constructor and append method. You will have to implement a contains method.

image text in transcribed

image text in transcribed

import java.util.Scanner;

public class PoD {

public static void main( String [] args ) {

Scanner in = new Scanner( System.in );

LinkedList listOfPlayers = new LinkedList();

final int LIST_SIZE = Integer.valueOf(in.nextLine());

for (int i=0; i

listOfPlayers.append(newPlayer); }

String checkPlayerStatus = in.nextLine();

if (listOfPlayers.contains(checkPlayerStatus)) { System.out.println(checkPlayerStatus + " is on the team."); } else { System.out.println(checkPlayerStatus + " did not make the team."); }

in.close(); System.out.print("END OF OUTPUT"); }

}

---------------------------------------------------------------------------------------------------

import java.util.NoSuchElementException;

/**

* A listnked list is a sequence of nodes with efficient element

* insertion and removal. This class contains a subset of the methods

* of the standard java.util.LinkedList class.

*

* You will finish off the contains method.

*/

public class LinkedList

{

//attributes

private Node head;

private Node tail;

//Node

class Node

{

public Object data;

public Node previous;

public Node next;

}

/**

* Constructs an empty linked list/

*/

public LinkedList()

{

head = null;

tail = null;

}

/**

* Appends a new node to the end of the linked list.

*/

public void append(Object element)

{

if (head == null) //Empty linked list

{

Node firstNode = new Node();

firstNode.data = element;

firstNode.previous = null;

firstNode.next = null;

head = firstNode;

tail = firstNode;

}

else //At least one node already exists.

{

Node newNode = new Node();

newNode.data = element;

newNode.previous = tail;

newNode.next = null;

tail.next = newNode;

tail = newNode;

}

}

//PLEASE START WORK HERE

//===============================================

/**

* Check to see if element is contained

* anywhere in the linked list.

* @returns boolean: true if contained

*/

//===============================================

//PLEASE END WORK HERE

}

Input Input is taken care of for you (in PoD java). It reads in the number of team members, followed by each of the team members' names. Finally, it reads in one more name to check and see if that person has made the team. Processing Complete the co are provided in the Java file at left. ntains method in the LinkedList class. Details of this Output Output is taken care of for you (in PoD java). If the person whose name is being checked against the team roster is on the list (i.e contained in the linked list), PoD java outputs NAME is on the team. otherwise it outputs NAME did not make the tean

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

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions