Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

could someone please finish this program it has on super class called ship and 3 sub classes with all setters and getters. Please add in

could someone please finish this program it has on super class called ship and 3 sub classes with all setters and getters. Please add in the code that does this
create a driver class called FlotillaDriver that is
required to do specific tasks.
Open the text file called flotilla.csv and load all ship using
the appropriate subclass into an ArrayList dedicated to the
super class Ship.
Instantiate the proper sub ship object to add to the list. You
might need only the basic ship information in the initial list,
but when creating the displays using JOptionPane when one of the buttons is
clicked, you must provide the additional information of the
individual sub ship. Yoy should master the specific technique of loading all information from the
unique subclasses into a list of the superclass.
The organization for each line of data within the file starts
with the subship code that lets you know what type of sub
ship you have. The next six fields are the ships name, year of
built, country of registration, length, draft and beam. The
data following this depends on the the type of ship represent
ed. At this point you will need to use a decision structure using loops and if statements
based on the subship code to determine how to access the
data.After you have successfully loaded the data, you need to con
figure a popup using the showOptionsDialog static method of the JOptionPane class.The Option buttons on this pop-up should be for each sub
ship and one to quit the program. Clicking on one of the subship options will produce the popups.
code so far:
class Ship
{
private String name; // Ship name
private String nation; // Nation of registry
private int year; //4 digit year built
private int length; // Length of ship at mean draft
private int draft; // average depth below sea level
private int beam; // side to side width at mean draft
public Ship(String nam, String nat, int yer, int len, int dra, int bem)
{
name = nam;
year = yer;
nation = nat;
length = len;
draft = dra;
beam = bem;
}
public int calculateDisplacment()
{
return length*beam*draft;
}
public void setName(String n)
{
name = n;
}
public void setNation(String na)
{
nation = na;
}
public String getName()
{
return name;
}
public int getYear()
{
return year;
}
public String getNation()
{
return nation;
}
public String toString()
{
return name +","+
year +","+
nation+","+
"Size: "+length +" by "+beam+" by "+draft;
}
public int getLength(){
return length;
}
public int getDraft(){
return draft;
}
public int getBeam(){
return beam;
}
}
Sub-class:
public class CargoShip extends Ship{//all setters and getters
private int maxCargo;
private int refrigiratedStorage;
public CargoShip( String nam, String nat, int yer, int len, int dra,
int bem, int mcg, int rst)
{
super(nam, nat, yer, len, dra, bem);
maxCargo = mcg;
refrigiratedStorage = rst;
}
public String toString()
{
return super.toString()+ maxCargo +","+ refrigiratedStorage +",";
}
}
}
sub-class
public class Yacht extends Ship {
private int numStateRooms;
private int poolSize;
private int numDecks;
private int power;
private int engineSize;
public Yacht(String nam, String nat, int yer, int len, int dra, int bem,
int nsr,int pSize, int numDec, int pow, int eSize)
{
super(nam, nat, yer, len, dra, bem);
numStateRooms = nsr;
poolSize = pSize;
numDecks = numDec;
power = pow;
engineSize = eSize;
}
public String toString()
{
return super.toString()+","+ numStateRooms + poolSize +","+
numDecks +","+ power
+",";
}
}
}
sub-class
public class CruiseShip extends Ship {
private int numOfExecStateRooms;
private int numOfDoubleBunkRooms;
private int numOfQuadBunkRooms;
public CruiseShip( String nam, String nat, int yer, int len, int dra,
int bem, int ner, int ndb, int nqr)
{
super(nam, nat, yer, len, dra, bem);
numOfExecStateRooms = ner;
numOfDoubleBunkRooms = ndb;
numOfQuadBunkRooms = nqr;
}
public String toString()
{
return super.toString()+
numOfExecStateRooms +","+ numOfDoubleBunkRooms +","+
numOfQuadBunkRooms +",";
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sql All In One For Dummies 7 Books In One

Authors: Allen G Taylor ,Richard Blum

4th Edition

1394242298, 978-1394242290

More Books

Students also viewed these Databases questions