Project 4

In this assignment you will be writing a program that uses
polymorphism, an abstract class and
inheritance.
In this assignment you will have the following classes:
An abstract SpaceShip class with the following members:
The name of the ship (string)
Date the ship was built (int)
A constructor and appropriate accessors and mutators
toString that displays the ships name and the year it was built
A ColonyShip class that is a subclass of SpaceShip. This should have
the following members:
Variable for number of passengers (int)
A constructor and appropriate accessors and mutators
A toString that only displays the ships name and the maximum number of
passengers
A CargoShip class that is a subclass of SpaceShip. This should have the
following members:
A member variable for the cargo capacity in tons (int)
A constructor and appropriate accessors and mutators
A toString that displays only the ships name and the cargo capacity.
A class to use these 3 classes with the following methods:
fillUp (described in following text)
displayShips (described in the following text)
changeShip(described in the following text)
In your main method, prompt the user for how many SpaceShips they would
like to work with.
Then create an array that can point to any instance of SpaceShips and
pass it to a method called
fillUp. This method should fill up the array by, for each element in
the array, prompting the user
for a type of ship and then creating the appropriate one (prompting for
any input needed).
You should then enter a loop, which starts by calling the method
displayShips (which takes in an
array of SpaceShips), which first outputs all the ColonyShips and then
all the CargoShips. The
user should then be prompted and asked if they want to change any of
the information. If not, the
program ends. If they want to change something, prompt them for the
ship that they want to
change and call a method changeShip which takes in a reference to a
SpaceShip and prompts the
user for a new ship type and then creates a new ship of that type.
Also, make sure that any inputs you take in are protected by exception
handling. You do not need
to check for each entry, but instead can check for overall correctness
(for example, put both the
date and name reads both in a try/catch block). If an error happens,
reprompt the user for the
information until it is of the correct type.
Lastly, I want you to save a text file record of any changes made to
the ships. So after creating
your initial list of Ships, save it to a file “log.txt”. After any
changes to the ships, output what
changes were made(Ship 5 was changed from ColonyShip with 5 passengers
to CargoShip with
500 tons). So the file should contain the original list, followed by
only the changees made.