/home/sjenks/NetBeansProjects/CS2/src/review/NumberClassification.java
  1 /*
  2  * Write a program to generate 25 three digit numbers and then print them, in turn
  3  * - all of the numbers
  4  * - just the odd numbers
  5  * - just those numbers which are stricly monotinic with respect to the digits 
  6  * - just those numbers which contain exactly two digits
  7  * - the numbers grouped according to the sum of the digits from low to high
  8  */
  9 package review;
 10 
 11 import java.util.ArrayList;
 12 import java.util.Collections;
 13 import java.util.Random;
 14 
 15 /**
 16  *
 17  * @author sjenks
 18  */
 19 public class NumberClassification {
 20 
 21     /**
 22      * @param args the command line arguments
 23      */
 24     public static void main(String[] args) {
 25         ArrayList<Integer> randList = getRandomNumber();
 26         getOddNumbers(randList);
 27         monotonic(randList);
 28         pairs(randList);
 29         digitSum(randList);
 30 
 31     }
 32 
 33     private static ArrayList<Integer> getRandomNumber() {
 34         ArrayList<Integer> randList = new ArrayList<>();
 35         System.out.println("The Numbers... ");
 36         for (int i = 0; i < 25; i++) {
 37             Random random = new Random();
 38             int rand = random.nextInt(900) + 100;
 39             System.out.print(rand + " ");
 40             randList.add(rand);
 41         }
 42         System.out.println();
 43         return randList;
 44 
 45     }
 46 
 47     private static void getOddNumbers(ArrayList<Integer> randList) {
 48        System.out.println("\n Odd numbers... ");
 49         for (int i = 0; i < randList.size(); i++) {
 50             int number = randList.get(i);
 51             if (isOdd(number)) {
 52                 System.out.print(number + " ");
 53             }
 54         }
 55         System.out.println();
 56 
 57     }
 58 
 59     private static boolean isOdd(int number) {
 60         return ((number % 2) == 1);
 61     }
 62 
 63     private static void monotonic(ArrayList<Integer> randList) {
 64         System.out.println("\n The strictly monotonic numbers are... ");
 65         for (int i = 0; i < randList.size(); i++) {
 66             int numb = randList.get(i);
 67             int firstNum = numb % 100;
 68             int onesPlace = firstNum % 10;
 69             int tensPlace = ((firstNum - onesPlace) / 10);
 70             int hundredsPlace = ((numb - firstNum) / 100);
 71             if (onesPlace < tensPlace & tensPlace < hundredsPlace) {
 72                 System.out.print(numb + " ");
 73             } else if (onesPlace > tensPlace & tensPlace > hundredsPlace) {
 74                 System.out.print(numb + " ");
 75             }
 76         }
 77         System.out.println();
 78     }
 79 
 80     private static void pairs(ArrayList<Integer> randList) {
 81         System.out.println("\n The pairs");
 82         for (int i = 0; i < randList.size(); i++) {
 83             int numb = randList.get(i);
 84             int firstNum = numb % 100;
 85             int onesPlace = firstNum % 10;
 86             int tensPlace = ((firstNum - onesPlace) / 10);
 87             int hundredsPlace = ((numb - firstNum) / 100);
 88             if (onesPlace == tensPlace | tensPlace == hundredsPlace | hundredsPlace == onesPlace) {
 89                 System.out.print(numb + " ");
 90             }
 91         }
 92         System.out.println();
 93     }
 94 
 95     private static void digitSum(ArrayList<Integer> randList) {
 96         System.out.println("\n The numbers by digit sum ... ");
 97         for (int s = 0; s <= 27; s++) {
 98             String theNumbers = "";
 99             for (int i = 0; i < randList.size(); i++) {
100                 int numb = randList.get(i);
101                 int firstNum = numb % 100;
102                 int onesPlace = firstNum % 10;
103                 int tensPlace = ((firstNum - onesPlace) / 10);
104                 int hundredsPlace = ((numb - firstNum) / 100);
105                 int digitSum = onesPlace + tensPlace + hundredsPlace;
106                 if (digitSum == s){
107                     theNumbers = theNumbers + " " + numb;
108                 }
109             }
110             String result = "{" + theNumbers + "}";
111             if (result.compareTo("{}")!= 0){
112                 System.out.println(result);
113             }
114         }
115     }
116 }
117 
118