0

So I've been working on a school project in Java regarding returning a frequency of words in a sentence. I started off using an array, and when I realised that wouldn't work, I switched to using a LinkedList. However, I've encountered a problem. I'm using the indexOf() and LinkedList.set methods to get an index and then set the value at the index, but these methods won't load/don't get recognised, despite importing the java.util.LinkedList library. The code is as follows.

import java.util.LinkedList;

public class Link {

//String with word and int with frequency of word
public String word;
public static int freq;
public static String input = "potato pizza pizza fries burger pizza"; //or get from client
public static String[] words = input.split(" ");

//Shows the link before this one
public Link next;

public Link(String word, int freq){
    this.word = word;
    Link.freq = freq;
}

public void display(){
    System.out.println(word +" " + freq);
}

public static void main(String[] args) {
    LinkList output = new LinkList();

    for (int i = 0; i < words.length; i++){
        Link activeLink = output.check(words[i]);

        if (activeLink != null){
            int index = indexOf(activeLink);
            output.set(index, freq++);
        }
        else
        {
            output.insertNewLink(words[i], 2);
        }
        //Insert new links
        //output.insertNewLink(words[i], 2);
    }

    output.display();
}

}

The program itself is relatively simple, if just I could get those 2 methods to work...

Any help would be greatly appreciated :-)

PS: There are quite a few custom methods in a seperate class, but I do not immedietly think them relevant to this exact problem.

0 Answers0