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

📄 store_alternatif.java

📁 This project developed in java leads us to realize a flight reservation system in order to emulate d
💻 JAVA
字号:
package reservation.system.functions;import reservation.system.Flight;import reservation.system.Pos;import reservation.system.Person;import java.io.PrintWriter;import java.io.FileWriter;import java.io.BufferedWriter;import java.io.File;import java.util.Vector;/** * This class hold Store structure. This object allows to save in a file the different command generating the content of the database. * @author Texier Mathieu and Frederic Bidon */public class Store_alternatif extends Functions{        /**Name of the file where we want to save the data.*/    private File datafile;        /**     * Verify invariants :     * <PRE>     * - Argument not null     * - The number of argument equals 1     * - File's name doesn't exist     * - The file can be created     * </PRE>     * @throws Exception if the file exists or cannot be created.     */        void _check (String[] arg) throws Exception {        CheckFlightListNotEmpty ();        ArgumentIsValid (arg, 1, 1);        File datafile = new File (arg[0]);        if (!datafile.exists ()) {            if (!datafile.createNewFile ())                throw new Exception ("Cannot create the file: " + datafile.getPath ());        } else            throw new Exception ("file " + datafile.getPath () + " already exist");                this.datafile = datafile;    }        /**     * Display the usage for the command <CODE>Save</code>.     * @return the usage.     */    static public String usage() {        String usage = " Usage command Save: save <fileName>\n\r";        usage += " - The <fileName> is the path to the file to be save \n\r";        usage +=" The file extention is .rcm .\n";        return usage;    }        /**     * Store in a file the different command generating the content of the database.     * @throws Exception if the file is not saved.     * @return a confimation's message if the file is saved.     */    public String execute () throws Exception {        String[] listFlight = fs.getFlightList ();        Integer[] listBooking = fs.getBookingList ();        Vector listPerson;        PrintWriter data =        new PrintWriter (new BufferedWriter (new FileWriter (datafile)));        for(int i = 0; i < listFlight.length; i++) {            Flight flight = fs.selectFlight (listFlight[i]);            String flightName = flight.getFlightName ();            Pos dim = flight.getDimension ();            short row = dim.getRow ();            short col = dim.getCol ();            String create = "create " + flightName + " " + row + " " + col;            data.println (create);        }                for (int j = 0; j < fs.getBookingNumberMax (); j++) {            listPerson = fs.identify (listBooking[j].intValue ());            String Passengers = " ";            Flight flightPerson = null;            Person personName = null;            for (int k = 0; k < listPerson.size (); k++) {                personName = (Person)listPerson.get (k);                Passengers += personName.getPersonName () + " ";                flightPerson = personName.getFlight ();            }            String reserve = "reserve " + flightPerson.getFlightName () + Passengers;            data.println (reserve);        }                data.close ();        return "File saved";    }}

⌨️ 快捷键说明

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