⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flightsystem.java

📁 This project developed in java leads us to realize a flight reservation system in order to emulate d
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        private PersonList personList;        private FlightSystem () {        flightList = new FlightSystem.FlightList ();        personList =  new FlightSystem.PersonList ();    }       /**    * Method which allows to atribute a place to a person.    * @throws Exception if the the flight doesn't exist.    * @return the position atribuated to a person.    */    private Pos[] getFreePlace (Flight flight, short number) throws Exception  {        Pos posList[] = new Pos[number];        short rest = number;        short count = 0;        Pos dimension = flight.getDimension ();        for (short row = 1; row <= dimension.getRow () && rest > 0; row ++) {            for (short col = 1; col <= dimension.getCol () && rest > 0; col++) {                Pos seat = new Pos (row,col);                Profile profile = new Profile ();                profile.setFlight (flight);                profile.setPos (seat);                if (!personList.contains (profile)) {                    posList[count++] = seat;                    rest --;                }            }        }        if (posList.length !=  number)            throw new Exception ("The place are not sucsesfully atribuated");        return posList;    }        /**     * The class hold the structure to access to the flights registered in the database.     * This object allows to modify the list of flight in the database.     * It contains all the methods accessing and altering the FlightList.     * @author Frederic Bidon and Mathieu Texier     */    private class FlightList extends LinkedList implements Serializable{        /**Constructor of the class*/        private FlightList () {            super ();        }               /**        * This method allows to obtain the flight(s) chosen.        * @throws Exception if the flight doesn't exist.        * @return a string containing the flight selected.        */        public Flight select (String flightName) throws Exception, CloneNotSupportedException {            Iterator it = iterator ();            while (it.hasNext () && flightName != null) {                Flight flight = (Flight) it.next ();                if (flightName.equals (flight.getFlightName ())) {                    flight._check ();                    return (Flight) flight.clone ();                }            }            return null;        }            /**     * Returns a string representation of this <CODE>FlightList</CODE> object. This method     * is intended to be used only for debugging purposes, and the content and format     * of the returned string may vary between implementations. The returned string may     * be empty but may not be <CODE>null</CODE>     * @return a string representation of this <CODE>FlightList</CODE> object.     */        public String toString () {            Iterator it = iterator ();            String resultList = "Flight List: " +"\r\n";            while (it.hasNext ()) {                resultList += "\t"+ (it.next ()).toString () +"\r\n";            }            return resultList;        }        /**     * This method allows to add a flight in the database.     * @throws an exception if the flight cannot be added.     * @return the flight added in the database.     */            public boolean add (Object o) {            boolean retValue;            if (o != null && o instanceof Flight) {                try {                    ((Flight) o)._check ();                } catch (Exception e) { System.err.println (e);}                if (retValue = true)                    retValue = super.add (o);            } else retValue = false;            return retValue;        }             /**        * This method allows to obtain the list of the flight(s) created.        * @throws Exception if the database contains no flight.        * @return an array of string containing the list of flight(s) created.        */        public String [] getFlightList () throws Exception {            Iterator it = iterator ();            String[] resultList =  new String[flightList.size ()];            for (int i=0; it.hasNext (); i++) {                Flight flight = (Flight) it.next ();                flight._check ();                resultList[i] = flight.getFlightName ();            }            return resultList;        }    }         /**     * The class hold the structure to access to the persons registered in the database.     * This object allows to modify the list of persons in the database.     * It contains all the methods accessing and altering the PersonList.     * @author Frederic Bidon and Mathieu Texier     */    private class PersonList extends LinkedList implements Serializable{        /**Constructor of the class*/        private PersonList () {            super ();        }               /**        * This method allows to obtain the person or the group of persons found in the PersonList.        * @throws Exception if the person or the group of persons doesn't exist.        * @return a string containing the person(s) selected.        */        public PersonList select (Profile profile) throws Exception{            PersonList groupePersonList = new PersonList ();            Iterator it = iterator ();            while (it.hasNext ()) {                Person person = (Person) it.next ();                if (person.equals (profile)) {                    person._check ();                    if (groupePersonList.add (person) == false)                        throw new Exception (person + " is not succesfully inserted in " +groupePersonList) ;                }            }            return groupePersonList;        }                /**         * Returns a string representation of this <CODE>PersonList</CODE> object. This method         * is intended to be used only for debugging purposes, and the content and format         * of the returned string may vary between implementations. The returned string may         * be empty but may not be <CODE>null</CODE>         * @return a string representation of this <CODE>PersonList</CODE> object.         */        public String toString () {            Iterator it = iterator ();            String resultList = "Person List: " +"\r\n";            while (it.hasNext ()) {                resultList += "\t"+ (it.next ()).toString () +"\r\n";            }            return resultList;        }                /**         * This method allows to add a person or a group of persons in the database.         * @throws an exception if the person or the group of persons cannot be added.         * @return the group of person added on a flight.         */        public boolean add (Object o) {            boolean retValue;            if (o != null && o instanceof Person && !(o instanceof Profile)) {                try {                    ((Person) o)._check ();                } catch (Exception e) { System.err.println (e);}                if (retValue = true)                    retValue = super.add (o);            } else retValue = false;            return retValue;        }                /**         * This method allows to remove all the persons belong to a same booking number.         * @return the collection of the persons removed.         */        public boolean removeAll (Collection c) {            boolean retValue;            if (!c.isEmpty ()) {                retValue = super.removeAll (c);            }            else retValue = false;            return retValue;        }                /**         * This method allows to remove one or more persons belong to a same booking number.         * @return the object of the persons removed.         */        public boolean remove (Object o) {            boolean retValue;            if (o != null && o instanceof Person) {                try {                    ((Person) o)._check ();                } catch (Exception e) { System.err.println (e);}                if (retValue = true)                    retValue = super.remove (o);            }            else retValue = false;            return retValue;        }              /**        * This method allows to obtain the list of the booking number.        * @throws Exception if the database contains no persons.        * @return an array of integer containing the list of the booking number atribuated.        */        public Integer [] getBookingtList () throws Exception {            Iterator it = personList.iterator ();            Set set = new HashSet ();            while (it.hasNext ()) {                Person person = (Person) it.next ();                person._check ();                set.add (new Integer (person.getBookingNumber ()));            }            return (Integer[]) set.toArray (new Integer[] {});        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -