Hi.
Still strugling with learning objects.
Basic idea is, that object Piste(x, y) checks if parameters are in proper range and returns a string in format "(xLoc, yLoc)".
.siirrä(x, y) adds parameters to xLoc and yLoc and checks does they stay in proper range and returns a string in same format.
Return value is "Piste@998b08" and im not sure is it up to my whole code or where. If someone could pinpoint where im doing the error, i would be pleased.
// in main code Piste piste = new Piste(1, 5); System.out.println("Pisteen paikka on nyt " + piste); piste.siirrä(10, 20); System.out.println("Pisteen paikka on nyt " + piste); // // Here is the code im pondering with. class Piste{ int xLoc; int yLoc; public Piste(int x, int y) { xLoc = x; yLoc = y; } public String Piste(int x, int y) { xLoc = x; yLoc = y; if (xLoc < 0) xLoc = 0; if (yLoc < 0) yLoc = 0; if (xLoc > 100) xLoc = 100; if (yLoc > 100) yLoc = 100; return stringiksi(xLoc, yLoc); } public String siirrä(int x, int y) { xLoc = xLoc + x; yLoc = yLoc + y; if (xLoc < 0) xLoc = 0; if (yLoc < 0) yLoc = 0; if (xLoc > 100) xLoc = 100; if (yLoc > 100) yLoc = 100; return stringiksi(xLoc, yLoc); } public String stringiksi(int xLoc, int yLoc) { String palautus; palautus = "(" + Integer.toString(xLoc) + "," + Integer.toString(yLoc) + ")"; return palautus; } }