Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Background Humankind is pushing out into space. New planets are being discovered and explored with a view to colonizing suitable planets. The agency tasked

Problem Background Humankind is pushing out into space. New planets are being discovered and explored with a view to colonizing suitable planets. The agency tasked with this somewhat momentous job is the Organization Of Finders, also referred to by its better known acronym, OOF. OOF is staffed by intrepid personnel known as Crew. Crew use vehicles known as Ferries to travel from their Base Ship, which is a space ship, down to a planet and back up to the space ship. When a Crew member first joins OOF, they have not been part of any missions, their skill level is recruit. A Crew member is also referred as a Crew. As a Crew member carries out more missions, their skill level increases. If the Crew has been on between 0 and 6 missions (inclusive), then their skill level is Recruit If the Crew has been on between 7 and 8 missions (inclusive), then their skill level is Trained If the Crew has been on between 9 and 14 missions (inclusive), then their skill level is Experienced If the Crew has been on 15, or more, missions, then their skill level is Expert To be assigned a mission, firstly, the Ferry must have a Crew and not be on a mission. Secondly, the skill level required for the mission must be within the skill level of the Crew. A Crew with a higher skill level can undertake a mission that requires a lesser skill level, but a Crew cannot undertake a mission that requires a higher skill level. The Crew must have the required skill level before being assigned the mission. Each time a Crew is assigned a mission, the number of missions they have been on is incremented by one. The program must then check if the Crew has accumulated enough missions to move to the next skill level. To end a mission, the Ferry must actually be on a mission. Program Requirements You have been asked to write an interactive program, in Java, to aid in monitoring and maintaining all aspects of Base Ship operations for OOF. This program is a prototype and there will be only 2 Ferry objects in the program. If the prototype proves successful, this will be expanded in the next iteration (The Progress Check Test assignment) Recall that a Ferry object also has an associated Crew object (when the Crew object is assigned).

