Lab 4 - Burger Multiple Toppings
In the last lab, we moved the responsibility for the pricing of a topping to the BurgerToppings
enum
.
In this lab, you will allow the burger to have multiple toppings.
Make sure ALL tests PASS before you start
-
Write a test for adding a topping to a "core" burger, something like the following:
Make sure this test FAILSBurger burger = new Burger(); burger.addTopping(BurgerToppings.CHEESE); assertThat(burger.price()).isEqualTo(6);
-
What Java collection class would be appropriate to keep track of the multiple toppings:
Map
?Set
?List
? Why?- Remember generics: you will have a collection of
BurgerToppings
instead of just a single one.
- Remember generics: you will have a collection of
-
Make the test PASS.
-
Write a few more tests and make sure that you cover:
- Adding no toppings: 5
- Adding single topping of cheese: 6
- Adding single cheese and single bacon: 7
- Adding 2 (two) cheese toppings: 7
Make sure ALL tests pass
-
Increase price of Bacon to 2
- Modify your test first
- Then make the change to make the test pass
You are done when ALL tests pass.