Thursday, July 17, 2014

Ship Simulator Java

Class 1 : Cargo Ship 
package ship;

public class Cargo_Ship extends ship {
public int CargoCapacity;
public Cargo_Ship()
{
CargoCapacity = 0;
}
public Cargo_Ship (int cc, String n, String y)
{
super(n,y);
CargoCapacity = cc;
}
public int getCargoCapacity() {
return CargoCapacity;
}
public void setCargoCapacity(int cargoCapacity) {
this.CargoCapacity = cargoCapacity;
}
public String toString(){
return "The ship's name is: " + getShipName() +
" and the ship's cargo capacity is: " + getCargoCapacity()
+ " and the ship's year is: " + getShipYear();
}


}

Class 2: Cruise Ship 
package ship;

public class Cruise_Ship extends ship {
public int maxPasangers;
public Cruise_Ship()
{
maxPasangers = 0;
}
public Cruise_Ship (int mp, String n, String y)
{
super(n,y);
maxPasangers = mp;
}
public int getMaxPasangers() {
return maxPasangers;
}
public void setMaxPasangers(int maxPasangers) {
this.maxPasangers = maxPasangers;
}
public String toString(){
return "The ship's name is: " + getShipName() + " and the ship's max pasangers is: " + getMaxPasangers() + " and the ship's year is: " + getShipYear();
}


}

Class 3: Ship 
package ship;

public class ship {
public String shipName;
public String shipYear;
 public ship()
{
shipName = "";
shipYear = "";
}
 public ship (String n, String y)
{
 shipName = n;
 shipYear = y;
}
public String getShipName() {
return shipName;
}
public void setShipName(String shipName) {
this.shipName = shipName;
}
public String getShipYear() {
return shipYear;
}
public void setShipYear(String shipYear) {
this.shipYear = shipYear;
}
public String toString(){
return "The ship's name is: " + getShipName() + " and the ship's year is: " + getShipYear();
}


}

Class 4: Ship Demo
package ship;

import java.util.ArrayList;
public class Ship_Demo extends ship {
public static void main(String[] args)
{
ArrayList<ship> list = new ArrayList<ship>();
ship ship1 = new ship();
ship ship2 = new ship();
ship1.setShipName("DAVISON");
ship2.setShipName("DENEBOLA");
ship1.setShipYear("1982");
ship2.setShipYear("1762");
list.add(ship1);
list.add(ship2);
for (ship entry : list) {
System.out.printf("Name = %s\tYear = %s\n",
entry.getShipName(), entry.getShipYear());
}
}
}


3 comments: