Beispiel #1
0
        public void Add(string manufacturer, string model, int modelYear, double initPrice, int purchaseDate, double currentOdometer, double engineSize, double cargoCapacity, double towingCapacity)
        {
            Truck tr = new Truck(manufacturer, model, modelYear, initPrice, purchaseDate, currentOdometer, engineSize, cargoCapacity, towingCapacity);

            if (numTruck < 10)
            {
                list.Add(tr);
                numTruck++;
            }
            else
            {
                throw new Exception("Can not hold more small trucks");
            }
        }
Beispiel #2
0
        public void LoadDB(string path)
        {
            if (System.IO.File.Exists(path) == false)
            {
                // empty
            }
            else
            {

                System.IO.StreamReader read = new System.IO.StreamReader(path);
                string line = "";

                while (true)
                {
                    line = read.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    if (line[0] == 'A')
                    {
                        if (this.numAuto >= 10)
                        {
                            continue;
                        }

                        string[] words = line.Split('|');
                        int i = 1;

                        string manufacturer = "";
                        string model = "";
                        int modelYear = 0;
                        double initPrice = 0.0;
                        int purchaseDate = 0;
                        double currentOdometer = 0.0;
                        double engineSize = 0.0;
                        int doorNumber = 0;
                        string fuelType = "";

                        foreach (string str in words)
                        {
                            switch (i)
                            {
                                case 1:
                                    // do nothing
                                    break;
                                case 2:
                                    {
                                        manufacturer = str;
                                    }
                                    break;
                                case 3:
                                    {
                                        model = str;
                                    }
                                    break;
                                case 4:
                                    {
                                        modelYear = Convert.ToInt32(str);
                                    }
                                    break;
                                case 5:
                                    {
                                        initPrice = Convert.ToDouble(str);
                                    }
                                    break;
                                case 6:
                                    {
                                        purchaseDate = Convert.ToInt32(str);
                                    }
                                    break;
                                case 7:
                                    {
                                        currentOdometer = Convert.ToDouble(str);
                                    }
                                    break;
                                case 8:
                                    {
                                        engineSize = Convert.ToDouble(str);
                                    }
                                    break;
                                case 9:
                                    {
                                        doorNumber = Convert.ToInt32(str);
                                    }
                                    break;
                                case 10:
                                    {
                                        fuelType = str;
                                    }
                                    break;
                            }
                            i++;
                        }
                        Automobile auto = new Automobile(manufacturer, model, modelYear, initPrice, purchaseDate, currentOdometer, engineSize, doorNumber, fuelType);
                        list.Add(auto);
                        this.numAuto++;
                    }
                    else if (line[0] == 'T')
                    {
                        if (this.numTruck >= 10)
                        {
                            continue;
                        }

                        string[] words = line.Split('|');
                        int i = 1;

                        string manufacturer = "";
                        string model = "";
                        int modelYear = 0;
                        double initPrice = 0.0;
                        int purchaseDate = 0;
                        double currentOdometer = 0.0;
                        double engineSize = 0.0;
                        double cargoCapacity = 0.0;
                        double towingCapacity = 0.0;

                        foreach (string str in words)
                        {
                            switch (i)
                            {
                                case 1:
                                    // do nothing
                                    break;
                                case 2:
                                    {
                                        manufacturer = str;
                                    }
                                    break;
                                case 3:
                                    {
                                        model = str;
                                    }
                                    break;
                                case 4:
                                    {
                                        modelYear = Convert.ToInt32(str);
                                    }
                                    break;
                                case 5:
                                    {
                                        initPrice = Convert.ToDouble(str);
                                    }
                                    break;
                                case 6:
                                    {
                                        purchaseDate = Convert.ToInt32(str);
                                    }
                                    break;
                                case 7:
                                    {
                                        currentOdometer = Convert.ToDouble(str);
                                    }
                                    break;
                                case 8:
                                    {
                                        engineSize = Convert.ToDouble(str);
                                    }
                                    break;
                                case 9:
                                    {
                                        cargoCapacity = Convert.ToDouble(str);
                                    }
                                    break;
                                case 10:
                                    {
                                        towingCapacity = Convert.ToDouble(str);
                                    }
                                    break;
                            }
                            i++;
                        }
                        Truck tr = new Truck(manufacturer, model, modelYear, initPrice, purchaseDate, currentOdometer, engineSize, cargoCapacity, towingCapacity);
                        list.Add(tr);
                        this.numTruck++;
                    }
                    else if (line[0] == 'M')
                    {
                        if (this.numMoto >= 10)
                        {
                            continue;
                        }

                        string[] words = line.Split('|');
                        int i = 1;

                        string manufacturer = "";
                        string model = "";
                        int modelYear = 0;
                        double initPrice = 0.0;
                        int purchaseDate = 0;
                        double currentOdometer = 0.0;
                        double engineSize = 0.0;
                        string type = "";

                        foreach (string str in words)
                        {
                            switch (i)
                            {
                                case 1:
                                    // do nothing
                                    break;
                                case 2:
                                    {
                                        manufacturer = str;
                                    }
                                    break;
                                case 3:
                                    {
                                        model = str;
                                    }
                                    break;
                                case 4:
                                    {
                                        modelYear = Convert.ToInt32(str);
                                    }
                                    break;
                                case 5:
                                    {
                                        initPrice = Convert.ToDouble(str);
                                    }
                                    break;
                                case 6:
                                    {
                                        purchaseDate = Convert.ToInt32(str);
                                    }
                                    break;
                                case 7:
                                    {
                                        currentOdometer = Convert.ToDouble(str);
                                    }
                                    break;
                                case 8:
                                    {
                                        engineSize = Convert.ToDouble(str);
                                    }
                                    break;
                                case 9:
                                    {
                                        type = str;
                                    }
                                    break;
                            }
                            i++;
                        }
                        Motorcycle moto = new Motorcycle(manufacturer, model, modelYear, initPrice, purchaseDate, currentOdometer, engineSize, type);
                        list.Add(moto);
                        this.numMoto++;
                    }
                }
                read.Close();
            }
        }