UNB/ CS/ David Bremner/ teaching/ java/ BestPrice.java
public class BestPrice
{  public static void main(String[] args)
   {  final int DATA_LENGTH = 1000;
      double[] data = new double[DATA_LENGTH];
      int dataSize = 0;
            
      // read data
      
      ConsoleReader console = new ConsoleReader(System.in);
      
      boolean done = false;
      while (!done)
      {  System.out.println("Enter price, 0 to quit:");
         double price = console.readDouble();
         if (price == 0) // end of input
            done = true; 
         else if (dataSize < data.length)
         {  // add price to data array
         
            data[dataSize] = price;
            dataSize++;
         }
         else // array is full
         {  System.out.println("Sorry, the array is full.");
            done = true; 
         }
      }
      
      // compute lowest price
      
      if (dataSize == 0) return; // no data
      double lowest = data[0];
      for (int i = 1; i < dataSize; i++)
         if (data[i] < lowest) lowest = data[i];
         
      // print out prices, marking the lowest one
      
      for (int i = 0; i < dataSize; i++)
      {  System.out.print(data[i]);
         if (data[i] == lowest) 
            System.out.print(" <-- lowest price");
         System.out.println();
      }
   }
}