Source of Common.java


  1: import java.util.Scanner;

  3: /**
  4:  *
  5:  * @author Mark Young (A00000000)
  6:  */
  7: public class Common {

  9:     /**
 10:      * Generate an array of random values.
 11:      *
 12:      * @param howMany the length of the list to be generated.
 13:      * @param lo the smallest value allowed in the list
 14:      * @param hi the largest value allowed in the list
 15:      * @return an "array" of {@code howMany} numbers in the range {@code lo} to
 16:      * {@code hi}
 17:      */
 18:     public static SortArray<Integer> randomNumbers(
 19:             int howMany, int lo, int hi) {
 20:         int range = hi - lo + 1;
 21:         SortArray<Integer> result = new SortArray<>(howMany);
 22:         for (int i = 0; i < howMany; ++i) {
 23:             result.set(i, (int) (lo + range * Math.random()));
 24:         }
 25:         return result;
 26:     }

 28:     /**
 29:      * Create a SortArray containing the names of the crew on Serenity.
 30:      *
 31:      * @return an "array" containing the names of Serenity's crew
 32:      */
 33:     public static SortArray<String> getCrew() {
 34:         return SortArray.containing("Mal", "Zoe", "Kaylee", "Wash", "Jayne",
 35:                 "Inara", "Simon", "River", "Book");
 36:     }

 38:     /**
 39:      * A Scanner on System.in. The only one needed or wanted!
 40:      */
 41:     public static Scanner KBD = new Scanner(System.in);
 42:     
 43:     /**
 44:      * Prompt the user and wait for them to press the enter key.
 45:      */
 46:     public static void pause() {
 47:         System.out.print("\n...press enter...");
 48:         KBD.nextLine();
 49:         System.out.println();
 50:     }

 52: }