Exercises

  1. Write down an explanation of how a class, object, and method are related.

  2. A rectangle can be defined by the length of two adjacent sides. Write a class that holds these two pieces of integer data, and provides useful rectangle-related operations, like calculating the area, updating the side data, and calculating the combined area of two rectangles. You'll write a method with a signature like this:

    int combinedArea(secondRect sr) // the first rect is "this" of course

  3. Rewrite the ClockView class (only) so the clock displays the time in Roman numerals. The Roman numerals from 1 to 12 are I, II, III, IV, V, VI, VII, VIII, IX, X, XI, and XII.

  4. Rewrite the ClockView class so it uses the 12-hour clock and also displays AM or PM as appropriate.

  5. Rewrite the ClockView class so that it includes tenths of seconds, and change the main routine in the clock class to update the display every tenth of a second. This code in Timestamp will obtain the tenths of a second from a Calendar object:

    int mlsec = now.get(java.util.Calendar.MILLISECOND);
    tenths = mlsec / 100;

    You'll need to declare tenths as a field of Timestamp. You also need to put that number into the display of the clock in ClockView.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.109.234