-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivityList.js
More file actions
134 lines (110 loc) · 4.6 KB
/
ActivityList.js
File metadata and controls
134 lines (110 loc) · 4.6 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
'use strict';
const fs = require('fs');
process.stdin.resume();
process.stdin.setEncoding("ascii");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", function (chunk) {
inputString += chunk;
});
process.stdin.on("end", function () {
inputString = inputString.split('\n');
main();
});
function readLine() {
return inputString[currentLine++];
}
function Activity(amount) { }
function Payment(amount, receiver) {
this.amount = amount;
this.receiver = receiver;
function getAmount() {
if (this.amount == undefined) this.amount = amount
return this.amount
}
function setAmount(amount) {
if (amount <= 0) return false
this.amount = amount
return true;
}
function getReceiver() {
if (this.receiver == undefined) this.receiver = receiver
return this.receiver
}
function setReceiver(receiver) {
this.receiver = receiver
}
return {
getAmount, setAmount, getReceiver, setReceiver
}
}
Payment.prototype.getReceiver = true;
Payment.prototype.setReceiver = true;
function Refund(amount, sender) {
this.amount = amount;
this.sender = sender;
function getAmount() {
if (this.amount == undefined) this.amount = amount
return this.amount
}
function setAmount(amount) {
if (amount <= 0) return false
this.amount = amount
return true;
}
function getSender() {
if (this.sender == undefined) this.sender = sender
return this.sender
}
function setSender(sender) {
this.sender = sender
}
return {
getAmount, setAmount, getSender, setSender
}
}
Refund.prototype.getSender = true;
Refund.prototype.setSender = true;
function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
const objectType = readLine().trim();
const inputsForObjectCreation = readLine().trim().split(' ');
const updatedAmount = parseInt(readLine().trim());
const updatedSenderReceiver = readLine().trim();
switch (objectType) {
case 'Payment':
const paymentObj = new Payment(parseInt(inputsForObjectCreation[0]), inputsForObjectCreation[1]);
ws.write(`Payment object created with amount ${paymentObj.getAmount()} and receiver ${paymentObj.getReceiver()}\n`);
if (paymentObj.setAmount(updatedAmount)) {
ws.write(`Amount updated to ${updatedAmount}\n`);
} else {
ws.write(`Amount not updated\n`);
}
paymentObj.setReceiver(updatedSenderReceiver);
ws.write(`Receiver updated to ${updatedSenderReceiver}\n`);
ws.write(`Payment object details - amount is ${paymentObj.getAmount()} and receiver is ${paymentObj.getReceiver()}\n`);
ws.write(`Payment.prototype has property setAmount: ${Payment.prototype.hasOwnProperty('setAmount')}\n`);
ws.write(`Payment.prototype has property getAmount: ${Payment.prototype.hasOwnProperty('getAmount')}\n`);
ws.write(`Payment.prototype has property setReceiver: ${Payment.prototype.hasOwnProperty('setReceiver')}\n`);
ws.write(`Payment.prototype has property getReceiver: ${Payment.prototype.hasOwnProperty('getReceiver')}\n`);
break;
case 'Refund':
const refundObj = new Refund(parseInt(inputsForObjectCreation[0]), inputsForObjectCreation[1]);
ws.write(`Refund object created with amount ${refundObj.getAmount()} and sender ${refundObj.getSender()}\n`);
if (refundObj.setAmount(updatedAmount)) {
ws.write(`Amount updated to ${updatedAmount}\n`);
} else {
ws.write(`Amount not updated\n`);
}
refundObj.setSender(updatedSenderReceiver);
ws.write(`Sender updated to ${updatedSenderReceiver}\n`);
ws.write(`Refund object details - amount is ${refundObj.getAmount()} and sender is ${refundObj.getSender()}\n`);
ws.write(`Refund.prototype has property setAmount: ${Refund.prototype.hasOwnProperty('setAmount')}\n`);
ws.write(`Refund.prototype has property getAmount: ${Refund.prototype.hasOwnProperty('getAmount')}\n`);
ws.write(`Refund.prototype has property setSender: ${Refund.prototype.hasOwnProperty('setSender')}\n`);
ws.write(`Refund.prototype has property getSender: ${Refund.prototype.hasOwnProperty('getSender')}\n`);
break;
default:
break;
}
}