package dt265.tutorial1;

import java.util.Scanner;

/**
 * Created by brian on 31/03/2014.
 */

public class RandomNumbers {
    // Assume these default size and range values if not otherwise specified
    static private final int MAX = 10;
    static private final int RANGE = 100;
    private int[] randomNumbers;

    @SuppressWarnings("unused")
    public RandomNumbers() {
        // Example of a constructor calling another constructor using "this"
        this(MAX, RANGE);
    }

    /*
     * Allocate and populate an array of random numbers of the specified size
     * having the specified range
     */
    public RandomNumbers(int len, int range) {
        randomNumbers = new int[len];
        for (int i = 0; i < randomNumbers.length; i++) {
            randomNumbers[i] = (int) (Math.random() * range);
        }
    }

    /*
     * Return a string representation of the random list
     */
    @Override
    public String toString() {
        // Use a string buffer to build up a string
        StringBuffer sb = new StringBuffer();
        // Showing an example of Java's forach() loop structure
        for (int n: randomNumbers) {
            sb.append(n).append(", ");
        }
        return sb.toString();
    }

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter length: ");
        int len = scanner.nextInt();

        System.out.print("Enter range: ");
        int range = scanner.nextInt();

        /*
         * Because there is a toString() method defined for
         * object instances, we can do the following
         */
        System.out.println(new RandomNumbers(len, range));
    }
}

@@ -48,17 +48,16 @@
 ner;%0A%0A/*
-*
 %0A * Crea
@@ -969,17 +969,17 @@
 a string
- 
+-
 buffer t
@@ -1014,18 +1014,19 @@
 StringBu
-ff
+ild
 er sb = 
@@ -1037,18 +1037,19 @@
 StringBu
-ff
+ild
 er();%0A  
@@ -1089,16 +1089,17 @@
 va's for
+e
 ach() lo
@@ -1129,16 +1129,17 @@
 r (int n
+ 
 : random
@@ -1145,24 +1145,67 @@
 mNumbers) %7B%0A
+            // An example of call-chaining%0A
             
@@ -1237,24 +1237,78 @@
 ;%0A        %7D%0A
+        // Convert the string-buffer back to a string%0A
         retu
@@ -1373,24 +1373,169 @@
 g args%5B%5D) %7B%0A
+        /*%0A         * XXX The use of the scanner here is very brittle in%0A         * that no error checking on the input is performed%0A         */%0A
         Scan
@@ -1819,16 +1819,20 @@
        *
+ our
  object 

Improve code comments