-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.js
More file actions
44 lines (38 loc) · 1.03 KB
/
menu.js
File metadata and controls
44 lines (38 loc) · 1.03 KB
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
const {isNaturalNumber, isString} = require('./myUtil.js');
const {BoardOneMenuDTO} = require('./terminalBoard.js');
class Menu {
constructor() {
this.map = new Map;
}
addDrink(num, name, time) {
if(!isNaturalNumber(num)) return false;
if(!isNaturalNumber(time)) return false;
if(!isString(name)) return false;
this.map.set(num, {name, time});
return true;
}
getDrink(num) {
if(!isNaturalNumber(num)) return null;
const {name, time} = this.map.get(num);
return new Drink(name, time);
}
hasMenu(num) {
return this.map.has(num);
}
getInfo() {
const ret = [];
for(const [num, {name, time}] of this.map.entries()) {
ret.push(new BoardOneMenuDTO(num, name, time));
}
return ret;
}
}
class Drink {
constructor(name, time) {
this.name = name;
this.time = time;
}
getName() {return this.name;}
getTime() {return this.time;}
}
module.exports = {Menu, Drink};