list of dots Digital Research Alliance of Canada logo  NSERC logo  University of Ottawa logo / UniversitĂ© d'Ottawa

User Manual    [Previous]   [Next]   

Vending Machine Classes

The following are basic requirements for a vending machine.

A vending machine dispenses a variety of products. Each product is held in one or more dispensers, identified by slot and row in the machine. The system keeps track of the number of each product type in each dispenser, so it knows when a dispenser becomes empty.

The vending machine has several coin holders. Each coin holder can contain a specific type of coin worth a particular number of cents, and with a certain weight and diameter. The system tracks the number of coins in each holder, so it can determine whether it can give change, and what coins it should give as change when somebody buys a product. Each holder also has a maximum capacity. The system keeps an electronic record of each successful purchase (transaction); it records the product dispensed from a dispenser and the number of coins added (i.e. paid by the customer) or deleted (i.e. given as change) from coin holders.

Example

// UML class diagram of a vending machine
class VendingMachine {
   singleton;
   1 -- * Dispenser slots;
}

class Dispenser {
  Character row;
  Character column;  
}

// It is possible for a dispenser to have
// one product type 'in front' and another in behind
class ProductInDispenser {
   * -- 1 Dispenser;
   * -- 1 ProductType;
   Integer numberProductsOfThisTypeLeft;
   }

class ProductType {
   Integer pricePerUnit; // cents
}

class VendingMachine {
   1 -- * CoinHolder;
}

class CoinType {
  Integer value; // cents
  Integer weight; // grams
  Integer diameter; // micrometers
}

class CoinHolder {
   * -- 1 CoinType canHold;
   Integer numCoinsCapacity;
   Integer currentNumberOfCoins;
}

// Every product purchase is recorded
class ProductTransaction {
  * -- 1 ProductInDispenser;
  1 -- * CoinHolderTransaction; // coins entered and change given
}

// The number of coins transferred to or from a CoinHolder
class CoinHolderTransaction {
   Integer numCoinsInOrOut; // negative if used to provide change
   * -- 1 CoinHolder sourceOrDestination;
}

//Positions used for diagram display
class VendingMachine
{
  position 50 29 119 45;
  position.association Dispenser:slots__VendingMachine 120,23 0,8;
  position.association CoinHolder__VendingMachine 27,45 5,0;
}

class Dispenser
{
  position 290 29 149 80;
}

class ProductInDispenser
{
  position 166 157 291 63;
  position.association ProductInDispenser__ProductType 10,63 30,0;
  position.association Dispenser__ProductInDispenser 217,0 56,80;
}

class ProductType
{
  position 120 254 166 63;
}

class CoinType
{
  position 45 531 144 97;
}

class CoinHolder
{
  position 29 362 236 80;
  position.association CoinHolder__CoinType:canHold 40,80 90,0;
}

class ProductTransaction
{
  position 337 277 136 45;
  position.association CoinHolderTransaction__ProductTransaction 112,46 179,0;
  position.association ProductInDispenser__ProductTransaction 3,0 93,63;
}

class CoinHolderTransaction
{
  position 283 501 201 63;
  position.association CoinHolder:sourceOrDestination__CoinHolderTransaction 16,0 223,80;
}
      

Load the above code into UmpleOnline

 

Another Example

// UML state machine diagram of a vending machine
// There is also a class diagram example separately
class VendingMachine
{
  controlUnit {
    ReceivingMoney {
      enterCoin  -> DeliveringItem;
    }

    DeliveringItem {
      deliveryComplete -> ReturningMoney;
    }
    
    ReturningMoney {
      returningComplete -> Waiting;
    }
    
    Waiting {
      pressSelection  -> ReceivingMoney;
    }
  }
}
      

Load the above code into UmpleOnline