Skip to main content

really basic help needed !! toString() method

1 reply [Last post]
lilmzhotti
Offline
Joined: 2010-04-21

i need to implement the toString() method to return the vales in x,y
You (4,3)

what i did is:

public ToString()
{
private String Youx;
private String Youy;

public void setYoux(String youx)
{
youx = 4;

}

public void setYouy(String youy)
{
youy = 3;

}

public String getYoux()
{
return youx;

}

public String getYouy()
{
return youy;

}

I tried this and it keeps on coming up with an error
by using the toString() how could i display the position of You (4,3)??

please help

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gvitor
Offline
Joined: 2010-04-23

Hi. I'm not sure if I got your question. Any way, I fix your code and implement "toString" method. Hope it helps.

public class ToString
{
private String Youx;
private String Youy;

public void setYoux(String youx)
{
Youx = youx;
}

public void setYouy(String youy)
{
Youy = youy;
}

public String getYoux()
{
return Youx;
}

public String getYouy()
{
return Youy;
}

public String toString(){
return "(" + Youx + "," + Youy + ")";
}

public static void main(String[] args){
ToString test = new ToString();
test.setYoux("4");
test.setYouy("3");
System.out.println(test);
}
}