Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hands on OOP submission by Muhammad Haulul Azkiyaa #75

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Muhammad Haulul Azkiyaa_Universitas Telkom/classes/aprilia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
exports.Aprilia = void 0;
var motor_1 = require("./motor");
var Aprilia = /** @class */ (function (_super) {
__extends(Aprilia, _super);
function Aprilia(speed, codename, rider) {
var _this = _super.call(this, 'Aprilia Racing', speed, codename) || this;
_this.rider = rider;
return _this;
}
Aprilia.prototype.move = function () {
console.log("".concat(this.getName(), " berjalan dengan kecepatan ").concat(this.getSpeed(), " mph"));
};
Aprilia.prototype.getName = function () {
return "".concat(this.rider, " [").concat(this.brand, "]");
};
return Aprilia;
}(motor_1.Motor));
exports.Aprilia = Aprilia;
18 changes: 18 additions & 0 deletions Muhammad Haulul Azkiyaa_Universitas Telkom/classes/aprilia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Motor } from './motor';

export class Aprilia extends Motor {
private rider: string;

constructor(speed: number, codename: number, rider: string) {
super('Aprilia Racing', speed, codename);
this.rider = rider;
}

move(): void {
console.log(`${ this.getName() } berjalan dengan kecepatan ${ this.getSpeed() } mph`);
}

getName(): string {
return `${ this.rider } [${ this.brand }]`;
}
}
59 changes: 59 additions & 0 deletions Muhammad Haulul Azkiyaa_Universitas Telkom/classes/competition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"use strict";
exports.__esModule = true;
exports.Competition = void 0;
var Competition = /** @class */ (function () {
function Competition(motors, distance) {
this.motors = motors;
this.distance = distance;
this.ranks = this.motors;
}
Competition.prototype.setMotors = function (motors) {
this.motors = motors;
};
Competition.prototype.getMotors = function () {
console.log("Mobil yang terdaftar: ");
for (var i in this.motors) {
console.log("".concat(Number(i) + 1, ". ").concat(this.motors[i].getName(), ": ").concat(this.motors[i].getSpeed(), " MPH"));
}
};
Competition.prototype.setDistance = function (distance) {
this.distance = distance;
};
Competition.prototype.getDistance = function () {
return this.distance;
};
Competition.prototype.race = function () {
console.log('Lomba balap mobil dimulai!!');
for (var _i = 0, _a = this.motors; _i < _a.length; _i++) {
var motor = _a[_i];
motor.move();
}
this.setRaceTime();
this.ranks.sort(function (obj1, obj2) {
if (obj1.times > obj2.times) {
return 1;
}
else if (obj1.times < obj2.times) {
return -1;
}
else {
return 0;
}
});
console.log('Lomba balap mobil telah berakhir');
};
Competition.prototype.setRaceTime = function () {
for (var _i = 0, _a = this.ranks; _i < _a.length; _i++) {
var motor = _a[_i];
motor.times = this.distance / motor.getSpeed();
}
};
Competition.prototype.winner = function () {
console.log('\n================ Pemenang Kompetisi : ===============');
this.ranks.forEach(function (motor, index) {
console.log("".concat(index + 1, ". ").concat(motor.getName(), " : ").concat(motor.times.toFixed(2), " jam"));
});
};
return Competition;
}());
exports.Competition = Competition;
67 changes: 67 additions & 0 deletions Muhammad Haulul Azkiyaa_Universitas Telkom/classes/competition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Motor } from './motor';

export class Competition {
private motors: Motor[];
private distance: number;
private ranks: any;

constructor(motors: Motor[], distance: number) {
this.motors = motors;
this.distance = distance;
this.ranks = this.motors;
}

setMotors(motors: Motor[]): void {
this.motors = motors;
}

getMotors(): void {
console.log(`Mobil yang terdaftar: `);
for (let i in this.motors) {
console.log(`${ Number(i) + 1 }. ${ this.motors[i].getName() }: ${ this.motors[i].getSpeed() } MPH`);
}
}

setDistance(distance: number): void {
this.distance = distance;
}

getDistance(): number {
return this.distance;
}

race(): void {
console.log('Lomba balap mobil dimulai!!');

for (let motor of this.motors) {
motor.move()
}

this.setRaceTime();

this.ranks.sort((obj1, obj2) => {
if(obj1.times > obj2.times) {
return 1;
} else if(obj1.times < obj2.times) {
return -1;
} else {
return 0;
}
});

console.log('Lomba balap mobil telah berakhir');
}

setRaceTime(): void {
for (let motor of this.ranks) {
motor.times = this.distance / motor.getSpeed();
}
}

winner(): void {
console.log('\n================ Pemenang Kompetisi : ===============');
this.ranks.forEach((motor, index) => {
console.log(`${ index + 1 }. ${ motor.getName() } : ${ motor.times.toFixed(2) } jam`);
});
}
}
18 changes: 18 additions & 0 deletions Muhammad Haulul Azkiyaa_Universitas Telkom/classes/decorator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";
exports.__esModule = true;
exports.Decorator = void 0;
var Decorator = /** @class */ (function () {
function Decorator(lap) {
this.laps = {};
this.lap = lap;
}
Decorator.prototype.setLaps = function (laps) {
var currLaps = this.lap.getLaps();
this.laps = laps * currLaps;
};
Decorator.prototype.getLaps = function () {
return this.laps;
};
return Decorator;
}());
exports.Decorator = Decorator;
19 changes: 19 additions & 0 deletions Muhammad Haulul Azkiyaa_Universitas Telkom/classes/decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Lap } from "./lap";

