Results 1 to 4 of 4
  1. #1
    ratler89 is offline Member
    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    Default List List implementation

    I have 3 files and are having trouble implementing them all, can someone help me with my errors in my driver:


    MY CODE:
    public class Driver extends LinkList
    {
    public static void main(String[] args)
    {
    LinkList l = new LinkList();

    do{
    l.reader();
    l.insert(word, listList);
    l.print(listList);
    }while(word != "stop");

    do{
    l.reader1();
    l.remove(listList, word);
    l.print(listList);
    }while(rmString != "done");

    l.first(listList);
    l.last(listList);
    l.count(listList);
    }
    }


    MY LINKLIST CODE:

    public class LinkList extends NodeClass
    {
    private NodeClass list;

    public NodeClass getlist(){
    return list;
    }

    public NodeClass setList(NodeClass list){
    NodeClass listList = list;
    return listList;
    }

    public LinkList(NodeClass listList){
    listList = null;
    }
    // method
    public String reader(){
    String word;
    System.out.println("Enter a word and enter the word stop when you are done: ");
    Scanner inputDevice = new Scanner(System.in);
    word = inputDevice.nextLine();
    return word;
    }

    // next method
    public void insert(String word, NodeClass listList){
    NodeClass temp = new NodeClass(size, word, null);
    if (listList == null){
    listList = temp;
    }else if (listList.getWord().compareTo(temp.getWord()) > 0){
    temp.setNext(listList);
    listList = temp;
    }else{
    NodeClass prev = null;
    NodeClass curr = listList;
    while(curr.getNext() != null && curr.getWord().compareTo(temp.getWord()) < 0){
    prev = curr;
    curr = curr.getNext();//moves the pointer
    } prev.setNext(temp);
    temp.setNext(curr);
    }
    }

    // next method
    public void print(NodeClass listList){
    NodeClass curr;
    curr = listList;
    while (curr.getNext() != null){
    System.out.println(curr.getWord()+" the size " + curr.getSize());
    curr = curr.getNext();
    }
    }

    public String reader1(){
    String rmString;
    System.out.println("Now type in a string of the node that you would like to remove, enter done when you are finishing removing strings: ");
    Scanner inputDevice = new Scanner(System.in);
    rmString = inputDevice.nextLine();
    return rmString;
    }

    //next method
    public void remove(NodeClass listList, String word, String rmString){
    NodeClass prev, front, curr;
    front=listList;
    reader1();
    if (front== null){
    System.out.print("The list is empty.");
    return;
    } if (front.getWord() == rmString){
    front= front.getNext();
    }else{ prev= null;
    curr=front;
    while (curr!= null){
    if (curr.getWord()==rmString){
    prev.setNext(curr.getNext());
    return;
    }else{
    prev=curr;
    curr= curr.getNext();
    }
    }
    return;
    }}

    // new method
    public void first(NodeClass listList){
    NodeClass front;
    front= listList;
    System.out.println("The contents of the first node contains: "+ front.getWord());
    }

    //new method
    public void last(NodeClass listList){
    NodeClass front;
    front= listList;
    while(front.getNext()!= null){
    front=front.getNext();}
    System.out.println("The contents of the last node contains: "+ front.getWord());
    }


    public boolean search(NodeClass listList, String rmString){
    NodeClass front;
    front=listList;
    while(front!= null){
    if(front.getWord() == rmString){
    return true;
    }else{front=front.getNext();
    }
    }return false;
    }


    //new method
    public int count(NodeClass listList){
    NodeClass curr;
    curr = listList;
    int count=0;
    while(curr != null){
    curr = curr.getNext();
    count++;
    }
    return count;
    }

    // Next Method
    public int reader2(NodeClass listList){
    int userInt;
    System.out.println("Enter size of string that you want to search for: ");
    Scanner inputDevice = new Scanner(System.in);
    userInt = inputDevice.nextInt();
    return userInt;
    }

    //Next method
    public int search(NodeClass listList, int userInt){

    int count=0;
    while(listList != null){
    if(listList.getSize()== userInt){
    count++;
    listList = listList.getNext();
    }else {listList=listList.getNext();}

    }return count;
    }
    }


    MY NODECLASS CODE:

    public class NodeClass{
    int size;
    String word;
    NodeClass next;

    public NodeClass(){
    size = 0;
    word = "";
    next = null;
    }

    public NodeClass(int s, String w, NodeClass n){
    word = w;
    size = s;
    next = n;
    }

    public String getWord(){
    return word;
    }

    public int getSize(){
    return word.length();
    }

    public NodeClass getNext(){
    return next;
    }

    public void setWord(String w){
    word = w;
    }

    public void setSize(int s){
    size = s;
    }

    public void setNext(NodeClass n){
    next = n;
    }
    }




    I have 13 errors in it compiles in my driver:

    Driver.java:15: error: constructor LinkList in class LinkList cannot be applied to given types;
    public class Driver extends LinkList
    ^
    required: NodeClass
    found: no arguments
    reason: actual and formal argument lists differ in length
    Driver.java:19: error: constructor LinkList in class LinkList cannot be applied to given types;
    LinkList l = new LinkList();
    ^
    required: NodeClass
    found: no arguments
    reason: actual and formal argument lists differ in length
    Driver.java:23: error: non-static variable word cannot be referenced from a static context
    l.insert(word, listList);
    ^
    Driver.java:23: error: cannot find symbol
    l.insert(word, listList);
    ^
    symbol: variable listList
    location: class Driver
    Driver.java:24: error: cannot find symbol
    l.print(listList);
    ^
    symbol: variable listList
    location: class Driver
    Driver.java:25: error: non-static variable word cannot be referenced from a static context
    }while(word != "stop");
    ^
    Driver.java:29: error: cannot find symbol
    l.remove(listList, word);
    ^
    symbol: variable listList
    location: class Driver
    Driver.java:29: error: non-static variable word cannot be referenced from a static context
    l.remove(listList, word);
    ^
    Driver.java:30: error: cannot find symbol
    l.print(listList);
    ^
    symbol: variable listList
    location: class Driver
    Driver.java:31: error: cannot find symbol
    }while(rmString != "done");
    ^
    symbol: variable rmString
    location: class Driver
    Driver.java:33: error: cannot find symbol
    l.first(listList);
    ^
    symbol: variable listList
    location: class Driver
    Driver.java:34: error: cannot find symbol
    l.last(listList);
    ^
    symbol: variable listList
    location: class Driver
    Driver.java:35: error: cannot find symbol
    l.count(listList);
    ^
    symbol: variable listList
    location: class Driver
    13 errors

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,993
    Rep Power
    9

    Default Re: List List implementation

    Please use code tags when posting code. Most of these problems are basic syntax errors. I suggest you write in smaller portions at a time- instead of writing the whole thing and then compiling, write a single function (or even a single line) and recompile to make sure you haven't made any mistakes. It's much harder to fix something like this than it is to fix a single compiler error.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,572
    Rep Power
    25

    Default Re: List List implementation

    Comment on single letter variable names: DON'T use them except for thing like for loop indexes or for x,y locations for drawn objects.
    Variable names should describe the data they contain.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: List List implementation

    Moved from Advanced Java. Please confine beginner questions to the New to Java section.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 1
    Last Post: 03-25-2012, 09:25 PM
  2. Singly Linked List Java implementation
    By xayto in forum New To Java
    Replies: 1
    Last Post: 08-31-2011, 01:36 PM
  3. Linked List implementation of various classes
    By the_rider9 in forum New To Java
    Replies: 2
    Last Post: 05-21-2011, 03:12 AM
  4. Linked list implementation using core java
    By jhapranay in forum Advanced Java
    Replies: 0
    Last Post: 02-03-2011, 03:15 PM
  5. Replies: 3
    Last Post: 11-21-2009, 05:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •