-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcredit0.ts
More file actions
26 lines (24 loc) · 853 Bytes
/
credit0.ts
File metadata and controls
26 lines (24 loc) · 853 Bytes
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
import IVendingMachineState from "./ivendingmachinestate";
import VendingMachine from "./vendingmachine";
import Credit5 from "./credit5";
import Credit10 from "./credit10";
class Credit0 implements IVendingMachineState {
private constructor(){ }
private static theInstance: Credit0;
static instance(v: VendingMachine) : Credit0 {
if (Credit0.theInstance === undefined) {
Credit0.theInstance = new Credit0();
}
v.welcome();
return Credit0.theInstance;
}
public addNickel(v: VendingMachine) : void {
v.changeState(Credit5.instance()); }
public addDime(v: VendingMachine) : void {
v.changeState(Credit10.instance()); }
public addQuarter(v: VendingMachine) : void {
v.dispenseProduct();
v.changeState(Credit0.instance(v)); }
public getBalance() : number { return 0; }
}
export default Credit0