I am attempting to modify the point values using my MoveUp method. However I am having trouble instantiating the class and its new values in the main method. I declared Point x1 = new Point(); then x1.moveUp();, but moveUp(); creates an error that the method is not applicable for the arguments.
public class Point { private int xcoord = 6; private int ycoord; public static void main(String[] args) { Point x1 = new Point(); x1.moveUp(); System.out.print(x1); } public Point () { xcoord = 0; ycoord = 0; } public Point (int x, int y) { x = 9; y = 8; } public int getX () { return xcoord; } public int getY () { return ycoord; } public void moveUp(int amount) { amount = xcoord + 1; } public void moveDown(int amount) { amount = ycoord - 2; } public void moveRight(int amount) { amount = xcoord + 1; } public void moveLeft(int amount) { amount = xcoord - 1; } }
x1.moveUp();, method decleration:void moveUp(int amount)intso pass an int argument..it will work finemoveUpdoes nothing but modifies the argument. The newly assigned value will never be used.Second: your method has an argument, but you call it without an argument.