-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fachrizal Gita
authored and
Fachrizal Gita
committed
Feb 23, 2018
1 parent
9aae033
commit bbd1775
Showing
11 changed files
with
186 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const WallE = require('./wall-e') | ||
const BayMax = require('./baymax') | ||
const AutoBot = require('./autobot') | ||
const RobotFactory = require('./robotfactory') | ||
|
||
let Walle = new WallE | ||
let Baymax = new BayMax | ||
let Autobot = new AutoBot | ||
|
||
let wall_e = RobotFactory.produceRobot('wall-e', 6); | ||
let baymax = RobotFactory.produceRobot('baymax', 5); | ||
let autobot = RobotFactory.produceRobot('autobot', 3); | ||
|
||
for (var i = 0; i < wall_e.length; i++) { | ||
wall_e[i].work() | ||
} | ||
|
||
for (var i = 0; i < baymax.length; i++) { | ||
baymax[i].heal(); | ||
} | ||
|
||
for (var i = 0; i < autobot.length; i++) { | ||
autobot[i].defend(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const Robot = require('./robot') | ||
|
||
class Autobot extends Robot { | ||
constructor() { | ||
super() | ||
this.name = 'AutoBot' | ||
this.purpose = 'defender' | ||
} | ||
defend(){ | ||
console.log(`${this.name}, let's roll!`) | ||
} | ||
} | ||
module.exports = Autobot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const Robot = require('./robot') | ||
|
||
class Baymax extends Robot { | ||
constructor() { | ||
super() | ||
this.name = 'BayMax' | ||
this.purpose = 'medic' | ||
} | ||
heal(){ | ||
console.log(`Hi, I'm ${this.name}, how may I help you?`) | ||
} | ||
} | ||
module.exports = Baymax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Robot { | ||
constructor(name, purpose) { | ||
this.name = name | ||
this.purpose = purpose | ||
} | ||
} | ||
|
||
module.exports = Robot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const Robot = require('./robot') | ||
const WallE = require('./wall-e') | ||
const BayMax = require('./baymax') | ||
const AutoBot = require('./autobot') | ||
|
||
class RobotFactory { | ||
constructor() { | ||
|
||
} | ||
static produceRobot(robotName, totalRobot){ | ||
let robot | ||
let result = [] | ||
if(robotName === 'wall-e'){ | ||
for(let i=0; i<totalRobot; i++){ | ||
robot = new WallE | ||
result.push(robot) | ||
} | ||
} | ||
else if(robotName === 'baymax'){ | ||
for(let i=0; i<totalRobot; i++){ | ||
robot = new BayMax | ||
result.push(robot) | ||
} | ||
} | ||
else if(robotName === 'autobot'){ | ||
for(let i=0; i<totalRobot; i++){ | ||
robot = new AutoBot | ||
result.push(robot) | ||
} | ||
} | ||
return result | ||
} | ||
} | ||
|
||
module.exports = RobotFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const Robot = require('./robot') | ||
|
||
class WallE extends Robot { | ||
constructor() { | ||
super() | ||
this.name = 'Wall-E' | ||
this.purpose = 'worker' | ||
} | ||
work(){ | ||
console.log(`${this.name} cleans the planet`) | ||
} | ||
} | ||
module.exports = WallE |
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
"author": "Erwin W Ramadhan <[email protected]>", | ||
"license": "ISC", | ||
"dependencies": { | ||
"cli-table": "^0.3.1", | ||
"sqlite3": "^3.1.13" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const sqlite3 = require('sqlite3').verbose() | ||
const db = new sqlite3.Database('database.db') | ||
const Table = require('cli-table') | ||
|
||
db.serialize(function(){ | ||
db.all(`SELECT title, point, level, name, age, gender FROM Status | ||
INNER JOIN Players ON Status.playerId = Players.id | ||
ORDER BY level DESC`, (error, data) => { | ||
if(!data){ | ||
console.log(error); | ||
}else{ | ||
console.log(data); | ||
} | ||
}) | ||
db.all(`SELECT COUNT(*) as totalcard, Players.id, Players.name, age, gender FROM Players | ||
INNER JOIN Cards ON Players.id = Cards.playerId | ||
WHERE gender = 'Male' | ||
LIMIT 3`, (error, data) => { | ||
if(!data){ | ||
console.log(error); | ||
}else{ | ||
let table = new Table({ | ||
head: ['totalcard', 'id', 'name', 'age', 'gender'], | ||
colWidths: [15, 5, 10, 5, 10] | ||
}) | ||
|
||
for(let i=0; i<data.length; i++){ | ||
table.push([data[i].totalcard, data[i].id, data[i].name, data[i].age, data[i].gender]) | ||
} | ||
console.log(table.toString()) | ||
} | ||
}) | ||
}) | ||
|
||
db.close() |