Question: 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
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.java
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 ); } }
MISSING THE public void loadStarships( String directoryName ) throws FileNotFoundException { IN THE FLEET.JAVA NEED HELP
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
