Question: JAVA Can someone tell my why I cannot get the direction? public class karel { public int karelsbeepers; public static int direction; public String kareldirection;

JAVA Can someone tell my why I cannot get the direction?

public class karel {

public int karelsbeepers;

public static int direction;

public String kareldirection;

public String s = "South";

public String w = "West";

public String e = "East";

public String n = "North";

public String karelonoff = "On";

public String up = "up";

public String right = "right";

public String down = "down";

public String left = "left";

public String karelface;

public int street = 1;

public int ave = 1;

if(direction==1)

{

kareldirection = n;

karelface = up;

}else if(direction==2)

{

kareldirection = e;

karelface = right;

}

else if(direction==3)

{

kareldirection = s;

karelface = down;

}

else if(direction==4)

{

kareldirection = w;

karelface = left;

}

public void kareldisplay() {

System.out.println("Robot:");

System.out.println(" Location: " + street + " st, " + ave + " ave");

System.out.println(" Direction: " + karelface);

System.out.println(" Beepers in bag: " + karelsbeepers);

System.out.println(" On/Off: " + karelonoff);

System.out.println("=====================================");

}

public static void main(String args[]) {

karel mykarel = new karel(street =1, avenue = 1, direction = 3, karelsbeepers = 0, karelonoff);

mykarel.kareldisplay();

mykarel.pickbeep();

mykarel.kareldisplay( );

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!