...
Suppose we want to define a class representing a right triangle given the length of the two sides forming the right angle, which we call base
and height
. What code should we write? Use the DrJava New
command to
create a new document. In this document define a class called RightTriangle
with fields of type double
called base
and height
, and a method
Code Block |
---|
doubleareadouble area() |
to compute the area of this right triangle. Save and compile this file. Interact with it in the Interactions pane.
...
Code Block |
---|
class Person { /** * Computes the number of months till the next birthday given the current month. */ intnMonthTillBD(intcurrentMonth) { // todo } } |
Notice in the above there is really no concrete code. As a matter of fact, the above would not compile. Now we must abandon everything and start writing test code for nMonthTillBD(...).
...
Code Block |
---|
class Person { int_bMonth; /** * Computes the number of months till the next birthday. */ int nMonthTillBD(intcurrentMonth) { return0;// todo } } |
Step 4.
After you have cleaned up your code for Person as shown in the above, you should be able to compile Test_Person. With Test_Person open, click on the Test button in DrJava tool bar.
...