Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is located at a point with integer coordinates and faces

Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is located at a point with integer coordinates and faces north, east, south, or west. Supple methods

public void turnLeft()

public void turnRight()

public void move()

public Point getLocation()

public String getDirection()

The turnLeft and turnRight methods change the direction but not the location. The move method moves the robot by one unit in the direction it is facing. The getDirection method returns a string "N", "E", "S", or "W".

Here is the tester file

import java.awt.Point; /** A class to test the Robot class. */ public class RobotTester { /** Tests the methods of the Robot class. @param args not used */ public static void main(String[] args) { // The direction of the robot. 0 - north, 1 - east, 2 - south, 3 - west // Creates a robot at Point x=5, y=5 facing east Robot robot = new Robot(new Point(5, 5), 1); robot.move(); // x=6, y=5, direction=1 robot.turnRight(); // 6, 5, 2 robot.move(); // 6, 4, 2 robot.move(); // 6, 3, 2 robot.turnRight(); // 6, 3, 3 robot.move(); // 5, 3, 3 robot.move(); // 4, 3, 3 robot.turnLeft(); // 4, 3, 2 robot.move(); // 4, 2, 2 robot.turnRight(); // 4, 2, 3 robot.turnRight(); // 4, 2, 0 robot.move(); // 4, 3, 0 Point location = robot.getLocation(); System.out.println("Location: " + location.x + ", " + location.y); System.out.println("Expected: 4, 3"); System.out.println("Direction: " + robot.getDirection()); System.out.println("Expected: N"); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

How many multiples of 4 are there between 10 and 250?

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago