Question
Needing all 3 codes completed. CrewMember.java , Starship.java , and Fleet.java Thank You. ----------------------------------------------------------------------------------- Task: The Federation needs you! The United Federation of Planets needs
Needing all 3 codes completed. CrewMember.java , Starship.java , and Fleet.java Thank You.
-----------------------------------------------------------------------------------
Task: The Federation needs you!
The United Federation of Planets needs your help organizing their fleet of interstellar starships. They're requesting software with a simple interface and Java objects to handle starships, which are spacecrafts manned by a crew. With this software, the Federation will be able to accurately track senior staff aboard each starship. Make it so!
Getting Started
Begin by creating a new Java project in Eclipse, named according to the lab guidelines
Create the following classes in the default package of your project:
Fleet.java
Starship.java
CrewMember.java
Your application will read in data from text files placed in a data directory. Create a new folder called data in your project (note: this new folder must not be in your src folder), and move all sample files into it.
To get you started, we've provided a test class, Lab2.java. Put this in your default package as well. Your final submission must include this class exactly as it appears here, and the data files given. Once your application is completed, running Lab2.java with the given data files will result in the exact output shown below. Do not change this class.
Lab2.java
Output:
Once your code compiles, you will be able to examine the output of your program. The output of your program must match the format of the sample below. This sample is the result of running the Lab2.java class with the given main method.
---------------------------- United Federation of Planets ---------------------------- USS Endeavour, Nebula. Registry: NCC-71805 0 crew members assigned. USS Bozeman, Sovereign. Registry: NCC-1941-A 0 crew members assigned. USS Enterprise, Constitution. Registry: NCC-1701-A 8 crew members assigned. - James T. Kirk (Captain) - Commanding Officer [Human] - Spock (Commander) - First Officer [Vulcan/Human] - Leonard McCoy (Lieutenant Commander) - Chief Medical Officer [Human] - Montgomery Scott (Lieutenant Commander) - Chief Engineering Officer [Human] - Christine Chapel (Crewman) - Nurse [Human] - Nyota Uhura (Lieutenant) - Communications Officer [Human] - Hikaru Sulu (Lieutenant) - Helmsman [Human] - Pavel Chekov (Ensign) - Navigator [Human] USS Bozeman, Soyuz. Registry: NCC-1941 0 crew members assigned. USS Enterprise, Galaxy. Registry: NCC-1701-D 8 crew members assigned. - Jean-Luc Picard (Captain) - Commanding Officer [Human] - William T. Riker (Commander) - First Officer [Human] - Beverly Crusher (Lieutenant Commander) - Chief Medical Officer [Human] - Geordi La Forge (Lieutenant) - Chief Engineering Officer [Human] - Deanna Troi (Lieutenant Commander) - Counselor [Betazoid] - Worf (Lieutenant) - Helmsman [Klingon] - Data (Lieutenant Commander) - Chief Operations Officer [Android] - Tasha Yar (Lieutenant) - Chief Security Officer [Human] USS Gibraltar, Sovereign. Registry: NCC-75689 0 crew members assigned.
CrewMember.java
This class will represent a CrewMember object, which we will define as having:
A name, represented as a String (e.g. James T. Kirk)
A position, (e.g. Commanding Officer)
A rank, (e.g. Captain)
A species (e.g. Human)
An assignment (e.g. NCC-1701-A)
Two constructors - one which requires all of the above fields, and one which requires all except for the assignment.
A toString() method which returns a String representation of the CrewMember
Getters and setters for all fields
Starship.java
This class will represent a Starship object, which we will define as having:
A name, represented as a String (e.g. USS Enterprise)
A registry, (e.g. NCC-1701-A)
A class of starship (e.g. Constitution)
An ArrayList of CrewMember objects
A constructor which requires all String fields and initializes the collection
A toString() method which returns a String representation of the Starship
An addCrewMember() method which takes a CrewMember parameter and adds them to the starship and returns nothing
A getNumberOfPersonnel() method which takes no parameters and returns an integer count of crew members on the starship
Getters and setters for all fields
Fleet.java
This class will represent a Fleet object, which we will define as having:
A name, represented as a String (e.g. United Federation of Planets)
An ArrayList of Starship objects
A constructor which requires all String fields and initializes the collection
A getSizeOfFleet() method which returns the number of starships in the fleet
An addStarship(..) method which takes a Starship parameter and adds it to the fleet, returning nothing.
A toString() method which calls upon the toString() in Starship to return a string representation of the fleet.
Getters and setters for all fields
A loadStarships() method which takes in a directory name and adds a Starship to the Fleet for each file found. This method should not return anything and needs to throw an exception in order to allow for file I/O. To do this you need only define your method as follows: public void loadStarships( String directoryName ) throws FileNotFoundException {
---------------
/** * Lab2 is a Java class containing a main method to run your program when completed. * This class will not compile until you have completed the requirements outlined in * the lab description. *
*/
public class Lab2 { public static void main( String[] args ) { Fleet unitedFederation = new Fleet( "United Federation of Planets" ); try { unitedFederation.loadStarships( "data" ); }catch( Exception e ) { // this is a try/catch which will show any errors to the console (more on these in coming weeks!) e.printStackTrace(); } System.out.println( unitedFederation ); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started