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

📄 person.java

📁 This project developed in java leads us to realize a flight reservation system in order to emulate d
💻 JAVA
字号:
/* * Person.java * The package system contains the different class allowing to create and to select the object to store in the database. */package reservation.system;import java.io.Serializable;/** * This class hold person structure. This object could be asserted in the <CODE>PersonList</CODE>. * @author Texier Mathieu and Frederic Bidon */public class Person extends Object implements Cloneable, Serializable{    /**     * Construct an empty person     */    Person (){    }        /**     * Construct a <CODE>Person</CODE> named <CODE>personName</CODE> booked on the <CODE>flight</CODE> the seat <CODE>pos</CODE> and has the booking number : <CODE>bookingNumber</CODE>.     * @param personName Name of the person.     * @param flight Flight on witch the person has booked.     * @param bookingNumber used to {@link  reservation.system.functions.Identify} a group of person     * @param pos The position of the seat on the <CODE>flight</CODE>     * @throws Exception if the invariant _check() is violated     */    Person (    String personName,    Flight flight,    int bookingNumber,    Pos pos) throws Exception {        this.personName = personName;        this.flight = flight;        this.bookingNumber = new Integer (bookingNumber);        try {            this.pos = (Pos) pos.clone ();        } catch (CloneNotSupportedException e) {System.err.println (e);}        _check ();    }        /**     * Set the name of the person     * @param personName name of the person     * @throws Exception if the invariant _check() is violated     */    void setPersonName (String personName) throws Exception {        this.personName = personName;        _check ();    }        /**     * Set the flight     * @param flight Flight on witch the person has booked.     * @throws Exception if the invariant _check() is violated     */    void setFlight (Flight flight) throws Exception {        this.flight = (Flight) flight.clone ();        _check ();    }        /**     * Set the booking number     * @param bookingNumber the booking number     * @throws Exception if the invariant _check() is violated     */    void setBookingNumber (int bookingNumber) throws Exception {        this.bookingNumber = new Integer (bookingNumber);        _check ();    }        /**     * Set the position     * @param pos The position of the seat on the <CODE>flight</CODE>     * @throws Exception if the invariant _check() is violated     */    void setPos (Pos pos) throws Exception {        this.pos = (Pos) pos.clone ();        _check ();    }        /**     * Return the name of the person     * @return the name of the person     * @throws Exception if the invariant _check() is violated     */    final public String getPersonName () throws Exception {        return personName;    }        /**     * Return the flight     * @return the flight on witch the person has booked.     * @throws Exception if the invariant _check() is violated     */    final public Flight getFlight () throws Exception {        if (flight == null)            return null;        else            return (Flight) flight.clone ();    }        /**     * Return the booking number     * @return the booking number     * @throws Exception if the invariant _check() is violated     */    final public int getBookingNumber ()  throws Exception {        if (bookingNumber == null)            return 0;        return bookingNumber.intValue ();    }        /**     * Return the position of the seat     * @return pos the position of the seat in the <CODE>Flight</CODE>     * @throws Exception if the invariant _check() is violated     */    final public Pos getPos () throws Exception {        if (pos == null)            return null;        else            return (Pos) pos.clone ();    }        /**     * Returns a string representation of this <CODE>Person</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>Person</CODE> object.     */    public String toString () {        return personName +" has booked on "+ flight +" the seat "+ pos +" under the booking number : "+ bookingNumber + "\r\n";    }        /**     * Overide equals     * @return <CODE>true</CODE> if this object is the same as the obj argument or match a {@link  reservation.system.Profile} object;     * <CODE>false</CODE> otherwise     * @param anObject <CODE>anObject</CODE> - the reference object with which to compare     */    public boolean equals (Object anObject) {        if (anObject != null && anObject instanceof Profile) {            boolean bPersonName = false;            boolean bBookingNumber = false;            boolean bFlightName = false;            boolean bPos = false;            Profile profile = (Profile) anObject;            try {                if (personName.equals (profile.getPersonName ()) || profile.personNameIsMask ())                    bPersonName = true;                if (bookingNumber.intValue () == profile.getBookingNumber () || profile.bookingNumberIsMask ())                    bBookingNumber = true;                if (flight.equals (profile.getFlight ()) || profile.flightIsMask ())                    bFlightName = true;                if (pos.equals (profile.getPos ()) || profile.posIsMask ())                    bPos = true;            } catch (Exception  e){System.err.println (e);}            return bPersonName && bBookingNumber && bFlightName && bPos;        }        else if (anObject != null && anObject instanceof Person) {            Person person = (Person) anObject;            return (flight.equals (person.flight)            && (personName == person.personName)            && (bookingNumber == person.bookingNumber)            && (pos.equals (person.pos)));        }        else            return false;    }        /**     * Verify invariants :     <PRE>     - <CODE>regex</CODE> ^[A-Z][a-z]*     - seat < dimension of the flight and > 0     </PRE>     * @throws NullPointerException if pos or name is null     * @throws Exception if the invariant is violated     */    public void _check () throws Exception, NullPointerException {        if (flight == null || pos == null || personName == null ||  bookingNumber == null)            throw new NullPointerException ("The person "+ this +" has a null value.") ;               if (bookingNumber.intValue () < 1 || bookingNumber.intValue () > Integer.MAX_VALUE        || pos.getRow () < 1 || pos.getRow () > flight.getDimension ().getRow ()        || pos.getCol () < 1 || pos.getCol () > flight.getDimension ().getCol ()) {            throw new Exception ("The person "+ this +" has an out of range value.");        }                if (!personName.matches ("^[A-Z][a-z]*") || personName.equals (""))            throw new Exception ("The name : "+ personName +" has illegal character(s)\r\n" +            "Remember that the first letter of a name has to be in upper case and the rest in lower case " +            "and that no number or special characters are allowed");    }        /**     * Creates and returns a copy of this object.     * @return a copy of this <CODE>Person</CODE> object     * @throws CloneNotSupportedException if the object's class does not support the <CODE>Cloneable</CODE> interface.     */    protected Object clone () throws CloneNotSupportedException {        Person retPerson = null;        try {            retPerson = new Person (personName, flight, bookingNumber.intValue (), (Pos) pos.clone ());        } catch (Exception e){System.err.println (e);}        return retPerson;    }        private Flight flight = null;    private String personName = null;    private Integer bookingNumber = null;    private Pos pos = null;}

⌨️ 快捷键说明

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