UNB/ CS/ David Bremner/ teaching/ java/ BestData.java
public class BestData
{  public static void main(String[] args)
   {  final int DATA_LENGTH = 1000;
      String[] names = new String[DATA_LENGTH];
      double[] prices = new double[DATA_LENGTH];
      int[] scores = new int[DATA_LENGTH];

      int dataSize = 0;
            
      // read data
      
      ConsoleReader console = new ConsoleReader(System.in);
      
      boolean done = false;
      while (!done)
      {  System.out.println
            ("Enter name or leave blank when done:");
         String inputLine = console.readLine();
         if (inputLine == null || inputLine.equals("")) 
            done = true; 
         else if (dataSize < DATA_LENGTH)
         {  names[dataSize] = inputLine;
            System.out.println("Enter price:");
            inputLine = console.readLine();
            prices[dataSize] = Double.parseDouble(inputLine);
            System.out.println("Enter score:");
            inputLine = console.readLine();
            scores[dataSize] = Integer.parseInt(inputLine);
            dataSize++;
         }
         else // array is full
         {  System.out.println("Sorry, the array is full.");
            done = true; 
         }
      }
      
      // compute best buy
      
      if (dataSize == 0) return; // no data
      double best = scores[0] / prices[0];
      for (int i = 1; i < dataSize; i++)
         if (scores[i] / prices[i] > best) 
            best = scores[i] / prices[i];
         
      // print out products, marking the best buys

      final int COLUMN_WIDTH = 30; 
      
      for (int i = 0; i < dataSize; i++)
      {  System.out.print(names[i]);

         // pad with spaces to fill column
      
         int pad = COLUMN_WIDTH - names[i].length();
         for (int j = 1; j <= pad; j++)
            System.out.print(" ");
            
         // print price and score

         System.out.print(" $" + prices[i] 
            + " score = " + scores[i]);
            
         // mark if best buy

         if (scores[i] / prices[i] == best) 
            System.out.print(" <-- best buy");
         System.out.println();
      }
   }
}
//