Answer to Question #170310 in HTML/JavaScript Web Application for hemanth

Question #170310

Submarine


Given two numbers

totalTorpedos, torpedosFired as inputs, write a super class Submarine with property and methods as below,


PropertyDescriptionisSubmergedIt should contain a boolean value to indicate whether the submarine is submerged or not.


MethodDescriptiondiveWhen this method is called, it should set the value of isSubmerged to true and log "Submarine Submerged" text in the console.surfaceWhen this method is called, it should set the value of isSubmerged to false and log "Submarine Surfaced" text in the console.

Add a sub class weaponUnit which extends to Submarine with the below properties and methods,

PropertyDescriptiontorpedosIt should contain the totalTorpedos loaded.torpedosLaunchedIt should contain the torpedosFired.

MethodDescriptionfireTorpedosWhen this method is called, it should decrease the totalTorpedos by torpedosFired and log the number of torpedos fired and left, as shown in the sample outputs.

The sequence of operations is,

  1. Submerge the Submarine
  2. Fire torpedos
  3. Surface the Submarine

Input

  • The first line of input contains a number totalTorpedos
  • The second line of input contains a number torpedosFired

Output

  • The first line of output is a string with Submarine Submerged text
  • The second line of output is a string with the number of torpedos fired and left, as shown in sample outputs
  • The third line of output is a string with Submarine Surfaced text

Sample Input 1

5

2

Sample Output 1

Submarine Submerged

2 Torpedos Fired, 3 Left

Submarine Surfaced

Sample Input 2

10

2

Sample Output 2

Submarine Submerged

2 Torpedos Fired, 8 Left

Submarine Surfaced


i want code in between write your 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 Submarine {

 constructor() {

  this.isSubmerged = false;

 }


 /* Write your code here */

}


class WeaponUnit extends Submarine {

  

 /* Write your code here */


}


/* Please do not modify anything below this line */


function main() {

 const totalTorpedos = parseInt(readLine());

 const torpedosFired = parseInt(readLine());  

  

 const weaponUnit1 = new WeaponUnit(totalTorpedos, torpedosFired);

  

 weaponUnit1.dive();

 weaponUnit1.fireTorpedos();

 weaponUnit1.surface();

}


1
Expert's answer
2021-03-14T18:27:26-0400
Dear hemanth, your question requires a lot of work, which neither of our experts is ready to perform for free. We advise you to convert it to a fully qualified order and we will try to help you. Please click the link below to proceed: Submit order

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
APPROVED BY CLIENTS