Problems calling a method

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jomcfall97
    New Member
    • Jan 2008
    • 2

    #1

    Problems calling a method

    hey wondering if anyone can help me with some work im doing
    im trying to remove a record from a queue by using a method from a class.

    class QueueNode
    {
    private String document ;
    private String owner ;
    private int size ;
    private QueueNode next ;
    private QueueNode previous ;

    public QueueNode (String document , String owner , int size)
    {
    this.document = document ;
    this.owner = owner ;
    this.size = size ;
    next = null ;
    previous = null ;
    }

    public String getDocument()
    {
    return document ;
    }

    public String getOwner()
    {
    return owner ;
    }

    public int getSize()
    {
    return size ;
    }

    public QueueNode getNext()
    {
    return next ;
    }

    public QueueNode getPrevious()
    {
    return previous ;
    }

    public void setDocument(Str ing document)
    {
    this.document = document ;
    }

    public void setOwner(String owner)
    {
    this.owner = owner ;
    }

    public void setSize(int size)
    {
    this.size = size;
    }

    public void setNext(QueueNo de next)
    {
    this.next = next ;
    }

    public void setPrevious(Que ueNode previous) //this is the part im having trouble with
    {
    this.previous = previous ;
    }
    }


    class Queue
    {
    private QueueNode start ;
    private QueueNode end ;

    public Queue ()
    {
    start = new QueueNode("","" ,0) ;
    start = null ;
    end = new QueueNode("","" ,0) ;
    end = null ;
    }


    public void add ( String document, String owner, int size )
    {
    if ( start == null )

    {
    start = new QueueNode(docum ent,owner,size) ;
    end = start ;

    }

    else
    {
    QueueNode temp = new QueueNode(docum ent,owner,size) ;
    temp.setNext (end) ;
    end.setPrevious (temp) ;
    end = temp ;
    }
    }

    public boolean isEmpty ()
    {
    return ( start == null) ;
    }

    public QueueNode remove ()
    {
    QueueNode temp = new QueueNode("","" ,0) ;
    if ( start == null )
    return null ;

    else if ( start.setPrevio us == null)
    {
    temp = start ;
    start = null ;
    return temp ;
    }
    else
    {
    temp = start ;
    start = start.setPrevio us ;
    return temp ;
    }
    }

    public void displayAll ()
    {

    QueueNode temp = new QueueNode ("","",0) ;
    temp = start ;
    while ( temp ! = null )
    {

    System.out.prin tln ( "Document: " + temp.getDocumen t() ) ;
    System.out.prin tln ( "Owner: " + temp.getOwner() ) ;
    System.out.prin tln ( "Size: " + temp.getSize() ) ;
    temp = temp.setPreviou s ;

    }
    }
    }

    and these are the errors im getting

    Queue.java:47: cannot resolve symbol
    symbol : variable setPrevious
    location: class QueueNode
    else if ( start.setPrevio us == null)
    ^
    Queue.java:56: cannot resolve symbol
    symbol : variable setPrevious
    location: class QueueNode
    start = start.setPrevio us ;
    ^
    Queue.java:74: cannot resolve symbol
    symbol : variable setPrevious
    location: class QueueNode
    temp = temp.setPreviou s ;
    ^
    3 errors

    so im not calling setPrevious properly but whats wrong with it?

    any help appreciated

    thanks
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Your method:

    [code=java]
    public void setPrevious(Que ueNode previous) //this is the part im having trouble with
    {
    this.previous = previous ;
    }
    [/code]

    ... can only be called like this:

    [code=java]
    someObject.setP revious(somePre viousNode);
    [/code]

    Simply put: you forgot the parentheses and the single parameter.

    kind regards,

    Jos

    Comment

    • jomcfall97
      New Member
      • Jan 2008
      • 2

      #3
      help calling a method

      hey wondering if anyone can help me with some coursework im doing
      im trying to remove a record from a queue by using a method from another class.

      [CODE=java] class QueueNode
      {
      private String document ;
      private String owner ;
      private int size ;
      private QueueNode next ;
      private QueueNode previous ;

      public QueueNode (String document , String owner , int size)
      {
      this.document = document ;
      this.owner = owner ;
      this.size = size ;
      next = null ;
      previous = null ;
      }

      public String getDocument()
      {
      return document ;
      }

      public String getOwner()
      {
      return owner ;
      }

      public int getSize()
      {
      return size ;
      }

      public QueueNode getNext()
      {
      return next ;
      }

      public QueueNode getPrevious()
      {
      return previous ;
      }

      public void setDocument(Str ing document)
      {
      this.document = document ;
      }

      public void setOwner(String owner)
      {
      this.owner = owner ;
      }

      public void setSize(int size)
      {
      this.size = size;
      }

      public void setNext(QueueNo de next)
      {
      this.next = next ;
      }

      public void setPrevious(Que ueNode previous)
      {
      this.previous = previous ;
      }
      }

      -----------------------------------------------------------------------
      class Queue
      {
      private QueueNode start ;
      private QueueNode end ;

      public Queue ()
      {
      start = new QueueNode("","" ,0) ;
      start = null ;
      end = new QueueNode("","" ,0) ;
      end = null ;
      }


      public void add ( String document, String owner, int size )
      {
      if ( start == null )

      {
      start = new QueueNode(docum ent,owner,size) ;
      end = start ;

      }

      else
      {
      QueueNode temp = new QueueNode(docum ent,owner,size) ;
      temp.setNext (end) ;
      end.setPrevious (temp) ;
      end = temp ;
      }
      }

      public boolean isEmpty ()
      {
      return ( start == null) ;
      }

      public QueueNode remove ()
      {
      QueueNode temp = new QueueNode("","" ,0) ;
      if ( start == null )
      return null ;

      else if ( start.setPrevio us == null)
      {
      temp = start ;
      start = null ;
      return temp ;
      }
      else
      {
      temp = start ;
      start = start.setPrevio us ;
      return temp ;
      }
      }

      public void displayAll ()
      {

      QueueNode temp = new QueueNode ("","",0) ;
      temp = start ;
      while ( temp ! = null )
      {

      System.out.prin tln ( "Document: " + temp.getDocumen t() ) ;
      System.out.prin tln ( "Owner: " + temp.getOwner() ) ;
      System.out.prin tln ( "Size: " + temp.getSize() ) ;
      temp = temp.setPreviou s ;

      }
      }
      }
      [/CODE]
      and these are the errors im getting

      Code:
       Queue.java:47: cannot resolve symbol
      symbol : variable setPrevious
      location: class QueueNode
      else if ( start.setPrevious == null)
      ^
      Queue.java:56: cannot resolve symbol
      symbol : variable setPrevious
      location: class QueueNode
      start = start.setPrevious ;
      ^
      Queue.java:74: cannot resolve symbol
      symbol : variable setPrevious
      location: class QueueNode
      temp = temp.setPrevious ;
      ^
      3 errors
      what do i have to change?
      i did get a reply but it didnt make much sense to me (sorry jos)

      thanks

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        See how you wrote line 98 above. That's how you should call a method.

        Comment

        • Laharl
          Recognized Expert Contributor
          • Sep 2007
          • 849

          #5
          In addition to not actually calling your functions, when setting something equal to the previous entry, you would need to use get, rather than set. This is found in all three errors.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            What is wrong with my answer in your other identical thread?
            Don't double post and stick to one thread for one problem.

            kind regards,

            Jos

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by JosAH
              What is wrong with my answer in your other identical thread?
              Don't double post and stick to one thread for one problem.

              kind regards,

              Jos
              Argh.
              <shakes head>

              Comment

              • RedSon
                Recognized Expert Expert
                • Jan 2007
                • 4980

                #8
                jomcfall97,

                You are skating on thin ice. Double posting, not using [CODE] tags, and generally being dense are among your infractions. If Jos's post did not make sense to you then politely ask him to explain.

                You need to read the posting guidelines, because the next problem might result in a 5-7 day ban on your account.

                -MODERATOR

                Comment

                Working...