Aircraftpublic class Aircraft extends Observable implements Runnable, SerializableThe Aircraft class represents an individual aircraft
in the simulated airspace.
Note: The Aircraft class is only accessible by objects that
are members of the gui2000 package.
- The call sign of the aircraft
- The position of the aircraft with respect to the centre of the
airspace. It is represented as two signed integer values:
- the number of metres EAST of the centre and
- the number of metres NORTH
Negative values represent distances WEST or SOUTH of the centre
of the airspace.
- The current heading of the aircraft. The heading is given in degrees
where a value of 0 means NORTH. Angles are measured colckwise from
NORTH, so EAST has a value of 90 degrees.
- The height of the aircraft - in feet
- The speed of the aircraft measured in kilometres/hour (kph)
|
Fields Summary |
---|
private String | callSign | int | east | int | north | private int | heading | int | height | private int | speed | private int | climbRate | private int | turnRate | private int | secToIncident | private String | newCallSign | private int | targetHeading | private int | targetHeight | private int | climbing | private int | turning | private boolean | running |
Constructors Summary |
---|
Aircraft(String callSign, int east, int north, int heading, int height, int speed, int climbRate, int turnRate, int secToIncident, String newCallSign)Create a new Aircraft object representing one
particular aircraft in the simulated airspace.
In general, these objects will be loaded from a datafile. this.callSign = callSign;
this.east = east;
this.heading = heading;
this.north = north;
this.height = height;
this.speed = speed;
this.climbRate = climbRate;
this.turnRate = turnRate;
this.secToIncident = secToIncident;
this.newCallSign = newCallSign;
|
Methods Summary |
---|
private void | changeHeading() heading += turning * turnRate;
if( heading < 0 )
{ heading += 360;
}
if( heading > 359 )
{ heading -= 360;
}
if( Math.abs( heading - targetHeading ) < turnRate )
{ heading = targetHeading;
turning = 0;
radio( "Turn completed - heading is " + heading + " degrees" );
}
| private void | changeHeight() height += climbing * climbRate;
if( Math.abs( height - targetHeight ) < climbRate )
{ height = targetHeight;
climbing = 0;
radio( "At new altitude of " + height + " feet" );
}
| public AircraftData | getData() // 1 = turn right, -1 = turn left
AircraftData d = new AircraftData();
d.callSign = callSign;
d.east = east;
d.north = north;
d.heading = heading;
d.flightLevel = height/100;
d.speed = speed;
return d;
| void | order(java.lang.String command)Parse, acknowledge and implement the command from air traffic control if( callSign.equals( "7600" ) ) return;
if( command.length() == 0 )
{ radio( "Missed your message" );
return;
}
StringTokenizer st = new StringTokenizer( command );
String replyString = null;
String theCommand = null;
String theValue = null;
int value = 0;
try
{ theCommand = st.nextToken();
theValue = st.nextToken();
value = Integer.parseInt(theValue.trim());
}
catch( Exception e )
{ radio( "Do not understand - please repeat" );
return;
}
if( theCommand.equals( "RIGHT" ) )
{ if( (value < 0) || (value > 359) )
{ radio( "Please repeat target bearing" );
return;
}
targetHeading = value;
turning = +1;
replyString = "Turning right to " + value + " degrees";
}
else if( theCommand.equals( "LEFT" ) )
{ if( (value < 0) || (value > 359) )
{ radio( "Please repeat target bearing" );
return;
}
targetHeading = value;
turning = -1;
replyString = "Turning left to " + value + " degrees";
}
else if( theCommand.equals( "CLIMB" ) )
{ if( value > 350 )
{ radio( "Sorry - I'm not a rocket can't get that high" +
"\n\tPlease re-send flight level" );
return;
}
if( value*100 < height )
{ radio( "Cannot comply, am currently at flight level " + height/100 );
return;
}
targetHeight = value*100;
climbing = +1;
replyString = "Climbing to flight level " + value;
}
else if( theCommand.equals( "DESCEND" ) )
{ if( value < 10 )
{ radio( "Isn't that rather low?" +
"\n\tPlease resend flight level" );
return;
}
if( value*100 > height )
{ radio( "Cannot comply, am currently at flight level " + height/100 );
return;
}
targetHeight = value*100;
climbing = -1;
replyString = "Descending to flight level " + value;
}
else
{ radio( "Do not understand - please repeat" );
return;
}
radio( "Wilco : " + replyString );
| void | radio(java.lang.String message) if( callSign.equals( "7600" ) ) return;
setChanged();
notifyObservers( message );
| public void | run()
int sec = 0;
while( running )
{ if( sec == secToIncident )
{ callSign = newCallSign;
}
if( turning != 0 )
{ changeHeading();
}
if( climbing != 0 )
{ changeHeight();
}
north += Math.round((10 * speed*1000/3600 * Math.cos( heading * Math.PI / 180 ))) / 10;
east += Math.round((10 * speed*1000/3600 * Math.sin( heading * Math.PI / 180 ))) / 10;
try
{ Thread.sleep(1000);
sec++;
}
catch( InterruptedException ie )
{}
}
| public java.lang.String | toString()Provided for debugging purposes return "Aircraft: " + callSign
+ "\tPosition: " + east + "E " + north + "N"
+ "\tHeading: " + heading
+ "\tHeight: " + height
+ "\tSpeed: " + speed;
|
|