Question
We want to implement a class called Robot , which designs the state and behavior of virtual robots. Each robot corresponds to an object which
We want to implement a class called Robot, which designs the state and behavior of virtual robots. Each robot corresponds to an object which is an instance of this class.
Robot characteristics:
ID (type: int).
Two integer attributes, representing coordinates, x and y, knowing that x increases by 1 when going East (decreases by 1 when going West) while y increases by 1 when going North (decreases by 1 when going South).
Direction: given by the attribute direction which takes one of the values "North", "East", "South" or "West".
The default constructor of the robot, will assign the robot ID by a value taken as an input parameter to the constructor. The position and direction can be set to default: (0,0) and "East".
Getters and setters for the attributes
Method advance() which allows the robot to go forward one step. This method checks the current direction of the robot and updates the position to move forward toward that direction by incrementing or decrementing the appropriate coordinate by 1.
Method display() which outputs the robot state in detail (prints all attributes values with System.out.println ()).
Write a RobotDemo class, containing the main method, which will be used to run your code. In the main method, you will need to create three robots of type Robot. Ask the user to input the ID of each robot. Then, ask the user to input a number between 0 and 10 (if the number is outside of this range, ask again until the input is in the range), and assign the input value to a variable called iterations. You will now loop through iterations and perform the following: For each iteration, you will randomly assign a direction (North, East, West, South) to each of the three robots, then each robot will advance following its assigned direction. You keep randomly assigning a direction and advancing robots iteration times. Then we display the final direction and coordinates of each robot.
We to improve these robots by creating a New Generation, the RobotNGs, which can do the same as Robots, and also: Advance twice as fast as the previous robots (x and y will be increased or decreased by 2 instead of 1). To do so, you need to create a new class called RobotNG that inherits from the class Robot, and do the necessary method(s) override(s) to make sure it takes into account their new feature (Advance twice as fast as the previous robots).
Update your main method, of RobotDemo class, to create 3 objects of type Robot and 3 objects of type RobotNGs, and then evolve them iteration times, just like the previous question, and print their final direction and coordinates.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started