Hi guys this is my 1st question so please excuse me if I fail to relay any key details. That being said, I must write a code that will move a turtle on the screen using objects given to us in class. I am currently having trouble with the user inputted string and am having trouble conceptualizing how I will move the turtle without opening a new window.
import java.awt.Color;
import java.util.Scanner;
public class Assignment7 {
public static void main (String[] args){
World timsWorld = new World (800,800);
int x = 400, y=100;
Turtle franklin = new Turtle (x,y,timsWorld);
while (true){
String direction;
Scanner input = new Scanner(System.in);
System.out.println("please enter direction to move - left (l), right (r), or forward (f)");
direction = input.next();
if (direction == "left"){
x=x-50;
}
else if (direction == "right"){
x=x+50;
}
else if (direction == "forward") {
y=y-50;
}
else {
System.out.println("invalid input");
}
Aucun commentaire:
Enregistrer un commentaire