Exercise 3b        Name __________________        Score __/9

 public class NumberDisplay
 {
 private int limit;
 private int value;
  public NumberDisplay(int rollOverLimit)
 {
     limit = rollOverLimit;
     value = 0;
 }
  public int getValue()
 {
     return value;
 }
  public void setValue(int replacementValue)
 {
     if((replacementValue >= 0) && (replacementValue < limit))
          value = replacementValue;
 }
  public void increment()
 {
     value = (value + 1) % limit;
 }
 }

  1. (3) Give the object diagram for the following fixed size array declaration similar to that of the TicketMachine at right.

    Use the NumberDisplay definition.

    NumberDisplay [ ] nd;
    nd = new NumberDisplay [ 2 ];

  2. (5) Add to the object diagram of Question 2 the results of the following similar to that at right for the TicketMachine example in Chapter 4 notes:

    NumberDisplay [ ] nd;
    nd = new NumberDisplay [ 2 ];

    nd[ 0 ] = new NumberDisplay( 10 );
    nd[ 1 ] = new NumberDisplay( 24 );

    nd[ 0 ].increment();
    nd[ 1 ].setValue( 20 );

  3. (1) Continuing Question 5, what is:

    nd[ 1 ].getDisplayValue( );   20