using java write a code with notepad++
Create the following classes using inheritance and polymorphism
Ship named Sailboat Sally with max speed of 35.0 mph was built in 1980
Cruise Ship named Triumph with max speed of 52.0 mph was built in 2007 carries 5500 passengers
Cargo Ship named Valdez with max speed of 45.8 mph was built in 1968 with maximum cargo of 350.3 tons
Aircraft Carrier named Alabama with max speed of 55.5 mph was built in 1939 carries 2300 crew members with 42 planes
Following is the answer:
Ship.java
public class Ship {
private String name;
private float maxSpeed;
private int year;
Ship(){}
Ship(String name, float maxSpeed, int year){
this.name = name;
this.maxSpeed = maxSpeed;
this.year = year;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getMaxSpeed() {
return maxSpeed;
}
public void setMaxSpeed(float maxSpeed) {
this.maxSpeed = maxSpeed;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
@Override
public String toString() {
return "Ship named " + this.name + " with max speed of " + this.maxSpeed + "mph was built in " + this.year;
}
}
CruiseShip.java
public class CruiseShip extends Ship {
private int maxPassengers;
CruiseShip(){}
CruiseShip(String name, float maxSpeed, int year, int maxPassengers){
super(name, maxSpeed, year);
this.maxPassengers = maxPassengers;
}
public int getMaxPassengers() {
return maxPassengers;
}
public void setMaxPassengers(int maxPassengers) {
this.maxPassengers = maxPassengers;
}
@Override
public String toString() {
return super.toString() + " carries " + this.maxPassengers + "passengers" ;
}
}
CargoShip.java
public class CargoShip extends Ship {
private float maxTons;
CargoShip(){}
CargoShip(String name, float maxSpeed, int year, float maxTons){
super(name, maxSpeed, year);
this.maxTons = maxTons;
}
public float getMaxTons() {
return maxTons;
}
public void setMaxTons(float maxTons) {
this.maxTons = maxTons;
}
@Override
public String toString() {
return super.toString() + " with maximum cargo of " + this.maxTons + " tons";
}
}
AircraftCarrier.java
public class AircraftCarrier extends CruiseShip {
private int maxPlane;
AircraftCarrier(){}
AircraftCarrier(String name, float maxSpeed, int year, int maxPassengers, int maxPlane){
super(name, maxSpeed, year, maxPassengers);
this.maxPlane = maxPlane;
}
public int getMaxPlane() {
return maxPlane;
}
public void setMaxPlane(int maxPlane) {
this.maxPlane = maxPlane;
}
@Override
public String toString() {
return super.toString() + " and " + this.maxPlane + " planes";
}
}
main.java
public class main {
public static void main(String[] args) {
Ship ship = new Ship();
ship.setName("Ship1");
ship.setYear(2016);
ship.setMaxSpeed(300);
System.out.println("Ship1");
System.out.println(ship.toString());
Ship ship1 = new Ship("Ship2", 302.5f,2017);
System.out.println("Ship2");
System.out.println(ship1.toString());
System.out.println("");
CruiseShip cruiseShip1 = new CruiseShip();
cruiseShip1.setName("Cruise1");
cruiseShip1.setMaxPassengers(300);
cruiseShip1.setMaxSpeed(300);
cruiseShip1.setYear(2013);
System.out.println("CruiseShip1");
System.out.println(cruiseShip1.toString());
CruiseShip cruiseShip2 = new CruiseShip("Cruise2",300,2015,200);
System.out.println("CruiseShip2");
System.out.println(cruiseShip2.toString());
System.out.println("");
CargoShip cargoShip1 = new CargoShip();
cargoShip1.setName("Cargo1");
cargoShip1.setMaxSpeed(300);
cargoShip1.setMaxTons(1000);
cargoShip1.setYear(2012);
System.out.println("CargoShip1");
System.out.println(cargoShip1.toString());
CargoShip cargoShip2 = new CargoShip("Cargo2",250,2016,2000);
System.out.println("CargoShip2");
System.out.println(cargoShip2.toString());
System.out.println("");
AircraftCarrier aircraftCarrier1 = new AircraftCarrier();
aircraftCarrier1.setMaxPlane(100);
aircraftCarrier1.setMaxSpeed(1000);
aircraftCarrier1.setName("AirCraft1");
aircraftCarrier1.setYear(2015);
aircraftCarrier1.setMaxPassengers(500);
System.out.println("Aircraft1");
System.out.println(aircraftCarrier1.toString());
AircraftCarrier aircraftCarrier2 = new AircraftCarrier("AirCraft2", 1000, 2016,300, 200);
System.out.println("AirCraft2");
System.out.println(aircraftCarrier2.toString());
}
}
Output:

using java write a code with notepad++ Create the following classes using inheritance and polymorphism Ship...
QUESTION 5 (15 Marks) Inheritance and Polymorphism Design a Ship class that has the following members: • A private String data field named name for the name of the ship. • A private String data field named yearBuilt for the year that the ship was built. • A constructor that creates a ship with the specified name and the specified year that the ship was built. • Appropriate getter and setter methods. A toString method that overrides the toString method...
[JAVA] Program: Design a Ship class that the following members: A field for the name of the ship (a string) o A field for the year the the ship was built (a string) o A constructor and appropriate accessors and mutators A toString method that displays the ship's name and the year it was built Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following members: A field for the maximum number of passengers...
Design a Ship class that has the following class members: A field for the name of the ship A field for the year the ship was built A constructor Appropriate accessors and mutators toString method that displays the ships name and the year it was built Design a CruiseShip class the inherits from the Ship class. Include the following members: A field for the max number of passengers A constructor Appropriate accessors and mutators toString method that overrides the Ship toString method. The method...
Program Challenge 10 Design a Ship class that the following members: · A field for the name of the ship (a string). · A field for the year that the ship was built (a string). · A constructor and appropriate accessors and mutators. · A toString method that displays the ship’s name and the year it was built. Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following members: · A field for the...
C++ code For each of the following classes create default constructor and parameterized constructors(calling parent(s) parameterized constructors where it applies Add accessor and mutator function for the attribute inherent to the class Create a Base class called Shape2d with the protected floating point attribute area operator overload the + & - and operations to return the float respective to the area Derive from the Base class from called Shape2d called Rectangle with the additional floating-point attributes length & width Derive...
Inheritance and Polymorphism (use Pet.java) You are given a class named Pet.java. Create two child classes named Cat.java and Dog.java. Cat.java should add attributes for color and breed. Dog.java should add attributes for breed and size (use String for small, medium, large). Add appropriate constructors, getter/setter methods and toString() methods. In a separate file named PetDriver.java, create a main. In the main, create an ArrayList of Pet. Add an instance of Cat and an instance of Dog to the ArrayList....
Ship, CruiseShip, and CargoShip Classes (in C++ language i use visual studios to code with) design a Ship class that has the following members: - A member variable for the name of the ship (a string) - A member variable for the year that the ship was built (a string) - A contsructor and appropriate accessors and mutators - A virtual print function that displays the ship's name and the year it was built (nobody seems to get this part...
java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the below classes: public class Date { private String month; private String day; private String year; public Date(String month, String day, String year) { this.month = month; this.day = day; this.year = year; } public String getMonth() { return month; } public String getDay() { return day; } public String...
Use inheritance to create a new class AudioRecording based on Recording class that: it will retain all the members of the Recording class, it will have an additional field bitrate (non-integer numerical; it cannot be modified once set), its constructors (non-parametrized and parametrized) will set all the attributes / fields of this class (reuse code by utilizing superclass / parent class constructors): Non-parametrized constructor should set bitrate to zero, If arguments for the parametrized constructor are illegal or null, it...
1. Please write the following program in Python 3. Also, please create a UML and write the test program. Please show all outputs. (The Fan class) Design a class named Fan to represent a fan. The class contains: Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. A private int data field named speed that specifies the speed of the fan. A private bool data field named on that specifies...