CS 1054: Lab 2

Lab meeting 2: A Simple Vending Machine!

Note

For this lab you can work with a partner.

Aim

The main aim of this lab is to introduce you to class implementation along with fields and methods.

List of tasks

For this lab you will implement a simple class that represents a simple vending machine. The vending machine just returns and updates the price of sodas.

Our vending machine is a bit limited and can serve only two kinds of soda. Let us say Pepsi and Coke. You can change these to your favorite soda names :). The vending machine stores prices for these. So you will need two fields that will store the prices.

The vending machine class should have two constructors. The first constructor should automatically initialize the fields to a specified value. It does not have any parameters. The second constructor will use parameters to initialize the field values.

There should be two Accessor methods, one to return value for coke and one for pepsi.

Also there should be two mutator methods to update the price of drinks.


© Mir Farooq Ali 2003.