Question

Problem Background Managing the operations of the air group on an aircraft carrier is a complex and dangerous task. These carrier operations involve launching and landing (recovering) aircraft. Aircra...

Problem Background

Managing the operations of the air group on an aircraft carrier is a complex and dangerous task.

These carrier operations involve launching and landing (recovering) aircraft.

Aircraft require an Aircrew. The Aircrew accumulate experience as they conduct more missions.

Missions require a certain level of expertise. This expertise is known as the status of the Aircrew.

When an aircraft is first created, it is placed on the carrier flight deck. An Aircrew will (can) be

created and assigned to an aircraft at a later time. An aircraft can exist without an Aircrew, but an

Aircrew cannot exist without an aircraft.

When an Aircrew first joins the carrier, they have no experience and their status level is Rookie.

As an Aircrew carries out more missions, their status level increases.

If the Aircrew has been on between 0 and 5 missions (inclusive),

then their status level is Rookie

If the Aircrew has been on between 6 and 10 missions (inclusive),

then their status level is Trained

If the Aircrew has been on between 11 and 16 missions (inclusive),

then their status level is Veteran

If the Aircrew has been on more than 16 missions,

then their status level is Ace pilot

To be launched on a mission, firstly the Aircraft must be on the deck (not currently on a mission),

the aircraft must have an aircrew and that aircrew must have at least the required status level.

An Aircrew with a higher status level can undertake a mission that requires a lesser status level,

but an Aircrew cannot undertake a mission that requires a higher status level.

The Aircrew must have the required status level before being assigned the mission.

Each time an Aircrew is assigned a mission (the aircraft is launched), the number of missions

they have been on is incremented by one. The program must then check if the Aircrew has

accumulated enough missions to move to the next status level.

To end a mission (the aircraft is recovered onto the deck), the aircraft must actually be on a

mission, that is, airborne

Program Requirements

You have been asked to write an interactive program, in Java, to aid in monitoring and maintaining

all aspects of Carrier air group operations.

This program is a prototype and there will be only 2 Aircraft objects in the program. If the prototype

proves successful, this will be expanded in the next iteration (The Progress Check Test

assignment)

Recall that an Aircraft object also has an associated Aircrew object (when the Aircrew object is

assigned).

Aircrew.java

All Aircrew objects have the following object attributes:

- name : This is a String (text) and is the name of the Aircrew, may be more

than one word

- call sign : This is a String (text) and is the unique call sign of the Aircrew, may be

more than one word

- missions : This is an integer and is the number of missions that the Aircrew

has participated in.(See the explanation below)

- status : This is a String and is one of the four status levels, as described above. The

status level is always based on the number of missions that the Aircrew

has participated in, and must be set by the program.

The user must NEVER be able to enter the status level, nor is it ever

stored in a file.

The Aircrew class requires the following functionality:

A constructor that takes name, call sign, and missions as parameters. This is the constructor

that is called when a new Aircrew 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 11 and 12

Recall that it is the number of missions that determines the status, so there has to be a way

for the constructor to set the status. If this constructor is also used for keyboard input, then the

number of missions must be set to 0 as the Aircrew 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 call sign) as parameters and assigns 0 to the number of

missions.

Either way, the status must be set by the constructor, not the user.

This is where you write a private helper method in the Aircrew class, similar to the

setCategory method in lab 7. Call it setStatus( ) for example.

The Aircrew class also requires accessor methods as you deem appropriate.

The Aircrew 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 Aircrew to the next status.

Finally the Aircrew class requires a toString method which returns a String with

information about the Aircrew object

Aircraft.java

The Aircraft class has the following attributes:

- tail code : This is a String (text) and may consist of more than one word

The tail code is the unique identifier for a Aircraft.

- status : This is a String (text). It has one of 2 values, either "on deck"

or "airborne". "on deck" indicates that the Aircraft is not on a

mission, "airborne" indicates that the Aircraft is on a mission.

- crew : This is the Aircrew class object reference for the Aircrew object that

is associated with this Aircraft

(when the Aircrew object is added and instantiated)

The Aircraft class requires 2 overloaded constructors.

The first overloaded constructor takes just the tail code for an Aircraft object. This

constructor is called when adding an Aircraft object from the keyboard. The Aircraft

cannot be on a mission as it has just been created and, for the same reason, it cannot have an

Aircrew object associated with it.

The second overloaded constructor is for creating an Aircraft object from the input text file.

In the text file there will be the tail code and a String, the status, which will be either

"on deck" or "airborne", indicating whether or not the Aircraft is currently on a mission.

There will also always be an integer, directly after this status String value. If this has the

value 1, then it indicates there is information for the Aircrew object associated with this

Aircraft. This will consist of the Aircrew's call sign, name and the number of

missions that they have flown. If the number is 0, then there is no Aircrew associated with

this Aircraft. See pages 11 and 12 for the file format.

The Aircraft class must never have an Aircrew object reference as a parameter in any of

its methods, including the constructor(s). Even when reading from the file, if there is an

Aircrew associated with the Aircraft, then the Aircrew's call sign, name and the

