Answer to Question #169162 in Java | JSP | JSF for Chandra sena reddy

Question #169162

Given code is :-


"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 {

 constructor(brand, ram, battery, isOnCall, song) {

  this.brand = brand;

  this.ram = ram;

  this.battery = battery;

  this.isOnCall = isOnCall;

  this.song = song;

  this.isOnCall = false;

 }

  

 onCall() {

  this.isOnCall = true;

 }

  

 removeCharging() {

   console.log("Please remove charging");

 }

  


 charging() {

  if (this.battery < 100) {

   this.battery = 100;

   console.log(`Mobile charged ${this.battery}%`);

  } else {

   console.log(`Mobile is fully charged`);

   this.removeCharging();

  }

 }

  

 playMusic() {

   this.song = this.song;

   console.log(`Playing ${this.song} song`);

  }

   

 stopMusic() {

   this.song = this.song;

   console.log('Music stopped');

  }

   

  makeCall() {

   console.log("Calling...");

  }

   

 endCall() {

  if (this.isOnCall == false) {

    this.isOnCall = true;

   console.log('No ongoing call to end');

  } else if (this.isOnCall == true) {

   console.log('Call Ended');

  }

 }

}


/* 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.

}


Input

  • The first line of input contains a string brand
  • The second line of input contains a string ram
  • The third line of input contains a number battery
  • The fourth line of input contains a string song
  • The fifth line of input contains a boolean isOnCall

Output

  • The first line of output is a string containing
  • battery before charging, as shown in the sample outputs
  • The second line of output is a string based on
  • battery, as shown in the sample outputs
  • The third line of output is a string containing
  • song, as shown in the sample outputs
  • The fourth line of output is a string "Music stopped"
  • The fifth line of output is a string "No ongoing call to end" or "Call Ended"
  • The sixth line of output is a string "Calling..."
  • The seventh line of output is a string "Call Ended"

Constraints

0 <=

battery <= 100


sample input :-

Apple

2 GB

90

Waka Waka

false


sample output :-

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


please help me for getting the accurate outputs a above, not error is displaying in the output, but the main problem is in the ( Endcall section) I think so.

Once U please run the code you may understand where to modify.

thankyou.



1
Expert's answer
2021-03-10T16:56:06-0500
class Mobile {

  private char brand;
private char ram;
private char battery;
private boolean isOnCall;
private char song;



void constructor(char brand,char ram,char battery,boolean isOnCall,char song){

  this.brand = brand;

  this.ram = ram;

  this.battery = battery;

  this.isOnCall = isOnCall;

  this.song = song;

  this.isOnCall = false;

 }

 

 void onCall() {

  this.isOnCall = true;

 }

 

 void removeCharging() {

   System.out.println("Please remove charging");

 }

 


 void charging() {

  if (this.battery < 100) {

   this.battery = 100;

   System.out.println("Mobile charged ${this.battery}%");

  } else {

   System.out.println("Mobile is fully charged");

   this.removeCharging();

  }

 }

 

 void playMusic() {

   this.song = this.song;

   System.out.println("Playing ${this.song} song");

  }

   

 void stopMusic() {

   this.song = this.song;

   System.out.println("Music stopped");

  }

   

  void makeCall() {

   System.out.println("Calling...");

  }

   

 void endCall() {

  if (this.isOnCall == false) {

    this.isOnCall = true;

   System.out.println("No ongoing call to end");

  } else if (this.isOnCall == true) {

   System.out.println("Call Ended");

  }

 }

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog