Skip to content

Interactive Meal Kiosk

In this lab, we'll take meal orders from the keyboard in the terminal then display the contents of the order with its price.

Step 1: Create a Scanner Instance

In the MealKioskConsole's main() method, create an instance of Scanner:

Scanner scanner = new Scanner(;

Importing Scanner

The Scanner class is located in the java.util.Scanner package.

Step 2: Display a Prompt and Get Input

To display a prompt, use System.out.println(), for example:

System.out.println("What toppings do you want on your Burger? none, cheese, bacon, avocado");`

To get a line of text from the user, use the nextLine() method that's on the scanner object. E.g.:

String input = scanner.nextLine();

Step 3: Convert Input into Choices

  1. Take the input string with the toppings they wanted and convert it into a Burger instance with the toppings added, if any.

    • The user can type multiple options, e.g., any of the following would be allowed:

      bacon, avocado
    • You do not need to support multiple toppings of the same type, i.e., cheese, cheese will only add a single cheese topping and not two.

    • You should let them type their toppings in any order, e.g., bacon, cheese is the same as cheese, bacon.

      Substring Search

      The String class has a contains() method that might be helpful. E.g.:

      if (input.contains("avocado")) {
        // it has the string avocado

      It's also useful to convert the input to lowercase to make it easier to find, so String has a toLowerCase() method. E.g.:

      String input = scanner.nextLine();
      input = input.toLowerCase();
  2. Ask for the Drink size (regular or large) and create a Drink instance of the appropriate size.

At this point you will have a Burger and a Drink that you can add to the MealOrder

  1. Instantiate a MealOrder and add the burger and drink using a new method, addItem, which method would look like:

    public void addItem(MenuItem menuItem) {
  2. Call the display() method on the MealOrder instance that you just created.

  3. To make the display() useful, you'll need to add a toString() method to the Toppings class. A quick way to do it is:

    public String toString() {
      return "Toppings{" +
          "toppings=" + toppings +

[Optional] Step 4: Use While Loop

Surround your code with a while loop so you continue to ask for orders until the user exits.


Documentation for the while loop (and other loops) can be found here:

Main Method For Reference

  public static void main(String[] args) {
    Scanner scanner = new Scanner(;

    System.out.println("Drink size? (regular, large)");
    String size = scanner.nextLine().toLowerCase();