Provide a class FirstDigitDistribution that works just like the LastDigitDistribution class of Worked Example 9.1, except that it counts the distribution of the first digit of each value. (It is a well-known fact that the first digits of random values are not uniformly distributed. This fact has been used to detect accounting fraud, when sequences of transaction amounts had an unnatural distribution of their first digits.)

Complete the following file:

FirstDigitDistribution.java

Use the following files:

RandomSequence.java

public class RandomSequence implements Sequence
{
   public int next()
   {
      return (int) (Integer.MAX_VALUE * Math.random());
   }
}

Sequence.java

public interface Sequence
{
   int next();
}

SequenceDemo.java

public class SequenceDemo
{
   public static void main(String[] args)
   {
      FirstDigitDistribution dist1 = new FirstDigitDistribution();
      dist1.process(new SquareSequence(), 1000);
      dist1.display();
      System.out.println();

      FirstDigitDistribution dist2 = new FirstDigitDistribution();
      dist2.process(new RandomSequence(), 1000);
      dist2.display();
   }
}

SquareSequence.java

public class SquareSequence implements Sequence
{
   private int n;

   public int next()
   {
      n++;
      return n * n; 
   }
}