number of missions they have flown will have been read out after the Aircraft object is

created. Then that Aircraft's addAircrew method will be called. The addAircrew

method will take all three Aircrew parameters.

This addAircrew method can be overloaded for adding an Aircrew from the keyboard. When

an Aircrew is first created from the keyboard, the number of missions they have flown must be

0.

In both addAircrew methods, the parameters are the individual components of an Aircrew,

never an Aircrew object. Marks will be deducted for not following this instruction.

The Aircraft class will require accessor methods as you deem appropriate.

The Aircraft class also requires a toString method that returns a String with information

about the state of that Aircraft object. The format of the String is shown in the example

output on page 15. As with the Aircrew screen output, you must follow the format shown

exactly, marks will be assigned to following the format.

The Aircraft also needs methods to start (launch) and end (recover/land) a mission. Recall

that when all the conditions are met and a mission is assigned to an Aircraft, the number of

missions for the associated Aircrew has to be incremented. Starting a mission sets the

status attribute of the Aircraft to "airborne" and ending a mission sets this attribute to

"on deck".

The status attribute, of the Aircrew class, is private to the Aircrew class, so it cannot be

called directly from the Aircraft class. All interactions (message passing) between the

Aircraft and Aircrew classes must be through the public methods of the Aircrew class.

If the status level attribute can be set directly from the Aircraft or Carrier classes, or any

other attributes of the Aircrew class can be directly access from the Aircraft or Carrier

classes, the whole assignment will be awarded 0, regardless of the functionality of the

program.

The Aircraft class could also use a method that takes the required status of the mission as

a parameter and returns true or false as to whether the associated Aircrew has the

required status. Note that this is could also be done in the main driver class, Carrier, which

is described below.

You might find it useful to write a method in the Aircraft class that returns a boolean to

indicate if the Aircraft already has an Aircrew or not, and another one to indicate if the

