THis is what I need to do...I need help with the third point
1. Write a class OrderedList. The implementation of OrderedList must be as a linked list of Comparable elements. The list items are maintained in ascending order at all times. On this assignment, no indexing methods are allowed. The following methods are required:
int size() //Return the number of items in the list
boolean contains(Comparable item)//Return true iff item is stored in the OrderedList
void insert(Comparable item)//Add an item to the OrderedList
Comparable remove(Comparable item) //Remove and return a matching item
Also, provide a default constructor and a toString() method.
2. Write a class, Record, to represent a concordance entry consisting of a word, a count, and a line-number list. The line-number list should be implemented as an ArrayList.
3. Write the Concordance class. There should be exactly 2 instance variables:
the name of the text file from which the Concordance is created,
and an OrderedList of Record elements.
Each Record element stores the information about one word from the text file. The constructor has a parameter for the file name, and builds the Concordance by processing the words from the text file. Provide a toString() method, a method Record lookup(String word) to look up a given word in a Concordance, and a method to write a Concordance to a text file.
this is what I have so far
import java.util.LinkedList;
public class OrderedList
{
private Node first;
public OrderedList()
{
this.first = null;
}
public int size()
{
int count = 0;
Node pointer = this.first;
while(pointer != null)
{
count++;
pointer = pointer.next;
}
return count;
}
public boolean contains(Comparable item)
{
Node pointer = this.first;
while (pointer!= null && !pointer.data.equals(item))
pointer = pointer.next;
return (pointer != null) && (pointer.data.equals(item));
}
public void insert( Comparable newI)
{
Node pointer = this.first;
Node newbee= new Node(newI);
while(pointer != null)
pointer = pointer.next;
if (pointer == null)
{
newbee.next = this.first;
this.first = newbee;
}
else
{
newbee.next = pointer.next;
pointer.next = newbee;
}
}
public Comparable remove(Comparable item)
{
if (this.first == null)
return null;
Node pointer = this.first;
Node trailer = null;
while(pointer.next != null)
{
trailer = pointer;
pointer = pointer.next;
}
if (pointer!= null)
if (trailer ==null)
this.first = pointer.next;
else
trailer.next = pointer.next;
return pointer.data;
}
public String toString()
{
String image = this.size() + " Items";
Node pointer = this.first;
while (pointer != null)
{
image += "\n" + pointer.data;
pointer = pointer.next;
}
return image;
}
private class Node
{
public Comparable data;
public Node next;
public Node(Comparable item)
{
this.data = item;
this.next = null;
}
}
}
***************************************************
import java.util.ArrayList;
public class Record
{
public String word = "";
public int count = 0;
public ArrayList<Integer> list = new ArrayList<Integer>();
public Record (String w, int c, ArrayList<Integer> l)
{
this.word = w;
this.count = c;
this.list = l;
}
}
******************************************************
import java.util.Comparator;
public class Concordance
{
public String filename = "";
public OrderedList list = new OrderedList();
public Concordance(String filename)
{
}
public Record lookup(String word)
{
// Record r = ;
return null;
}
public String toString()
{
String r ="";
//for (Record term: list)
// r = r + term;
return r;
}
}
Please I have been trying to figure it out but could not figure it out.