- Draw a UML class diagram for the following class. Make sure to also include any direct superclass (but, no details are needed for the superclass).
import becker.robots.City;
import becker.robots.Direction;
import becker.robots.Robot;
public class MyRobot extends Robot {
private Direction lookingDirection;
public MyRobot(City arg0, int arg1, int arg2, Direction arg3) {
super(arg0, arg1, arg2, arg3);
}
public static void main(String[] args) {
}
private int money;
public void findTreasure(int x, int y){
}
public ThingBag purse;
private int numPhonesInPurse(){
}
}
- In the preceding program
- Which one is the constructor?
- Which one is the parent class?
- What are the arguments the constructor takes?
- How many attributes does the MyRobot class have?
- Which services does the MyRobot class make available to others?
- Write the line of code you need to create an instance of MyRobot.
- Write a function called isOnItems which takes one integer argument x and returns true if there are at least x items on the robot's current intersection. The function should have the properly formed javadoc comment.
- Write a class which over-writes Robot's turnLeft() function and makes him move forward instead (obviously, this is a bad idea).
- Where does steve end up after running the following program?
import becker.robots.*;
public class Wanderer {
public static void main(String[] args) {
City columbia = new City();
RobotSE steve = new RobotSE(columbia, 0, 0, Direction.SOUTH);
int marbles = 5;
while (marbles > 3){
steve.move();
marbles = marbles - 1;
};
steve.turnLeft();
steve.move(marbles);
}
}
- Find and explain all the syntax errors in this program:
import becker.robots.*;
public class BadClass {
City columbia = new City();
Robot robby = new Robot(columbia, 0, 0, SOUTH);
while (i < 10){
}
public BadClass() {
super();
}
private static void main(String[] args) {
steve = new Robot(charlotte,0,0,Direction.NORTH;)
turnLeft();
}
}
- Implement a robot which, given a height and a
base numbers, places flowers (Things) such that they
form a triangle of base width = base and height = height.