-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvendingmachine.ts
More file actions
35 lines (29 loc) · 967 Bytes
/
vendingmachine.ts
File metadata and controls
35 lines (29 loc) · 967 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
30
31
32
33
34
35
import IVendingMachineState from "./ivendingmachinestate";
import Credit0 from "./credit0";
class VendingMachine {
private state: IVendingMachineState;
public constructor() {
this.state = Credit0.instance(this);
}
// methods welcome(), displayBalance() etc. as before
public welcome() : void {
console.log("Welcome. Please enter $0.25 to buy product.");
}
public dispenseProduct() : void {
console.log("dispensing product...");
}
public displayBalance() : void {
console.log("balance is now: " + this.state.getBalance());
}
public refund(i: number) : void {
console.log("refunding: " + i);
}
public changeState(state: IVendingMachineState) : void{
this.state = state;
this.displayBalance();
}
public addNickel() : void { this.state.addNickel(this); }
public addDime() : void { this.state.addDime(this); }
public addQuarter() : void { this.state.addQuarter(this); }
}
export default VendingMachine