From af3a30011a34796c2275b1433b287d9b6a568328 Mon Sep 17 00:00:00 2001 From: YaFedImYaEatIm Date: Thu, 25 Aug 2016 15:37:58 +1200 Subject: [PATCH] Added Javadoc to Airport and configured a few variable types. --- .gitignore | 3 +- .../java/seng202/group9/Core/Airport.java | 194 +++++++++++++++--- 2 files changed, 163 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index f13a63f..2902811 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ target/ SENG202.iml .classpath .project -.settings/ \ No newline at end of file +.settings/ +doc/ \ No newline at end of file diff --git a/src/main/java/seng202/group9/Core/Airport.java b/src/main/java/seng202/group9/Core/Airport.java index 9f68171..8260a2c 100644 --- a/src/main/java/seng202/group9/Core/Airport.java +++ b/src/main/java/seng202/group9/Core/Airport.java @@ -2,6 +2,12 @@ package seng202.group9.Core; import java.util.ArrayList; +import seng202.group9.Controller.DataException; +/** + * Airport Class + * @author Fan-Wu Yang + * + */ public class Airport { private int ID; private String ICAO; @@ -9,12 +15,22 @@ public class Airport { private float altitude; private float longitude; private float latitude; - private City location; + private String location; private ArrayList departureRoutes = new ArrayList(); private ArrayList arrivalRoutes = new ArrayList(); + /** + * Constructor + * @param ID from the database + * @param ICAO + * @param IATA_FFA + * @param altitude + * @param longitude + * @param latitude + * @param location + */ public Airport(int ID, String ICAO, String IATA_FFA, float altitude, float longitude, - float latitude, City location){ + float latitude, String location){ this.ID = ID; this.ICAO = ICAO; this.IATA_FFA = IATA_FFA; @@ -23,89 +39,201 @@ public class Airport { this.latitude = latitude; this.location = location; } - + /** + * Secondary Constructor the ID needs to be set after. + * @param ICAO + * @param IATA_FFA + * @param altitude + * @param longitude + * @param latitude + * @param location + */ + public Airport(String ICAO, String IATA_FFA, float altitude, float longitude, + float latitude, String location){ + this.ID = -1; + this.ICAO = ICAO; + this.IATA_FFA = IATA_FFA; + this.altitude = altitude; + this.longitude = longitude; + this.latitude = latitude; + this.location = location; + } + /** + * returns the IATA/FFA code + * @return + */ public String getIATA_FFA() { return IATA_FFA; } - + /** + * sets the IATA/FFA code + * @param iATA_FFA + */ public void setIATA_FFA(String iATA_FFA) { IATA_FFA = iATA_FFA; } - + /** + * sets the database ID (Autoincremented) + * @param iD + */ public void setID(int iD) { ID = iD; } - + /** + * sets the ICAO Code + * @param iCAO + */ public void setICAO(String iCAO) { ICAO = iCAO; } - + /** + * sets the altitude of the airport + * @param altitude + */ public void setAltitude(float altitude) { this.altitude = altitude; } - + /** + * set longitude of the airport + * @param longitude + */ public void setLongitude(float longitude) { this.longitude = longitude; } - + /** + * set latitude of the airport + * @param latitude + */ public void setLatitude(float latitude) { this.latitude = latitude; } - - public void setLocation(City location) { + /** + * sets the coordinates of the place + * @param latitude + * @param longitude + */ + public void setCoordinates(float latitude, float longitude){ + this.latitude = latitude; + this.longitude = longitude; + } + /** + * sets the location of the airport (which city it is in) + * @param location + */ + public void setLocation(String location) { this.location = location; } - + /** + * set the routes that depart from it + * @param departureRoutes + */ public void setDepartureRoutes(ArrayList departureRoutes) { - this.departureRoutes = departureRoutes; - } - + //the array list must be clones else future errors may occur + this.departureRoutes = new ArrayList(); + for (int i = 0; i < departureRoutes.size(); i ++){ + this.departureRoutes.add(departureRoutes.get(i)); + } + } + /** + * sets the routes that arrive at this airport + * @param arrivalRoutes + */ public void setArrivalRoutes(ArrayList arrivalRoutes) { - this.arrivalRoutes = arrivalRoutes; - } - - public int getID(){ - return ID; - } - + //the array list must be clones else future errors may occur + this.arrivalRoutes = new ArrayList(); + for (int i = 0; i < departureRoutes.size(); i ++){ + this.arrivalRoutes.add(arrivalRoutes.get(i)); + } + } + /** + * gets the data auto-incremented database ID of the airport. + * if it is -1 it throws an not set data error + * @return + * @throws DataException + */ + public int getID() throws DataException{ + if (this.ID == -1){ + throw new DataException("ID not set."); + }else{ + return ID; + } + } + /** + * get the ICAO of the airport + * @return + */ public String getICAO(){ return ICAO; } - + /** + * gets the IATA/FFA of the airport + * @return + */ public String IATA_FFA(){ return IATA_FFA; } - + /** + * gets the altitude of the airport + * @return + */ public float getAltitude(){ return altitude; } - + /** + * gets the longitude of the airport + * @return + */ public float getLongitude(){ return longitude; } - + /** + * gets the latitude of the airport + * @return + */ public float getLatitude(){ return latitude; } - - public City getLocation(){ + /** + * gets the city the airport is located in + * @return + */ + public String getLocation(){ return location; } - + /** + * gets the routes that depart from this airport + * @return + */ public ArrayList getDepartureRoutes(){ return departureRoutes; } - + /** + * gets the routes that arrive at this airport + * @return + */ public ArrayList getArrivalRoutes(){ return arrivalRoutes; } - + /** + * adds departing routes to this airport + * @param route + */ public void addDepartureRoutes(Route route){ departureRoutes.add(route); } - + /** + * add arriving routes to this airport + * @param route + */ public void addArrivalRoutes(Route route){ arrivalRoutes.add(route); } - + /** + * Information of the airport returned in String format. + */ + @Override + public String toString(){ + return this.location+" Airport has ICAO: "+this.ICAO+", IATA/FFA: "+this.IATA_FFA+" and is located at ("+this.latitude+", "+this.longitude + + ").\n It has "+this.departureRoutes.size()+" departing routes and "+this.arrivalRoutes+" arriving routes."; + } }