To aid in the rapid development of this program, 3 Java files and 3 sample input files are provided for you: Crew.java, Ferry.java, SpaceShip.java and sample input files a1.dat, b1.dat and c1.dat Copy them from the unit library area into your current directory using: cp /home/1st/csilib/cse1oof/assignC/* .

In order to further speed up the development of this program, some of the files listed above have been partially implemented for you, read the comments in the files and in this document.

Crew.java All Crew objects have the following object attributes:

name This a String (text) and is the name of the Crew, may be more than one word

Crew id This a String (text) and is the unique id of the Crew, may be more than one word

missions This is an integer and is the number of missions that the Crew has participated in.(See the explanation below)

skill level This is a String and is one of the four skill levels, as described above. The skill level is always based on the number of missions that the Crew has participated in, and must be set by the program. The user must NEVER be able to enter the skill level, nor is it ever stored in a file. The skill level is also known as the task level. Any references to task level in this document are the same as skill level. The Crew class requires the following functionality: A constructor that takes name, Crew id, and missions as parameters. This is the constructor that is called when a new Crew is added from the text file. From the file, all three of these parameters have values. The format of the text file is shown on pages 8 - 9 Recall that it is the number of missions that determines the skill level, so there has to be a way for the constructor to set the skill level. If this constructor is also used for keyboard input, then the number of missions must be set to 0 as the Crew has just been created.

Alternatively, you could write an overloaded constructor, just for use with the keyboard, this just takes the first two values (name and Crew id) as parameters and assigns 0 to the number of missions. Either way, the skill level must be set by the constructor, not the user. This is where you write a private helper method in the Crew class. The Crew class also requires accessor methods as you deem appropriate. The Crew class also requires a method to increment the number of missions. Calling this method adds another mission to the total number of missions. This method should then check whether that moves the Crew to the next skill level. Finally the Crew class requires a toString method which returns a String with information about the Crew object, see pages 14 and 16 for the format of the String to be returned. Please note that the output must follow the format exactly, this will be assigned marks in the execution test.

Ferry.java The Ferry class has the following attributes:

ferry id This is a String (text) and may consist of more than one word The Ferry id is the unique identifier for a Ferry.

on mission This is a boolean variable, the value false indicates that the Ferry is NOT on a mission. The value true indicates that the Ferry is on a mission.

crew This is the Crew class object reference for the Crew object that is associated with this Ferry (when the Crew object is added and instantiated)

The Ferry class requires 2 overloaded constructors. The first overloaded constructor takes just the Ferry id for a Ferry object. This constructor is called when adding a Ferry object from the keyboard. The Ferry cannot be on a mission as it has just been created and, for the same reason, it cannot have a Crew object associated with it. The second overloaded constructor is for creating a Ferry object from the input text file. In the text file there will be the Ferry id, number of missions worked and a boolean value to indicate whether or not the Ferry is currently on a mission. There will also always be another boolean, directly after this on mission boolean value. If this has the value true, then it indicates there is information for the Crew object associated with this Ferry. This will consist of the Crew's Crew id, name and the number of missions that they have worked. If the boolean is false, then there is no Crew associated with this Ferry. See pages 8 and 9 for the file format. The Ferry class must never have a Crew object reference as a parameter in any of its methods, including the constructor(s). Even when reading from the file, if there is a Crew associated with the Ferry, then the Crew's name, id and the number of missions they have worked will have been read out after the Ferry object is created. Then that Ferry's addCrew method will be called. The addCrew method will take all three Crew parameters. The Ferry class will require accessor methods as you deem appropriate. The Ferry class also requires a toString method that returns a String with information about the state of that Ferry object. The format of the String is shown in the example output. As with the Crew screen output, you must follow the format shown exactly, marks will be assigned to following the format. The Ferry class requires a method to add a Crew to the Ferry. (This was discussed above) This method takes all of the relevant parameters for instantiating a Crew object (but doesn't pass in a Crew object reference). The resultant object is stored in the Crew object reference. Each Ferry can have only one Crew. When adding from the keyboard, the program needs to check that the Ferry object does not already have a Crew object. This method is called when the user attempts to add a Crew from the keyboard or from the file. The Ferry also needs methods to start and end a mission. Recall that when all the conditions are met and a mission is assigned to a Ferry, the number of missions for the associated Crew has to be incremented. Starting a mission sets the on mission attribute of the Ferry to true and ending a mission sets this attribute to false. The skill level attribute is private to the Crew class, so it cannot be called directly from the Ferry class. All interactions (message passing) between the Ferry and Crew classes must be through the public methods of the Crew class. If the skill level attribute can be set directly from the Ferry class, or any other attributes of the Crew class can be directly access from the Ferry class, the whole assignment will be awarded 0, regardless of the functionality of the program. The Ferry class could also use a method that takes the required skill level of the mission as a parameter and returns true or false as to whether the associated Crew has the required skill level. Note that this is could also be done in the main driver class, SpaceShip, which is described below. You might find it useful to write a method in the Ferry class that returns a boolean to indicate if the Ferry already has a Crew or not, and another one to indicate if the Ferry is on a mission or not.

The driver program, SpaceShip.java starts by presenting the user with a menu, as follows:

OOF Planetary Explorer Main menu

1. Load from file

2. Add Ferry

3. Start Mission

4. End Mission

5. Display

6. Add Crew

7. Close the program

Enter choice >>

The Crew and Ferry classes do NOT ask the user for any input, either keyboard or file. There must not be any input objects in these classes such as Scanner or BufferedReader but not limited to these 2. Another way of saying this is that these classes are not interactive. Note: SpaceShip class must NOT have Crew object attribute(s) or Crew object references. All interactions involving a Crew will be through the relevant Ferry object

Crew.Java and Ferry.Java is empty

import java.io.File;

import java.io.IOException;

import java.util.Scanner;

public class SpaceShip

{

private Scanner kb;

private Ferry ferry1;

private Ferry ferry2;

private final int LOAD_FROM_FILE = 1;

private final int ADD_FERRY = 2;

private final int START_MISSION = 3;

private final int END_MISSION = 4;

private final int DISPLAY = 5;

private final int ADD_CREW = 6;

private final int EXIT = 7;

public static void main( String [ ] args ) throws IOException

{

SpaceShip sp = new SpaceShip( );

sp.run( );

}

public SpaceShip( )

{

kb = new Scanner( System.in );

ferry1 = null;

ferry2 = null;

}

public void run( ) throws IOException

{

int choice = -1;

while( choice != EXIT )

{

displayMenu( );

System.out.print("Enter choice >> " );

choice = kb.nextInt( );

kb.nextLine( );

process( choice );

}

}

void displayMenu( )

{

System.out.println(" OOF Planetary Explorer Main menu" );

System.out.println("\t" + LOAD_FROM_FILE + ". Load from file " );

System.out.println("\t" + ADD_FERRY + ". Add Ferry " );

System.out.println("\t" + START_MISSION + ". Start Mission" );

System.out.println("\t" + END_MISSION + ". End Mission" );

System.out.println("\t" + DISPLAY + ". Display" );

System.out.println("\t" + ADD_CREW + ". Add Crew" );

System.out.println("\t" + EXIT + ". Close the program" );

}

void process( int choice ) throws IOException

{

switch( choice )

{

case LOAD_FROM_FILE :

load( );

break;

case ADD_FERRY :

addFerry( );

break;

case START_MISSION :

startMission( );

break;

case END_MISSION :

endMission( );

break;

case DISPLAY :

display( );

break;

case ADD_CREW :

addCrew( );

break;

case EXIT :

// just trap this choice so that it doesn't appear

// as an invalid choice when the user slects it

// from the menu

break;

default:

System.out.println( choice + " is not a valid choice " );

break;

}

}

private void addFerry( )

{

}

public void display( )

{

}

// Since we need to check if there is at least one actual Ferry object

// in almost every method, let's write a method that returns

// true or false and just call that method, rather than repeat code.

//

// Given that we always assign an actual Ferry object to ferry1 first,

// we only need to check ferry1. This method is complete, you

// do not have to use this method if you don't want to.

//

private boolean hasFerry( )

{

return ferry1 != null;

}

public void addCrew( )

{

}

public void startMission( )

{

}

private void endMission( )

{

}

public void load( ) throws IOException

{

}

}

a1.dat

A 09 D54

false

false

b1.dat

A 04 S23

true

true

Carl Ton

A 01

6

A 10-N23

false

true

Mel A Born

A 02

14

c1.dat

C33 7

false

false

D 45 ERT

false

true

Oof Ness

B 12

3

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

Data Visualization A Practical Introduction

Authors: Kieran Healy

1st Edition

0691181624, 978-0691181622

More Books

Students also viewed these Databases questions