-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSoldState.cpp
45 lines (37 loc) · 832 Bytes
/
SoldState.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "GumballMachine.h"
#include "SoldState.h"
#include <iostream>
SoldState::SoldState(GumballMachine *gbm) : gumballMachine(gbm) { }
void
SoldState::insertQuarter()
{
std::cout << "Please wait, we're already giving you a gumball\n";
}
void
SoldState::ejectQuarter()
{
std::cout << "Sorry, you already turned the crank\n";
}
void
SoldState::turnCrank()
{
std::cout << "Turning twice doesn't get you another gumball!\n";
}
void
SoldState::dispense()
{
gumballMachine->releaseBall();
if (gumballMachine->getCount() > 0)
gumballMachine->setState(gumballMachine->getNoQuarterState());
else {
std::cout << "Oops, out of gumballs\n";
gumballMachine->setState(gumballMachine->getSoldOutState());
}
}
void
SoldState::refill() { }
void
SoldState::toString(std::ostream &os) const
{
os << "waiting for quarter";
}