Assignment:3 Create a base class called WaterVehicle that has: length of ship (i
ID: 3889507 • Letter: A
Question
Assignment:3 Create a base class called WaterVehicle that has: length of ship (in number of grid spaces) starting grid location horizontal or vertical orientation on grid . sunk (boolean) Then create a class called Submarine that is derived from WaterVehicle and has the following additional properties: dive depth surfaced (Boolean) Be sure your classes have a reasonable complement of constructors, accessor, and mutator methods including a public function to determine if the Submarine was hit by a torpedo and whether a hit sunk the ship. Additionally, create an overloaded assignment operator Write a program which will allow input of the ship length, grid location, orientation, and dive depth. Assume the grid where the submarine is to be placed is a 10 by 10 grid. Randomly generate 15 torpedo shots, output the shot grid locations to the screen (you could use the grid class from the last assignment to hold the shot locations), and ther output whether the submarine was hit or missed or sunk. The submarine should be the object to understand whether it was hit or sunk. Then create a second submarine and use your overloaded assignment operator to assign the values from the first submarine to the second submarine. Print out the information about the second submarine.Explanation / Answer
public class WaterVehicle {
private int length;
private Grid start;
private boolean isHorizontal;
private boolean hasSunk;
public WaterVehicle(int length, Grid start, boolean isHorizontal, boolean hasSunk) {
this.length = length;
this.start = start;
this.isHorizontal = isHorizontal;
this.hasSunk = hasSunk;
}
public WaterVehicle() {
this.length = 0;
this.start = null;
this.isHorizontal = false;
this.hasSunk = false;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public Grid getStart() {
return start;
}
public void setStart(Grid start) {
this.start = start;
}
public boolean isIsHorizontal() {
return isHorizontal;
}
public void setIsHorizontal(boolean isHorizontal) {
this.isHorizontal = isHorizontal;
}
public boolean isHasSunk() {
return hasSunk;
}
public void setHasSunk(boolean hasSunk) {
this.hasSunk = hasSunk;
}
}
class Submarine extends WaterVehicle{
int diveDept;
boolean hasSurfaced;
public Submarine() {
diveDept = 0;
hasSurfaced = false;
}
public Submarine(int diveDept, boolean hasSurfaced, int length, Grid start, boolean isHorizontal, boolean hasSunk) {
super(length, start, isHorizontal, hasSunk);
this.diveDept = diveDept;
this.hasSurfaced = hasSurfaced;
}
}
for the main method we need the grid class from your previous assignment. Please provide the grid class also so that we can proceed with the main method
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.