Part A. Change the `move`

and `turn`

methods of the
`Bug2`

class from Homework 3 Part C so that

- the bug can move by an arbitrary fractional number, e.g.
`bug.move(0.5)`

- the bug can turn by an arbitrary angle (in degrees), e.g.
`bug.turn(45)`

to turn 45 degrees clockwise.

Hint: Both position and direction can now be arbitrary numbers. You need to know how to rotate a direction. The equations are

newdx = cos(α) dx + sin(α) dy

newdy = -sin(α) dx + cos(α) dy

Here, α is the angle in radians. There is a method in the `Math`

class to do the conversion from degrees to radian.

Draft: Provide a tester that

- Constructs a
`Bug2`

(at the origin, facing the 3 o'clock direction) - Turns 90 degrees clockwise
- Moves by one unit
- Prints the actual and expected x- and y-values
- Turns 36.86989764584402 degrees counterclockwise (that's
sin
^{-1}(3 / 5)—draw a right triangle with side lengths 3, 4, 5 to see why this is a convenient test case) - Moves 5 units
- Prints the actual and expected x- and y-values

For the draft, you submit only `BugTester.java`

. It will be
tested with an actual `Bug2`

class (which you don't see).

For the final version, you submit both `BugTester.java`

and
`Bug2.java`

. Make sure that `Bug2`

has appropriate
Javadoc comments.

Part B. Write a tester for the following method of the
`BankAccount`

class:

/** Adds a given percentage to the balance of this account @param n how often to add the interest (e.g. 10 for ten times) @param percent the percentage to add, e.g. 5.5 to add 5.5% */ public void addInterest(int n, double percent)

You don't write the `BankAccount`

class—it's provided for you.
Actually, two classes are provided for you. For the draft, the
`addInterest`

method doesn't use compound interest—it simply adds
`n * percent`

interest. In the final, the `addInterest`

method uses compound interest. Your job is to test that the result is correct
according to the formula for compound interest:

interest = (1 + percent/100)^{n}

For both draft and final, supply `BankAccountTester.java`

that
construct a `BankAccount`

with $1000, add 10 years of interest at 5
percent, and print the actual and expected balance. In the final version, be
sure to use `Math.pow`

.

Part C. Write a class that helps in writing mail templates. Something like

DearJohn: It appears you have not turned inCS46A homework 2 draft. Please remember that you are expected to attempt all assignments in this class. Sincerely,Professor Fiendish

Each mail has these items:

- The salutation: Dear, followed by a name, colon, and a blank line
- The body,with fixed “before” and “after” parts and a variable part in the middle.
- The greeting: a blank line, Sincerely,, a blank line, and the sender.

You construct a `Mail`

object with the before and after parts and
the sender:

Mail warning = new Mail("It appears you have not turned in ", ". Please remember that\nyou are expected to attempt all assignments in this class. ", "Professor Fiendish");

Then you can make as many text strings as you like, with the
`createMessage`

method that has two parameters: the name and the
variable part.

String message1 = warning.createMessage("John", "CS46A homework 2 draft"); String message2 = warning.createMessage("Mary", "CS46A homework 2 draft"); String message3 = warning.createMessage("Shawn", "CS46A homework 2 final");

Draft: A `Mail`

class that has the required constructor and
`createMessage`

methods. The constructor need not do anything, but
`createMessage`

should return a string like ```
"Dear
John"
```

, i.e. `"Dear"`

followed by the recipient, but not a
colon. Make sure to provide Javadoc comments.

Final: The complete class.

Hint: You can use the `concat`

method to combine two strings. Try
out `"Hello".concat("World")`

to see what it does.