export class Decorator implements Lap {
protected laps: number = <number>{};
protected lap: Lap;

constructor(lap: Lap) {
this.lap = lap;
}

setLaps(laps: number): void {
const currLaps = this.lap.getLaps();
this.laps = laps * currLaps;
}

getLaps(): number {
return this.laps;
}
}
35 changes: 35 additions & 0 deletions Muhammad Haulul Azkiyaa_Universitas Telkom/classes/ducati.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
exports.Ducati = void 0;
var motor_1 = require("./motor");
var Ducati = /** @class */ (function (_super) {
__extends(Ducati, _super);
function Ducati(speed, codename, rider) {
var _this = _super.call(this, 'Ducati Lenovo Team', speed, codename) || this;
_this.rider = rider;
return _this;
}
Ducati.prototype.move = function () {
console.log("".concat(this.getName(), " berjalan dengan kecepatan ").concat(this.getSpeed(), " mph"));
};
Ducati.prototype.getName = function () {
return "".concat(this.rider, " [").concat(this.brand, "]");
};
return Ducati;
}(motor_1.Motor));
exports.Ducati = Ducati;
18 changes: 18 additions & 0 deletions Muhammad Haulul Azkiyaa_Universitas Telkom/classes/ducati.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Motor } from './motor';

export class Ducati extends Motor {
private rider: string;

constructor(speed: number, codename: number, rider: string) {
super('Ducati Lenovo Team', speed, codename);
this.rider = rider;
}

move(): void {
console.log(`${ this.getName() } berjalan dengan kecepatan ${ this.getSpeed() } mph`);
}

getName(): string {
return `${ this.rider } [${ this.brand }]`;
}
}
2 changes: 2 additions & 0 deletions Muhammad Haulul Azkiyaa_Universitas Telkom/classes/lap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
exports.__esModule = true;
4 changes: 4 additions & 0 deletions Muhammad Haulul Azkiyaa_Universitas Telkom/classes/lap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Lap {
setLaps(laps: number): void;
getLaps(): number;
}
16 changes: 16 additions & 0 deletions Muhammad Haulul Azkiyaa_Universitas Telkom/classes/laps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";
exports.__esModule = true;
exports.Laps = void 0;
var Laps = /** @class */ (function () {
function Laps() {
this.laps = {};
}
Laps.prototype.setLaps = function (laps) {
this.laps = laps;
};
Laps.prototype.getLaps = function () {
return this.laps;
};
return Laps;
}());
exports.Laps = Laps;
13 changes: 13 additions & 0 deletions Muhammad Haulul Azkiyaa_Universitas Telkom/classes/laps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Lap } from "./lap";

export class Laps implements Lap {
private laps: number = <number>{};

setLaps(laps: number): void {
this.laps = laps;
}

getLaps(): number {
return this.laps;
}
}
35 changes: 35 additions & 0 deletions Muhammad Haulul Azkiyaa_Universitas Telkom/classes/mooney.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
exports.Mooney = void 0;
var motor_1 = require("./motor");
var Mooney = /** @class */ (function (_super) {
__extends(Mooney, _super);
function Mooney(speed, codename, rider) {
var _this = _super.call(this, 'Mooney VR46 Racing Team', speed, codename) || this;
_this.rider = rider;
return _this;
}
Mooney.prototype.move = function () {
console.log("".concat(this.getName(), " berjalan dengan kecepatan ").concat(this.getSpeed(), " mph"));
};
Mooney.prototype.getName = function () {
return "".concat(this.rider, " [").concat(this.brand, "]");
};
return Mooney;
}(motor_1.Motor));
exports.Mooney = Mooney;
18 changes: 18 additions & 0 deletions Muhammad Haulul Azkiyaa_Universitas Telkom/classes/mooney.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Motor } from './motor';

export class Mooney extends Motor {
private rider: string;

constructor(speed: number, codename: number, rider: string) {
super('Mooney VR46 Racing Team', speed, codename);
this.rider = rider;
}

move(): void {
console.log(`${ this.getName() } berjalan dengan kecepatan ${ this.getSpeed() } mph`);
}

getName(): string {
return `${ this.rider } [${ this.brand }]`;
}
}
Loading