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,
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
class Submarine{
constructor(totalTorpedos,torpedosFired ){
this.isSubmerged = false;
this.totalTorpedos = totalTorpedos;
this.torpedosFired = torpedosFired;
}
PropertyDescriptionisSubmergedIt(Submerged){
this.isSubmerged = Submerged;
}
DescriptiondiveWhen(){
this.PropertyDescriptionisSubmergedIt(true);
console.log('Submarine Submerged');
}
surfaceWhen(){
this.PropertyDescriptionisSubmergedIt(false);
console.log('Submarine Surfaced');
}
FireTorpedos(){
console.log(`${this.torpedosFired} Torpedos Fired, ${this.totalTorpedos-this.torpedosFired} Left`);
}
}
class weaponUnit extends Submarine{
DescriptiondiveWhen(){
super.DescriptiondiveWhen();
}
surfaceWhen(){
super.surfaceWhen();
}
FireTorpedos(){
super.FireTorpedos();
}
}
let submarine = new weaponUnit(5,2);
submarine.DescriptiondiveWhen();
submarine.FireTorpedos();
submarine.surfaceWhen();
console.log('/////////////////////////////////////////////');
let newSubmarine = new weaponUnit(10,2);
newSubmarine.DescriptiondiveWhen();
newSubmarine.FireTorpedos();
newSubmarine.surfaceWhen();
Comments
Leave a comment