Skip to content

Coffee Vending Machine

The goal of this lab is to write code that will provide the price for a cup of coffee, similar to the MealOrder code we wrote in class. Instead of using classes, you'll start out using Strings.

For example code that does this for MealOrder, you can look at this code, which includes the tests for the code.

Pricing

The coffee order has the following options with pricing:

Category Choices Price (cents)
Size Small 100
Medium 150
Large 200
Creamer None 0
Milk 25
Half-n-half 35

Step 1: Create CoffeeOrder Class

Create a new class CoffeeOrder that's similar to the MealOrder class we created. You should have:

  • Class-level variables to store the Size and Creamer options

Step 2: Write a Test

Write a test for a CoffeeOrder of Size Small and assert that the price is 100 cents. You will need to write code in the CoffeeOrder class, so create a price() method that returns an int based on the chosen options.

Step 3: Fail and then Pass Test

Make sure the test runs and fails, then implement the simplest code to make it pass.

Step 4: Create More Size Tests

Create more tests for the other size options, following the TDD cycle of:

  1. Write a failing test
  2. Make the test compile and pass
  3. Repeat from 1 until done with all size options.

Step 5: Support Creamer

Add tests for Creamer options and then write the code to support that. Follow the TDD cycle.

Step 6: Support Size + Creamer

Add tests that exercise having both Size and Creamer options set. You don't need to cover every combination. (Why is that?)


Once you've completed the above steps, check in with the instructor to review your code.