Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need this program completed. Instructions are provided, the programming language

ID: 3887579 • Letter: N

Question

Need this program completed. Instructions are provided, the programming language is JAVA. Thank you!

Purpose: To review defining a Class of objects, instantiating objects of that class, and calling methods of the instantiated object. Instructions: Write a Java class named Ship to meet the requirements described in the following UMLClass Diagram. Shi Attributes Name of the ship Type of the ship Year of build Builder company rivate name: Strin private type: String rivate year: int private builder: String Operations ceconstructor>> Ship): Shi

Explanation / Answer


Note : Could you please check the output .If you required any changes Just intimate.I will modify it.Thank You.

______________

Ship.java

public class Ship {

//Declaring instance variables
private String name;
private String type;
private int year;
private String builder;

//Zero argumented constructor
public Ship() {}

//Parameterized constructor
public Ship(String name, String type, int year, String builder) {
this.name = name;
this.type = type;
this.year = year;
this.builder = builder;
}

//getters and setters
public final String getName() {
return name;
}

public final void setName(String name) {
this.name = name;
}

public final String getType() {
return type;
}

public final void setType(String type) {
this.type = type;
}

public final int getYear() {
return year;
}

public final void setYear(int year) {
this.year = year;
}

public final String getBuilder() {
return builder;
}

public void setBuilder(String builder) {
this.builder = builder;
}

//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return name + " is a " + type + " built by " + builder + " in " + year;
}

}

______________________

TestShip.java

public class TestShip {

public static void main(String[] args) {

//Creating two ship class objects
Ship s1 = new Ship("TI Oceania", "Tanker", 2003, "Daewoo Shipbuilding & Marine");
Ship s2 = new Ship("Celebrity Equinox", "Cruise", 2009, "Meyer Werft");

//Displaying the Ship class object contents inside it
System.out.println(s1.toString());
System.out.println(s2.toString());

}

}

_________________

Output:

TI Oceania is a Tanker built by Daewoo Shipbuilding & Marine in 2003
Celebrity Equinox is a Cruise built by Meyer Werft in 2009

______________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote