Pages

Nine Inch Nails

README

See Also

Code

Q&A

Notes

Exercises

  1. Carefully study the “Nine Inch Nails” code shown on the Code tab of this MESS.
    1. 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.
    2. Ask questions if you encounter code you don’t understand.
    3. Compile the code.
    4. 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.
      1. java Nails
      2. java NineInchNails
      3. java Nail
  2. Add a main method to the Ruler class.
    1. 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.
    2. Execute your main method using the command java Ruler.
  3. Call your Ruler.main method (exercise 2) from the Nails.main method.
    1. Call Ruler.main before Nail.main is called.
    2. Update the Javadoc comment for the Nails class. Update the description, add your name to the list of authors, and change the version number.
  4. In the method NineInchNails.print, replace the nine identical System.out.println statements with a loop that executes the statement nine times.
  5. In the method Nail.makeNineInch, replace the seven identical assignment statements with a loop that accomplishes the same thing.
  6. Simplify the Nail.main method as follows.
    1. Add a method called testMake to the class Nail. Define testMake in terms of a parameter of type double.
    2. 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.
  7. Finish implementing the method Nail.make.
  8. 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.