Results 1 to 4 of 4

Thread: Help with stack

  1. #1
    boots9491 is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Help with stack

    Java Code:
    public class Coordinate{
    	
    	private Integer row;
    	private Integer column;
    	
    	public Coordinate(Integer row, Integer column){
    		this.row = row;
    		this.column = column;
    	}
    	
    	public void setRow(Integer row){
    		this.row = row;
    	}
    	
    	public void setColumn(Integer column){
    		this.column = column;
    	}
    	
    	public Integer getRow(){
    		return row;
    	}
    	
    	public Integer getColumn(){
    		return column;
    	}
    	
    	public String toString(){
    		return "<" + row.toString() + "," + column.toString() + ">";
    	}
    }
    ok so i have this coordinate class and i have some of them pushed onto a stack. now what i want to do is peek() at one of them and be able to use the getRow and getColumn method at the one i peek at. How do i do this? The problem i am having is i am creating a new instance of Coordinate and then assigning stack.peek() to it and then using the methods on it but that not working. Confused

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

    Default Re: Help with stack

    that not working.
    Please explain what is not working.
    I don't see where you are calling the peek() method.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    boots9491 is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Re: Help with stack

    Java Code:
    Coordinate coordinate = stack.peek();
    it gives me this; incompatible types
    Coordinate coordinate = mazeStack.peek();
    ^
    required: Coordinate
    found: Object
    1 error

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

    Default Re: Help with stack

    Did you define your stack to contain Coordinate objects? If not, you will have to cast what is returned by peek() to be a Coordinate.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: 01-14-2012, 09:56 PM
  2. need stack help
    By ali1 in forum New To Java
    Replies: 4
    Last Post: 11-05-2011, 09:48 PM
  3. stack program
    By pinkx in forum New To Java
    Replies: 22
    Last Post: 08-26-2011, 09:55 PM
  4. Stack
    By kayln in forum Eclipse
    Replies: 0
    Last Post: 03-04-2011, 09:14 PM
  5. How big is the stack??
    By mgeno216 in forum New To Java
    Replies: 6
    Last Post: 03-04-2011, 09:04 AM

Tags for this Thread

Posting Permissions

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