Nine Inch Nails
README
See Also
Code
Q&A
Notes
Exercises
- Carefully study the “Nine Inch Nails” code shown on the Code tab of this MESS.
- As you study the code, refer to sections 1.2 and 1.3 of Computer Science - An Interdisciplinary Approach by Sedgewick and Wayne.
Almost everything you need to know to understand the code is covered in those sections of that book.
- Ask questions if you encounter code you don’t understand.
- Compile the code.
- Try each of the following ways of executing the code after you have successfully compiled it. Make sure you understand what you are doing and observing.
java Nails
java NineInchNails
java Nail
- Add a
main
method to the Ruler
class.
- Your main method should be analogous to the
main
method of the Nail
class. When the new main
method executes it should exercise (i.e. test) the Ruler.make
method.
- Execute your
main
method using the command java Ruler
.
- Call your
Ruler.main
method (exercise 2) from the Nails.main
method.
- Call
Ruler.main
before Nail.main
is called.
- Update the Javadoc comment for the
Nails
class. Update the description, add your name to the list of authors, and change the version number.
- In the method
NineInchNails.print
, replace the nine identical System.out.println
statements with a loop that executes the statement nine times.
- In the method
Nail.makeNineInch
, replace the seven identical assignment statements with a loop that accomplishes the same thing.
- Simplify the
Nail.main
method as follows.
- Add a method called
testMake
to the class Nail
. Define testMake
in terms of a parameter of type double
.
- The
Nail.main
method repeatedly calls the same sequence of three System.out.println
statements several times.
Replace each of these repeated series of statements with a call to Nail.testMake
that does the same thing.
- Finish implementing the method
Nail.make
.
- Document the
Nail.make
method using a Javadoc style comment. After you have added your comment, use the javadoc.exe
utility to produce .html
files using a file named Nails.java
as input. Open the file named index.html
in a web browser and study what you see.