15-100 Sections S-V / Fall 2008
Quiz 6 / 2 Questions / 35 Minutes
Quiz Date:  Tue 04-Nov-2008

  1.      Chapter 1 Q’s (More may appear on next quiz)

SHOW YOUR WORK

a.       Approximately how many seconds would it take to transfer one gigabyte of data from a hard drive to on online server using a cable modem (a high-speed internet connection).

State whatever assumptions you make.  Round-off to make the math easy.

b.      The number 255 comes up a lot in computing.  It is the largest value in each part of an IP address.  It is the largest value for red, green, or blue in a Java color.  And so on.  Why?

c.       Arrange these in order from highest-level to lowest-level:

1.      Assembly language

2.      Java byte code

3.      4GLs

4.      Machine Language

5.      Java source code

2.      On a separate sheet of paper, with your name, andrew id, and section clearly written…
Write the Robot class so that the following code passes all its tests.  Do not worry about any test cases besides those given here.

All questions regarding robot behavior are answered by the test cases below!

  private static void testRobotClass() {
    System.out.print("Running Robot class tests...  ");
    // constructor (and toString)
    Robot r1 = new Robot();
    assert(r1.toString().equals("Robot[location=(0,0),facing=up]"));
 
    // another constructor
    Robot r2 = new Robot(3,5,Robot.DOWN);
    assert(r2.toString().equals("Robot[location=(3,5),facing=down]"));
 
    // accessors
    assert(r2.getLocationX() == 3);
    assert(r2.getLocationY() == 5);
    assert(r2.getFacing() == Robot.DOWN);
 
    // simple mutators
    r2.setLocation(3,6);
    r2.setFacing(Robot.RIGHT);
    assert(r2.toString().equals("Robot[location=(3,6),facing=right]"));
 
    // moveForward:  move one step in the direction the robot is facing.
    r2.moveForward(); // the robot is now facing right, so this
                      // moves right from (3,6) to (4,6)
    assert(r2.toString().equals("Robot[location=(4,6),facing=right]"));

    r2.setFacing(Robot.DOWN);
    r2.moveForward(); // the robot is now facing down, so this
                      // moves down from (4,6) to (4,5)
    assert(r2.toString().equals("Robot[location=(4,5),facing=down]"));
 
    // Overloaded moveForward: move forward as many steps as indicated
    // (Do not worry about negative values.)
    r2.moveForward(5); // moves 5 down from (4,5) to (4,0)
    assert(r2.toString().equals("Robot[location=(4,0),facing=down]"));
 
    // sameLocationAs:  takes a second Robot and returns true if they
    // are at the same (x,y) location and false otherwise.
    assert(r2.sameLocationAs(r1) == false); // r1 is at (0,0), r2 is at (4,0)
    r1.setLocation(4,0);
    assert(r2.sameLocationAs(r1) == true);  // both are at (4,0) now
 
    // We're done!
    System.out.println("Passed all tests!!!");
  } 

carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem