Skip to content

Lab 3 - Burger Topping Price

Turn Burger Options Into Toppings

Now that a Burger can stand alone, let's get rid of "regular" from the options and treat them as toppings.

Removing Regular

This is a bit tedious, since there's a bunch of tests and code that pass in REGULAR as an option.

  1. Remove REGULAR from the BurgerOptions Enum

  2. Run all of the tests

  3. They should fail. How will you fix them?


Don't continue unless ALL tests pass.


Rename to Toppings

  • Use the Refactor >> Rename... method to rename BurgerOptions into BurgerToppings

  • Run all of the tests

Don't continue unless ALL tests pass.


Push Pricing to Toppings

Let's modify the enum so that it's responsible for determining the price of each topping.

Here's an example of an enum that has an additional piece of information (in this case a code).

public enum Priority
  HIGH(3),
  MEDIUM(2),
  LOW(1)
  ;

  private final int code;

  private Priority(int code) {
    this.code = code;
  }

  public int code() {
    return code;
  }
  • Modify the BurgerToppings enum so that it can store the price for each topping. The toppings pricing is as follows:

    Topping Price
    BACON 1
    CHEESE 1
    AVOCADO 3
    • You should have a constructor that takes the price and a price() method for the enum
  • In Burger, change the price() method to use the price coming from the topping instead of calculating it directly using the else if statements. (You will still need to check for null for no topping specified.)

    Warning

    The Bacon-Cheeseburger test will fail, because we don't yet have a way to create a burger that has two toppings. Don't worry about it, you can tag it with @Ignore for now (or comment it out).

  • Run all tests