UNB/ CS/ David Bremner/ teaching/ java/ ProductTest2.java
import ccj.*;

public class ProductTest2
{  public static void main(String[] args)
   {  Product best = new Product();

      boolean done = false;
      while (!done)
      {  Product next = new Product();
         next.read();
         if (next.isBetterThan(best)) best = next;

         String answer;
         System.out.print("More data? (Y/N) ");
         answer = Console.in.readLine();
         if (!answer.toUpperCase().equals("Y"))
            done = true;
      }

      System.out.print("The best bang for the buck is ");
      best.print();
   }
}

class Product
{  public Product()
   {  name = "";
      price = 0;
      score = 0;
   }

   public void read()
   {  System.out.print("Please enter the model name: ");
      name = Console.in.readLine();
      System.out.print("Please enter the price: ");
      price = Numeric.parseDouble(Console.in.readLine());
      System.out.print("Please enter the score: ");
      score = Integer.parseInt(Console.in.readLine());
   }

   public boolean isBetterThan(Product b) 
   {  if (price == 0) return false;
      if (b.price == 0) return true;
      if (score / price > b.score / b.price)
         return true;
      return false;
   }

   public void print()
   {  System.out.println(name 
         + " Price: " + price
         + " Score: " + score);
   }

   private String name;
   private double price;
   private int score;
}