1. Write a useful javadoc comment for the following method. Use the javadoc format with @param and @return clauses. Be sure to describe the purpose of the method.

public Rectangle makeRectangle(int x, int y, int width, int height)
{
   int newX = x - width / 2;
   int newY = y - height / 2;
   Rectangle rect = new Rectangle(newX, newY, width, height);
   return rect;
}

2. Consider this Line class that is similar to, but not the same as, the one in the graphics library.

Complete this LineTester class that constructs two lines of your choice that are perpendicular to each other (i.e., form a 90 degree angle), and verifies that the angle is 90 degrees.

3. Modify the grant method of the Genie class so that the genie only grants 3 wishes, and otherwise (politely) refuses.

/**
   A Genie grants wishes.
*/
public class Genie
{
   private int grantedWishes;
  
   /**
      Constructs a genie, who will claim to grant wishes.
   */
   public Genie()
   {
      grantedWishes = 0;
   }

   /**
      The genie claims to grant your wish.
      @param wish Your wish
   */
   public void grant(String wish)
   {
      System.out.println("Your wish (" + wish + ") is my command!");
      grantedWishes++;
   }
}

4. Find and fix the critical logic error in the code for the bet method in the following class:

/**
   A gambler will make any even probability bet, any time.
*/
public class Gambler
{
   private double funds;
  
   /**
      Constructs a gambler with a set amount of starting funds.
      @param startingFunds the amount of money he starts with.
   */
   public Gambler(double startingFunds)
   {
      funds = startingFunds;
   }

   /**
      Makes the gambler take a bet at even probability to win or lose.
      @param amount the amount of the bet
   */
   public void bet(double amount)
   {
      double random = Math.random(); // A random floating-point value between 0 and 1
      if (random < 0.5)
         funds = amount + funds; // The gambler won
      else
         funds = amount - funds; // The gambler lost
   }

   /**
      Gets the funds remaining for the gambler.
      @return funds remaining
   */
   public double getFunds()
   {
      return funds;
   }
}

5. In Lab 4, you traced changes in the instance variables and local variables, by writing values into boxes and crossing them out. In this exercise, you will do the same tracing for a different problem. Don't cross out old values. Simply write new values under the old ones, and put an X when a local variable is removed. A typical run for Lab 4A would be

totalScore | quizCount | score | newTotalScore | newQuizCount
-------------------------------------------------------------
     0     |           |       |               |         
           |    0      |       |               |         
           |           |   8   |               |         
           |           |       |       8       |         
           |           |       |               |       1 
     8     |           |       |               |         
           |    1      |       |               |         
           |           |   X   |       X       |       X 
           |           |   7   |               |         
           |           |       |      15       |         
           |           |       |               |       2 
    15     |           |       |               |         
           |    2      |       |               |         
           |           |   X   |       X       |       X 

Note that each line only changes one variable so that one can see in which order the variables were changed.

However, when a method ends, all local variables go out of scope at the same time, so the X are all in one line.

Consider this Robot class and the sequence of calls

Robot carol = new Robot();
carol.turnLeft();
carol.moveForward();

Show the values for x, y, dx, dy, and newDx, as they are set when executing the three statements given above.

6. Draw a musical note. It should look like the following:

7. Given a string str, write a statement that sets the string rev to str with the first and last character flipped. For example, if str is "tarp", then rev should be set to "part", and if str is "sunset", then rev is "tunses".