-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcredit15.ts
More file actions
29 lines (27 loc) · 881 Bytes
/
credit15.ts
File metadata and controls
29 lines (27 loc) · 881 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
27
28
29
import IVendingMachineState from "./ivendingmachinestate";
import Credit0 from "./credit0";
import VendingMachine from "./vendingmachine";
import Credit20 from "./credit20";
class Credit15 implements IVendingMachineState {
private constructor(){ }
private static theInstance : Credit15;
static instance() : Credit15 {
if (Credit15.theInstance === undefined){
Credit15.theInstance = new Credit15();
}
return Credit15.theInstance;
}
public addNickel(v: VendingMachine) : void {
v.changeState(Credit20.instance()); }
public addDime(v: VendingMachine) : void {
v.dispenseProduct();
v.changeState(Credit0.instance(v)); }
public addQuarter(v: VendingMachine) : void {
v.dispenseProduct();
v.refund(15);
v.changeState(Credit0.instance(v)); }
public getBalance() : number {
return 15;
}
}
export default Credit15