For the following program determine if it will compile properly and why and dete
ID: 3832369 • Letter: F
Question
For the following program determine if it will compile properly and why and determine what the program does. int JoyStick_X = A0; int JoyStick_Y = A1; int JoyStick_Z = 3; void setup () {pinMode (JoyStick_X, INPUT); pinMode (JoyStick_Y, INPUT); pinMode (JoyStickZ, INPUT_PULLUP); Serial.begin (9600);} void loop () {int x, y, z; x = analogRead (JoyStick_X) y = analogRead (JoyStick_Y); z = digitalRead (JoyStick_Z); Serial.print (x, DEC); Serial.print (", "); Serial.print (y, DEC); Serial.print (", "); Serial.println (z, DEC); delay (100);Explanation / Answer
public final class Dungeon { private final Map map = new HashMap(); private Room currentRoom; private int currentX = 0; private int currentY = 0; private Dungeon() { } private void putRoom(int x, int y, Room room) { if (!map.containsKey(x)) { map.put(x, new HashMap()); } map.get(x).put(y, room); } private Room getRoom(int x, int y) { return map.get(x).get(y); } private boolean roomExists(int x, int y) { if (!map.containsKey(x)) { return false; } return map.get(x).containsKey(y); } private boolean isComplete() { return currentRoom.isBossRoom() && currentRoom.isComplete(); } public void movePlayer(Player player) throws IOException { boolean northPossible = roomExists(currentX, currentY + 1); boolean southPossible = roomExists(currentX, currentY - 1); boolean eastPossible = roomExists(currentX + 1, currentY); boolean westPossible = roomExists(currentX - 1, currentY); System.out.print("Where would you like to go :"); if (northPossible) { System.out.print(" North (n)"); } if (eastPossible) { System.out.print(" East (e)"); } if (southPossible) { System.out.print(" South (s)"); } if (westPossible) { System.out.print(" West (w)"); } System.out.print(" ? "); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String direction = in.readLine(); if (direction.equals("n") && northPossible) { currentY++; } else if (direction.equals("s") && southPossible) { currentY--; } else if (direction.equals("e") && eastPossible) { currentX++; } else if (direction.equals("w") && westPossible) { currentX--; } currentRoom = getRoom(currentX, currentY); currentRoom.enter(player); } public void startQuest(Player player) throws IOException { while (player.isAlive() && !isComplete()) { movePlayer(player); } if (player.isAlive()) { System.out.println(Art.CROWN); } else { System.out.println(Art.REAPER); } } public static Dungeon newInstance() { Dungeon dungeon = new Dungeon(); dungeon.putRoom(0, 0, Room.newRegularInstance()); dungeon.putRoom(-1, 1, Room.newRegularInstance()); dungeon.putRoom(0, 1, Room.newRegularInstance()); dungeon.putRoom(1, 1, Room.newRegularInstance()); dungeon.putRoom(-1, 2, Room.newRegularInstance()); dungeon.putRoom(1, 2, Room.newRegularInstance()); dungeon.putRoom(-1, 3, Room.newRegularInstance()); dungeon.putRoom(0, 3, Room.newRegularInstance()); dungeon.putRoom(1, 3, Room.newRegularInstance()); dungeon.putRoom(0, 4, Room.newBossInstance()); dungeon.currentRoom = dungeon.getRoom(0, 0); return dungeon; } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.