CSCE 145: Test 1

  1. (20%) 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.*;
    public class R2D2 extends Robot {
      private Direction headDirection;
      private Direction bodyDirection;
      public ThingBag box;
      public R2D2(City city, Direction dir) {
      public void findObiWan(City aCity){
      protected int playMessage(){
  2. (20%) In the preceding program
    1. Which is/are the constructor(s)?
    2. How many arguments do the constructor(s) take?
    3. How many attributes does the MyRobot class have?
    4. Which services does the MyRobot class make available to others?
    5. Write the line of code you need to create an instance of R2D2.
  3. (10%) When you write a line of code that looks like like;
    1. What must foo refer to (what is it)?
    2. What must bar refer to (what is it)?
    Make sure you use the correct words to describe these things and describe them fully.
  4. (10%) The function below finds the area of a rectangle of width and height. Write the properly formatted javadoc comment for it.
    public int findArea(int width, int height){}
  5. (15%) What is wrong with this program? There are three things wrong.
    import becker.robots.*;
    public class BadClass {
      private int i = 20;
      while (i < 10){
        i = i - 1;
      public void main(String[] args) {
        marvin = new Robot(new City(),0,0,Direction.NORTH);
  6. (15%) Implement a boolean function for a robot which returns true if the robot is facing either North or South and false otherwise.
  7. (10%) Implement a robot which offers only one service. This function is to be called drawTriangle and takes one integer argument num. The function will first plant one Thing at the robot's current position then move one Avenue to the right and plant a column of two Things, then move right one Avenue and plant three things, and so on until it plants num columns. For example, for num = 5 the final picture should look like:
    Tip: implement a helper function that plants a column.

Jose M Vidal
Last modified: Mon Oct 2 08:47:15 EDT 2006