Other 2014 FR Questions FR other years Be Prepared Home
A-4
public class Trio implements MenuItem
{
  private Sandwich sandwich;
  private Salad salad;
  private Drink drink;
  
  public Trio(Sandwich aSandwich, Salad aSalad, Drink aDrink)
  {
    sandwich = aSandwich;
    salad = aSalad;
    drink = aDrink;
  }
  
  public String getName()
  {
    return sandwich.getName() + "/" + salad.getName() +
                                "/" + drink.getName() + " Trio";
  }
  
  public double getPrice()
  {
    double price1 = sandwich.getPrice();
    double price2 = salad.getPrice();
    double price3 = drink.getPrice();
    double smallest = Math.min(Math.min(price1, price2), price3); 1
    return price1 + price2 + price3 - smallest;
  }
}
Notes:
  1. Math.min is not in the AP subset but is handy here. Alternatively you can write, of course:
        double smallest = price1;
        if (price2 < smallest)
          smallest = price2;
        if (price3 < smallest)
          smallest = price3;


Other 2014 FR Questions | Back to Contents

Copyright © 2014 by Skylight Publishing
support@skylit.com