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.....
The sequence of operations is,
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
sir plz provide the code for this program
class Submarine{
isSubmerged = true;
constructor(totalTorpedos, torpedosFired){
this.totalTorpedos = totalTorpedos;
this.torpedosFired = torpedosFired;
}
fireTorpedo(){
console.log(`${this.torpedosFired} torpedos fired,${this.totalTorpedos - this.torpedosFired} torpedos left`);
this.isSubmerged = false;
}
checkSubmerge(){
if(this.isSubmerged === true){
console.log("Submarine Submerged");
}else{
console.log("Submarine Resurface");
}
}
submerge(){
this.checkSubmerge();
this.fireTorpedo();
this.checkSubmerge();
}
}
const submarine = new Submarine(10,2);
submarine.submerge();
Comments
Leave a comment