java - trouble with implementing classes -
i have trouble implementing classes car ship , plane. made interface is:
public interface movable public void moveforward(); public void moveforward(int x); public void movebackward(); public void movebackward(int x); public void moveleft(); public void moveleft(int y); public void moveright(); public void moveright(int y); public void displaycoordinates();
but want have 2 int
fields keep track of coordinates (x, y).
• default coordinates (0, 0), , overloaded constructor allow user initialize them other values.
• movement of objects change coordinates (x, y) 1 step @ time default depending on direction (i.e. moveforward()
add 1
x
, moveleft()
subtract 1
y
). overloaded methods allow user change coordinates n number of steps @ time (i.e. moveforward( 7 )
add 7
x
). don't know do. can me?
an interface defines methods implementing classes need implement. not define variables or maintain values variables.
for example, might have this:
public interface movable { public void moveleft(int x); }
and have class implements interface:
public class ball implements movable { private int position; public ball() { // set initial position position = 2; } @override public void moveleft(int x) { position = position - x; } }
Comments
Post a Comment