// This class represents a Restaurant to recommend public class Restaurant implements Comparable { private String name; private int rating; // 0 - 5 stars private double avgMealCost; // in dollars // Constructs a Restaurant object with the given name, rating // and average meal cost public Restaurant(String name, int rating, double avgMealCost) { this.name = name; this.rating = rating; this.avgMealCost = avgMealCost; } // Returns a string representing the Restaurant in the following format: // ( stars, $) // ex: Mod Pizza (1 stars, $8.6) public String toString() { return name + " (" + rating + " stars, $" + avgMealCost + ")"; } // Restauraunts are first compared based on rating, then average meal cost // then name. Restaurants with higher ratings come first. If the rating is tied, // then restaurants with a lower average meal cost come first. If the rating and // the average meal cost are tied, then restaurants are compare lexicographically // by name public int compareTo(Restaurant other) { if (this.rating != other.rating) { /* if (this.rating < other.rating) { return 1; } else if (this.rating > other.rating) { return -1; }*/ return other.rating - this.rating; } else if (this.avgMealCost != other.avgMealCost) { if (this.avgMealCost < other.avgMealCost) { return -1; } else { // this.avgMealCost > other.avgMealCost return 1; } } else { return this.name.compareTo(other.name); } } }