Aircraft is on a mission or not (on the deck or airborne.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

###################### Aircrew.java ###################
/**
* The Class Aircrew.
*/
public class Aircrew {

   /** The name. */
   private String name;
  
   /** The call sign. */
   private String callSign;
  
   /** The mission. */
   private int mission;
  
   /** The status. */
   private String status;

   /**
   * Instantiates a new aircrew.
   *
   * @param name the name
   * @param callSign the call sign
   * @param mission the mission
   */
   public Aircrew(String name, String callSign, int mission) {
       this.name = name;
       this.callSign = callSign;
       this.mission = mission;
       setStatus();
   }

   /**
   * Instantiates a new aircrew.
   *
   * @param name the name
   * @param callSign the call sign
   */
   public Aircrew(String name, String callSign) {
       this.name = name;
       this.callSign = callSign;
       this.mission = 0;
       setStatus();
   }

   /**
   * Gets the name.
   *
   * @return the name
   */
   public String getName() {
       return name;
   }

   /**
   * Sets the name.
   *
   * @param name the name to set
   */
   public void setName(String name) {
       this.name = name;
   }

   /**
   * Gets the call sign.
   *
   * @return the callSign
   */
   public String getCallSign() {
       return callSign;
   }

   /**
   * Sets the call sign.
   *
   * @param callSign the callSign to set
   */
   public void setCallSign(String callSign) {
       this.callSign = callSign;
   }

   /**
   * Gets the mission.
   *
   * @return the mission
   */
   public int getMission() {
       return mission;
   }

   /**
   * Sets the mission.
   */
   public void setMission() {
       this.mission++;
       setStatus();
   }

   /**
   * Gets the status.
   *
   * @return the status
   */
   public String getStatus() {
       return status;
   }

   /**
   * Sets the status.
   */
   public void setStatus() {
       if (mission >= 0 && mission <= 5) {
           this.status = "Rookie";
       }
       else if (mission >= 6 && mission <= 10) {
           this.status = "Trained";
       }
       else if (mission >= 11 && mission <= 16) {
           this.status = "Veteran";
       }
       else if (mission > 16) {
           this.status = "Ace pilot";
       }
   }

   @Override
   public String toString() {
       return String.format("Aircrew:%n Name: %s%n Call Sign: %s%n Missions: %s%n Status: %s", name, callSign, mission, status);
   }

}

########################### Aircraft.java ####################
/**
* The Class Aircraft.
*/
public class Aircraft {

   /** The tail code. */
   private String tailCode;
  
   /** The status. */
   private String status;
  
   /** The crew. */
   private Aircrew crew;

   /**
   * Instantiates a new aircraft.
   *
   * @param tailCode the tail code
   */
   public Aircraft(String tailCode) {
       this.tailCode = tailCode;
       this.status = "on deck";
   }

   /**
   * Instantiates a new aircraft.
   *
   * @param tailCode the tail code
   * @param status the status
   */
   public Aircraft(String tailCode, String status) {
       this.tailCode = tailCode;
       this.status = status;
   }

   /**
   * Adds the crew.
   *
   * @param callSign the call sign
   * @param name the name
   * @param mission the mission
   */
   public void addCrew(String callSign, String name, int mission) {
       this.crew = new Aircrew(name, callSign, mission);
   }

   /**
   * Adds the crew.
   *
   * @param callSign the call sign
   * @param name the name
   */
   public void addCrew(String callSign, String name) {
       this.crew = new Aircrew(name, callSign);
   }

   /**
   * Gets the tail code.
   *
   * @return the tailCode
   */
   public String getTailCode() {
       return tailCode;
   }

   /**
   * Sets the tail code.
   *
   * @param tailCode the tailCode to set
   */
   public void setTailCode(String tailCode) {
       this.tailCode = tailCode;
   }

   /**
   * Gets the status.
   *
   * @return the status
   */
   public String getStatus() {
       return status;
   }

   /**
   * Sets the status.
   *
   * @param status the status to set
   */
   public void setStatus(String status) {
       this.status = status;
   }

   /**
   * Gets the crew.
   *
   * @return the crew
   */
   public Aircrew getCrew() {
       return crew;
   }

   /**
   * Sets the crew.
   *
   * @param crew the crew to set
   */
   public void setCrew(Aircrew crew) {
       this.crew = crew;
   }

   /**
   * Start.
   */
   public void start() {
       System.out.println("Mission started.....");
       setStatus("airborne");
       crew.setMission();
   }

   /**
   * End.
   */
   public void end() {
       System.out.println("Mission ended....");
       setStatus("on deck");
   }

   /**
   * Check crew status.
   *
   * @param status the status
   * @return true, if successful
   */
   public boolean checkCrewStatus(String status) {
       if (status.equalsIgnoreCase(crew.getStatus())) {
           return true;
       }
       return false;
   }

   /**
   * Check crew availablity in aircraft.
   *
   * @return true, if successful
   */
   public boolean checkCrewAvailablityInAircraft() {
       if (crew != null) {
           return true;
       }
       return false;
   }

   @Override
   public String toString() {
       return String.format("Aircraft:%n Tail Code: %s%n Status: %s%n%s", tailCode, status, crew != null ? crew.toString() : "");
   }

}

###################### MainDriver.java ###############

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

/**
* The Class MainDriver.
*/
public class MainDriver {

   /**
   * The main method.
   *
   * @param args the arguments
   */
   public static void main(String[] args) {
       readFromFile();
       readFromKeyBoard();
   }

   /**
   * Read from key board.
   */
   private static void readFromKeyBoard() {
       Scanner scan = new Scanner(System.in);
       int n = 0;
       Aircraft aircraft = null;
       do {
           System.out.println("1. Add aircraft");
           System.out.println("2. Add crew");
           System.out.println("3. Show Aircaft detail");
           System.out.println("4. Start mission");
           System.out.println("5. Stop mission");
           System.out.println("6. Exit");
           System.out.println("Enter your selection");
           n = scan.nextInt();
           switch (n) {
           case 1:
               System.out.println("Enter tail code: ");
               String tailCode = scan.next();
               aircraft = new Aircraft(tailCode);
               break;
           case 2:
               System.out.println("Enter Call sign: ");
               String callSign = scan.next();
               System.out.println("Enter name:");
               String name = scan.nextLine();
               aircraft.addCrew(callSign, name);
               break;
           case 3:
               System.out.println(aircraft.toString());
               break;
           case 4:
               aircraft.start();
               break;
           case 5:
               aircraft.end();
               break;
           case 6:
               System.out.println("Program ended...");
               break;

           }
       } while (n != 6);
       scan.close();
   }

   /**
   * Read from file.
   */
   private static void readFromFile() {
       Aircraft aircraft = addAirCraftDetails("aircraft.txt");
       System.out.println(aircraft.toString());
       aircraft.start();
       System.out.println(aircraft.toString());
       aircraft.end();
   }

   /**
   * Adds the air craft details.
   *
   * @param fileName the file name
   * @return the aircraft
   */
   private static Aircraft addAirCraftDetails(String fileName) {
       Aircraft aircraft = null;
       try {
           FileReader fr = new FileReader(fileName);
           BufferedReader br = new BufferedReader(fr);
           String line = null;
           while ((line = br.readLine()) != null) {
               String[] data = line.split(",");
               String tailCode = data[0];
               String status = data[1];
               aircraft = new Aircraft(tailCode, status);
               if (Integer.parseInt(data[2]) == 1) {
                   String name = data[3];
                   String callSign = data[4];
                   int mission = Integer.parseInt(data[5]);
                   aircraft.addCrew(callSign, name, mission);
               }
           }
           fr.close();
           br.close();
       }
       catch (IOException e) {
           e.printStackTrace();
       }
       return aircraft;
   }
}


########## aircraft.txt ##############
AT0X093,on deck,1,Samuel Win,Wing Commander,8

terminated Aircraft: MainDriver [Java ApplicationC Tail Code: ATexe93 Status: on deck Aircrew: Name: Samuel Win Call Sign: Wi

Add a comment
Know the answer?
Add Answer to:
Problem Background Managing the operations of the air group on an aircraft carrier is a complex and dangerous task. These carrier operations involve launching and landing (recovering) aircraft. Aircra...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT