/* Given the price and the "approval score" for different computer models, find the "best buy" -- the computer with the highest score to price ratio. */ import java.util.Scanner; public class ComputerOO { public static void main (String[] args) { Scanner scan = new Scanner(System.in); Computer best = new Computer(); best.getData(); boolean done = false; // Set the loop to find the best buy while (!done) { System.out.print ("More data? (yes/no): "); System.out.flush(); String answer = scan.nextLine(); if (answer.equals("no")) done = true; else { Computer next = new Computer(); next.getData(); if (next.isBetterThan(best)) best = next; } } best.display(); } } class Computer { private String model; private double price; private int score; public Computer () { model = ""; price = 0; score = 0; } public void getData () { Scanner scan = new Scanner(System.in); System.out.print ("Enter model: "); System.out.flush(); model = scan.nextLine(); System.out.print ("Enter price: "); System.out.flush(); price = scan.nextFloat(); System.out.print ("Enter score: "); System.out.flush(); score = scan.nextInt(); } public boolean isBetterThan (Computer nextModel) { if (this.score/this.price > nextModel.score/nextModel.price) return true; else return false; } public void display () { System.out.println ("The best buy is " + model); System.out.println ("Ratio score to price: " + score/price); } }