Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A Simple Robot. Your task is to write Robot.java that describes the robots The Robot needs to be able to: turnLeft (90 degrees) moveForward (one

A Simple Robot. Your task is to write Robot.java that describes the robots

The Robot needs to be able to:

turnLeft (90 degrees)

moveForward (one step)

The Robot also needs to remember its location. Two methods:

getX(), and

getY()

can be used to report the current values of the robot's location. The location of the robot is a pair ( x , y ) of integers, that describes the position of the robot. When one creates a Robot one need specify:

the location (x, y)

a name for the robot

the direction the robot is facing

The robot also needs to be able to:

report the direction() it's facing (N, S, W, E)

produce a complete report() (x, y, name, direction)

Here's a sample program with two robots:

class Walk { public static void main(String[] args) { Robot a = new Robot("Alice", 2, 3, "North"); a.report(); Robot q = new Robot("Queen", -4, -1, "West"); q.report(); a.turnLeft(); a.report(); a.moveForward(); a.report(); a.turnLeft(); a.report(); a.moveForward(); a.report(); a.moveForward(); a.report(); a.moveForward(); a.report(); q.moveForward(); q.report(); q.turnLeft(); q.report(); } } 

This would produce the following output:

 Robot Alice located at (2, 3) facing North Robot Queen located at (-4, -1) facing West Robot Alice now turns left. Robot Alice located at (2, 3) facing West Robot Alice now moves forward. Robot Alice located at (1, 3) facing West Robot Alice now turns left. Robot Alice located at (1, 3) facing South Robot Alice now moves forward. Robot Alice located at (1, 4) facing South Robot Alice now moves forward. Robot Alice located at (1, 5) facing South Robot Alice now moves forward. Robot Alice located at (1, 6) facing South Robot Queen now moves forward. Robot Queen located at (-5, -1) facing West Robot Queen now turns left. Robot Queen located at (-5, -1) facing South 

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

Intelligent Information And Database Systems 12th Asian Conference ACIIDS 2020 Phuket Thailand March 23 26 2020 Proceedings

Authors: Pawel Sitek ,Marcin Pietranik ,Marek Krotkiewicz ,Chutimet Srinilta

1st Edition

9811533792, 978-9811533792

More Books

Students also viewed these Databases questions

Question

7-5 How will MIS help my career?

Answered: 1 week ago

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago

Question

Explain the testing process of accounting 2?

Answered: 1 week ago

Question

=+ What typical employee will the IA compare him/

Answered: 1 week ago

Question

=+7 What is the overall cost of the international assignment?

Answered: 1 week ago