Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a java program within eclipse. I have provided all the java classes listed below needed to do the problem. They are all below

This is a java program within eclipse. I have provided all the java classes listed below needed to do the problem. They are all below the instructions labeled in bold and also have the .txt files below the .java classes

image text in transcribed

IndexedListLinkedList.Java:

public class IndexedListLinkedList implements IndexedList { private LinearNode  head; // reference to first node private LinearNode  tail; // reference to last node private int count; // number of nodes in the list public IndexedListLinkedList ( ) // POST: empty list { head = tail = null; count = 0; } public void addFirst (T element) // POST: element added to front of list { LinearNode newNode = new LinearNode(element); if (isEmpty()) head = tail = newNode; else { newNode.setNext(head); head = newNode; } count++; } public void addLast (T element) // POST: element added to rear of list { LinearNode newNode = new LinearNode(element); if (isEmpty()) head = tail = newNode; else { tail.setNext(newNode); tail = newNode; } count++; } public void add (T element, int position) throws InvalidPositionException { // PRE: 0 = count) // POST: element added at position throw new InvalidPositionException (); if (position == 0) addFirst(element); else if (position == count) addLast(element); else { LinearNode current = head; for (int i = 1; i  newNode = new LinearNode (element); newNode.setNext(current.getNext()); current.setNext(newNode); count++; } } public T removeFirst( ) throws EmptyCollectionException // PRE: list is not empty { // POST: remove and return first element if (isEmpty()) throw new EmptyCollectionException(); LinearNode temp = head; head = head.getNext(); count--; if (isEmpty()) tail = null; T element = temp.getElement(); return element; } public T removeLast( ) throws EmptyCollectionException // PRE: list is not empty { // POST: remove and return last element if (isEmpty( )) throw new EmptyCollectionException( ); LinearNode temp = tail; if (count == 1) head = tail = null; else { LinearNode current = head; for (int k = 0; k= count) throw new InvalidPositionException( ); if (position == 0) return removeFirst( ); else if (position == count-1) return removeLast( ); else { LinearNode previous = head; for (int k = 1; k  current = previous.getNext( ); previous.setNext(current.getNext( )); count--; return current.getElement( ); } } public boolean isEmpty ( ) // POST: return true if list is empty, else false { return count == 0; } public int size( ) // POST: return number of elements in list { return count; } public void clear ( ) // POST: remove all nodes { head = tail = null; count = 0; } public String toString ( ) // POST: return a string representation of list elements { String result = "["; LinearNode current = head; while (current != null) { result = result + " " + current.getElement(); current = current.getNext(); } result = result + " ]"; return result; } // complete the remaining methods public T remove (T element) // POST: remove and return specified element { return null; // return null if element is not found } public T first ( ) throws EmptyCollectionException // PRE: list is not empty { return null; // POST: return first element } public T last ( ) throws EmptyCollectionException // PRE: list is not empty { return null; // POST: return last element } public boolean contains (T target) // POST: return true if list contains target, else false { return true; } public int indexOf (T element ) // POST: return position of element, else -1 { return 0; } public T get (int position) throws InvalidPositionException // PRE: 0  

LinearNode.Java:

public class LinearNode {

 private T element; // element private LinearNode next; // reference to next node or null public LinearNode () // POST: empty node { element = null; next = null; } public LinearNode (T elem) // POST: node element set { element = elem; next = null; } // accessors and modifiers public LinearNode getNext() { return next; } public void setNext (LinearNode node) { next = node; } public T getElement ( ) { return element; } public void setElement (T elem) { element = elem; } }
 
TestIndexedListLinkedList.java:
 import java.io.*; import java.util.Scanner; public class TestIndexedListLinkedList { public static void main(String[] args) { Scanner scan = new Scanner (System.in); IndexedListLinkedList list = new IndexedListLinkedList ( ); list.addLast("a"); list.addLast("b"); list.addLast("*"); list.addLast("c"); System.out.println("Tester by Your Name"); System.out.println("Original list: " + list.toString()); // test remove method list.remove("*"); // element * is found and removed list.remove("d"); // element d is not found and nothing done System.out.println("List after remove: " + list.toString()); // test first and last System.out.println("First element: " + list.first()); System.out.println("Last element: " + list.last()); // test contains if (list.contains("b")) System.out.println("List contains b"); else System.out.println("List does not contain b"); if (list.contains("d")) System.out.println("List contains d"); else System.out.println("List does not contain d"); // test indexOf System.out.println("Index of b is: " + list.indexOf("b")); System.out.println("Index of d is: " + list.indexOf("d")); // test get System.out.println("String at position 1 is: " + list.get(1)); // test set list.set(1, "*"); System.out.println("List after set position 1 to *: " + list.toString()); // test invalid position try { System.out.println("Element at position 1000 is: " + list.get(1000)); } catch (InvalidPositionException e) { System.out.println(1000 + " " + e.getMessage()); } finally { System.out.println("Test program is ending."); } scan.close(); } }

Courses.txt:

COS103 COS120 COS125 COS213 COS220 COS221 COS225 COS226 COS235 COS250 COS301 COS312 COS331 COS350 COS397 COS412 COS420 COS430 COS440 COS451 COS460 COS470 COS480 COS490 COS497 

students.txt:

Adams COS103 COS213 Benson COS213 COS220 Brown COS103 COS213 Cheng COS301 COS350 COS451 Davis COS440 COS451 COS480 Eghert COS125 COS220 French COS225 COS235 COS312 Georges COS235 COS250 COS312 Heinrich COS301 COS331 COS350 Jackson COS225 COS312 Keller COS235 COS221 COS312 Lee COS125 COS220 Manner COS301 COS331 COS350 COS397 Nelsom COS220 COS225 COS312 Petty COS301 COS331 COS451 Rumer COS397 COS440 COS490 Stein COS301 COS331 COS480 Thompson COS125 COS220 Venner COS221 Washington COS490 COS497 Zaghert COS103

Part II: (80 pts.) In this assignment, remaining methods will be added to the IndexedListLinkedList class developed in lecture. An application is developed that uses this class to maintain student enrollment information. 1. Develop the InvalidPositionException class that reports a message on an invalid position for use with the IndexedListLinkedList class. 2. Complete remaining methods used in the IndexedListLinkedList class. The partially completed class is available on Blackboard attached to the assignment link. 3. Run the test program available on Blackboard. Add your name to the top line of output where it says "Your Name". Submit a screen shot only of your output; code is not needed. Tester by Your Name Original list: [ ab c1 List after remove: [abc First element: a Last element: c List contains b List does not contain d Index of b is: 1 Index of d is:-1 String at position 1 is: b List after set position 1 to: [ a c 1880 Invalid position Test program is ending 4. Create a class named Student to store data for a student. Data includes a name and a list of courses taken by the student. Use the Indexed ListLinkedList class for the list of classes. Include constructors, accessors, and modifier methods. 5. Develop an application named A6YourName.java that uses the IndexedListLinkedList class. File courses.txt contains a list of COS courses. Read theses course names into a String IndexedListLinkedList object. File students.txt contains a list of student names followed by courses taken by that student. Assume names have no blanks. Read student data into a Student IndexedListLinkedList object. 6. Report a list of each course name followed by student names taking that course. 7. Run an interactive sentinel-controlled loop that allows the user to enter student names until sentinel value "xxx" and report courses taken by that student. Report an error message if the student name cannot be found. Note: Proper structure of a sentinel-controlled loop with a priming read was reviewed in lecture and should be used here

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

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions

Question

6. How do histories influence the process of identity formation?

Answered: 1 week ago