212 lines
4.9 KiB
Java
212 lines
4.9 KiB
Java
/**
|
|
* <PRE>
|
|
* Aircraft.java
|
|
*
|
|
* Revisions: 1.0 Oct. 16, 2002
|
|
* Created the Aircraft class
|
|
* 1.1 Oct. 27, 2002
|
|
* Compiled, Commented
|
|
*
|
|
* </PRE>
|
|
*
|
|
* Collaboration Statement:
|
|
* I worked on the homework assignment alone, using only
|
|
* course materials.
|
|
*
|
|
* Created with JCreatorLE, some indents are off when viewed through notepad
|
|
* or EMACS
|
|
*
|
|
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
|
* @version Version 1.1, Oct. 27, 2002
|
|
*/
|
|
|
|
public class Aircraft implements Comparable{
|
|
|
|
//hey what happened to Hungarian Notation?
|
|
private String model ;
|
|
private String nickname ;
|
|
private String role ;
|
|
private Integer launchPriority;
|
|
|
|
private Comparable comparator = nickname;
|
|
|
|
////////////////
|
|
//Constructors//
|
|
////////////////
|
|
|
|
/**
|
|
*Constructor for Aircraft
|
|
*@param model, the model
|
|
*@param nickname, the nickname
|
|
*@param role, the role
|
|
*@param launchPriority, the launchPriority
|
|
*/
|
|
public Aircraft(String model, String nickname,
|
|
String role, Integer launchPriority){
|
|
this.model = model;
|
|
this.nickname = nickname;
|
|
this.comparator = nickname;
|
|
this.role = role;
|
|
this.launchPriority = launchPriority;
|
|
}
|
|
|
|
/**
|
|
*Constructor for Aircraft
|
|
*@param nickname, the nickname
|
|
*sets all other params to default
|
|
*/
|
|
public Aircraft(String nickname){
|
|
this("default",nickname,"default",new Integer(0));
|
|
}
|
|
|
|
/**
|
|
*Constructor for Aircraft
|
|
*@param model, the model
|
|
*@param nickname, the nickname
|
|
*@param role, the role
|
|
*@param launchPriority, the launchPriority
|
|
*/
|
|
public Aircraft(String model, String nickname,
|
|
String role, int launchPriority){
|
|
this(model,nickname,role,new Integer(launchPriority));
|
|
}
|
|
|
|
///////////////////////
|
|
//Accessors/Modifiers//
|
|
///////////////////////
|
|
|
|
/**
|
|
*Accessor for Model
|
|
*@return value of model
|
|
*/
|
|
public String getModel(){
|
|
return model;
|
|
}
|
|
|
|
/**
|
|
*Modifier for model
|
|
*@param the new value for model
|
|
*/
|
|
public void setModel(String model){
|
|
this.model = model;
|
|
}
|
|
|
|
/**
|
|
*Accessor for nickname
|
|
*@return the value of nickname
|
|
*/
|
|
public String getNickname(){
|
|
return nickname;
|
|
}
|
|
|
|
/**
|
|
*Modifier for nickname
|
|
*@param the new value of nickname
|
|
*/
|
|
public void setNickname(String nickname){
|
|
this.nickname = nickname;
|
|
this.comparator = nickname;
|
|
}
|
|
|
|
/**
|
|
*Accessor for role
|
|
*@return the role of the aircraft
|
|
*/
|
|
public String getRole(){
|
|
return role;
|
|
}
|
|
|
|
/**
|
|
*Modifier for role
|
|
*@param the new value for role
|
|
*/
|
|
public void setRole(String role){
|
|
this.role = role;
|
|
}
|
|
|
|
/**
|
|
*Accessor for launchPriority
|
|
*@return the value of launchPriority
|
|
*/
|
|
public Integer getLaunchPriority(){
|
|
return launchPriority;
|
|
}
|
|
|
|
/**
|
|
*Modifier for launchPriority
|
|
*@param the new value for launchPriority
|
|
*/
|
|
public void setLaunchPriority(Integer launchPriority){
|
|
this.launchPriority = launchPriority;
|
|
}
|
|
|
|
///////////
|
|
//Methods//
|
|
///////////
|
|
|
|
/**
|
|
*switches the comparators from the nickname to launchPriority
|
|
*/
|
|
public void switchComparators(){
|
|
if(comparator == nickname){
|
|
comparator = launchPriority;
|
|
}
|
|
else{//otherwise
|
|
comparator = nickname;
|
|
}
|
|
}
|
|
|
|
/**
|
|
*compareTo, returns >,<,or ==
|
|
*@param obj, the Object to compare with
|
|
*/
|
|
public int compareTo(Object obj){
|
|
if(!(obj instanceof Aircraft)){
|
|
return -5;
|
|
}
|
|
|
|
Aircraft temp = (Aircraft)obj;
|
|
|
|
if(comparator instanceof String && temp.comparator instanceof String){
|
|
return(comparator.compareTo(temp.comparator));
|
|
}
|
|
else if(comparator instanceof Integer &&
|
|
temp.comparator instanceof Integer)
|
|
{
|
|
return(comparator.compareTo(temp.comparator));
|
|
}
|
|
else{
|
|
System.err.println("Comparing apples and oranges doesn't work");
|
|
return -5;
|
|
}
|
|
}
|
|
|
|
/**
|
|
*@return String representation of Aircraft
|
|
*/
|
|
public String toString(){
|
|
return (model + " " + nickname + " of Type " + role + " with launch " +
|
|
"priority " + launchPriority);
|
|
}
|
|
|
|
/**
|
|
* Debugging main for class Aircraft.
|
|
* This method will rigorously test my code.
|
|
*
|
|
* <br><br>
|
|
* @param args a String array of command line arguments.
|
|
*/
|
|
public static void main(String[] args) {
|
|
Aircraft air = new Aircraft("F-14","Tomcat","Interceptor",8);
|
|
System.out.println(air);
|
|
|
|
System.out.println(air.compareTo(new Integer(8)));
|
|
System.out.println(air.compareTo(new Aircraft("Eagle")));
|
|
System.out.println(air.compareTo(air));
|
|
System.out.println(air.compareTo(new Aircraft("Zebra")));
|
|
|
|
|
|
}// end of main(String[] args)
|
|
|
|
}// end of class Aircraft
|