Stats

/*****************
 STATS
 
 This is a simple program that can calculate some statistics.
 So far it inputs 5 numbers (data), stores them in an array,
 and then adds up the TOTAL of all the numbers.  
 The program runs in text mode.  If you use NetBeans,
 you need to start with an Empty Java Class.
 
 Make the following changes:
 
 (1) Add a METHOD that prints only numbers (data) that
     are larger than 100.
     
 (2) Add a METHOD to ADD UP only the large numbers -
     those greater than 100.

 (3) Add a new method called SMALL.  It should ask the
     user what the LARGEST number is that they want to see,
     and then prints only numbers SMALLER than this max number.
     
 (4) Add a method called AVERAGESMALL.  This should COUNT the
     small numbers, then ADD them up, then divide to find
     the average of just the small numbers.

 (5) Change the program so that all the data and calculations
     are done with DOUBLE values (e.g. with decimals).
     
 (6) Change the program so that it IMMEDIATELY rejects large
     numbers (over 100) and does not save them in the array.

 (7) Write a method to fill up the array with an Arithmetic
     Progression.  It should ask the user for the starting value A,
     the common difference D, and then save 10 numbers into
     the array.

******************/

public class Stats
{
   public static void main(String[] args)
   {
      new Stats();
   }
   
   int[] data = new int[5];
   
   public Stats()
   {
      inputData();
      total();
   }
   
   public void inputData()
   {
      for (int x = 0; x < 5; x++)
      {
         int num = inputInt("Type a number:");
         data[x] = num;
      }
   }
   
   public void total()
   {
      int sum = 0;
      for (int x = 0; x < 5; x++)
      {  
         sum = sum + data[x];
      }
      output("Total = " + sum);      
   }
   
//===========================================================
//   IBIO Standard Input and Output
//===========================================================

   static void output(String info)
   { System.out.println(info);   }

   static void output(char info)
   { System.out.println(info);   }

   static void output(byte info)
   { System.out.println(info);   }

   static void output(int info)
   { System.out.println(info);   }

   static void output(long info)
   { System.out.println(info);   }

   static void output(double info)
   { System.out.println(info);   }

   static void output(boolean info)
   { System.out.println(info);   }

   static String input(String prompt)
   {  String inputLine = "";
      System.out.print(prompt);
      try
      {inputLine = (new java.io.BufferedReader(
              new java.io.InputStreamReader(System.in))).readLine();
      }
      catch (Exception e)
      { String err = e.toString();
      System.out.println(err);
      inputLine = "";
      }
      return inputLine;
   }

   static String inputString(String prompt)
   { return input(prompt);   }

   static String input()
   { return input("");       }

   static int inputInt()
   {  return inputInt(""); }

   static double inputDouble()
   { return inputDouble(""); }

   static char inputChar(String prompt)
   {  char result=(char)0;
      try{result=input(prompt).charAt(0);}
      catch (Exception e){result = (char)0;}
      return result;
   }

   static byte inputByte(String prompt)
   {  byte result=0;
      try{result=Byte.valueOf(input(prompt).trim()).byteValue();}
      catch (Exception e){result = 0;}
      return result;
   }

   static int inputInt(String prompt)
   {  int result=0;
      try{result=Integer.valueOf(
      input(prompt).trim()).intValue();}
      catch (Exception e){result = 0;}
      return result;
   }

   static long inputLong(String prompt)
   {  long result=0;
      try{result=Long.valueOf(input(prompt).trim()).longValue();}
      catch (Exception e){result = 0;}
      return result;
   }

   static double inputDouble(String prompt)
   {  double result=0;
      try{result=Double.valueOf(
      input(prompt).trim()).doubleValue();}
      catch (Exception e){result = 0;}
      return result;
   }

   static boolean inputBoolean(String prompt)
   {  boolean result=false;
      try{result=Boolean.valueOf(
      input(prompt).trim()).booleanValue();}
      catch (Exception e){result = false;}
      return result;
   }

}