// Fig. 4.7: RandomInt.java
// Shifted, scaled random integers
import java.awt.*;
import java.applet.*;

public class RandInt extends Applet
{
   public void paint( Graphics g )
   {
      int value, xPosition, yPosition = 25;

      for ( int i = 1; i <= 4; i++ )
      {
        xPosition = 25;     // [re]initialize column position
        for (int j = 1; j <= 5; j++)
        {
            g.setColor( selColor(i,j) ); // select a color
            value = 1 + (int) ( Math.random() * 6 );
            g.drawString( Integer.toString( value ),
                       xPosition += 40, yPosition );
        }
        yPosition += 15;
      }
   }

   // select a color corresponding to (x + y) mod 3
   public Color selColor(int x, int y)
   {
    switch ( (x + y) % 3 )
    {
        case 0:
            return Color.red;
        case 1:
            return Color.blue;
        default:
            return Color.green;
    }
   }
}