Mobile
You are given an incomplete
Mobile class.A Mobile object created using the
Mobile class should have the properties like brand, ram, battery, isOnCall, and song.Implement the
Mobile class to initialize the mentioned properties and add the following methods,
MethodDescriptionchargingWhen this method is called, it should set the value of the battery to 100, if the battery is already 100 then log "Mobile Fully Charged" and call removeChargingremoveChargingIt should log "Please remove charging"playMusicIt should log a text with the song, as shown in the sample outputstopMusicIt should log "Music Stopped"makeCallWhen this method is called, it should set the value of the isOnCall to true and log "Calling ..."endCallWhen this method is called, it should log "No ongoing call to end" if isOnCall is false, else log "Call Ended" and set the value of the isOnCall to false
0 <=
battery <= 100
Sample Input 1
Apple
2 GB
90
Waka Waka
false
Sample Output 1
Mobile charged 90%
Mobile charged 100%
Playing Waka Waka song
Music stopped
No ongoing call to end
Calling...
Call Ended
Sample Input 2
Samsung
8 GB
100
Gangnam Style
true
Sample Output 2
Mobile charged 100%
Mobile is fully charged
Please remove charging
Playing Gangnam Style song
Music stopped
Call Ended
Calling...
Call Ended
i want code in between write code here
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
/* Please do not modify anything above this line */
class Mobile {
/*
* Write your code here
*/
}
/* Please do not modify anything below this line */
function main() {
const brand = readLine();
const ram = readLine();
const battery = parseInt(readLine());
const song = readLine();
const isOnCall = JSON.parse(readLine());
const myMobile = new Mobile(brand, ram, battery, isOnCall, song);
console.log(`Mobile charged ${myMobile.battery}%`); // The Mobile battery charged percentage
myMobile.charging(); // The Mobile charging
myMobile.playMusic(); // The Mobile will start playing a song
myMobile.stopMusic(); // The Mobile will stop playing a song
myMobile.endCall(); // The Mobile will end a call.
myMobile.makeCall(); // The Mobile will make a call.
myMobile.endCall(); // The Mobile will end a call.
}
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
/* Please do not modify anything above this line */
class Mobile {
/* Write your code here */
constructor(brand, ram, battery, isOnCall, song) {
this.brand = brand;
this.ram = ram;
this.battery = battery;
this.isOnCall = isOnCall;
this.song = song;
}
charging() {
if (this.battery < 100) {
this.battery = 100;
console.log('Mobile charged 100%');
} else {
console.log('Mobile Fully Charged');
this.removeChargingremoveChargingIt();
}
}
playMusic() {
console.log(`Playing ${this.song} song`);
}
stopMusic() {
console.log('Music Stopped');
}
makeCall() {
this.isOnCall = true;
console.log('Calling ...');
}
endCall() {
if (this.isOnCall) {
console.log('Call Ended');
this.isOnCall = false;
} else {
console.log('No ongoing call to end');
}
}
removeChargingremoveChargingIt() {
return console.log('Please remove charging');
}
}
/* Please do not modify anything below this line */
function main() {
const brand = readLine();
const ram = readLine();
const battery = parseInt(readLine());
const song = readLine();
const isOnCall = JSON.parse(readLine());
const myMobile = new Mobile(brand, ram, battery, isOnCall, song);
console.log(`Mobile charged ${myMobile.battery}%`); // The Mobile battery charged percentage
myMobile.charging(); // The Mobile charging
myMobile.playMusic(); // The Mobile will start playing a song
myMobile.stopMusic(); // The Mobile will stop playing a song
myMobile.endCall(); // The Mobile will end a call.
myMobile.makeCall(); // The Mobile will make a call.
myMobile.endCall(); // The Mobile will end a call.
}
Comments
Leave a comment