public List <AircraftObj> parse() { String readingText; An_2 an_2 = new An_2(); Boeing_747 boeing_747 = new Boeing_747(); Il_86 il_86 = new Il_86(); An_124_100 an_124_100 = new An_124_100(); Boeing_727_100C boeing_727_100C = new Boeing_727_100C(); List <AircraftObj> aircrafts = new List <AircraftObj>(); try { using (StreamReader sr = new StreamReader(TEXT_FILE_NAME)) { while (!sr.EndOfStream) { readingText = sr.ReadLine(); switch (readingText) { case "An-2": an_2 = readAn2(sr); aircrafts.Add(new An_2(an_2.ManufactureYear, an_2.ID1, an_2.AircraftWeight, an_2.FuelReserve, an_2.AverarageRage, an_2.HumanCapacity, an_2.CargoCapacity, an_2.ModelName, an_2.FuelConsumption)); break; case "Boeing-747": boeing_747 = readBoeing_747(sr); aircrafts.Add(new Boeing_747(boeing_747.ManufactureYear, boeing_747.ID1, boeing_747.AircraftWeight, boeing_747.FuelReserve, boeing_747.AverarageRage, boeing_747.HumanCapacity, boeing_747.CargoCapacity, boeing_747.ModelName, boeing_747.FuelConsumption)); break; case "Il-86": il_86 = readIl86(sr); aircrafts.Add(new Il_86(il_86.ManufactureYear, il_86.ID1, il_86.AircraftWeight, il_86.FuelReserve, il_86.AverarageRage, il_86.HumanCapacity, il_86.CargoCapacity, il_86.ModelName, il_86.FuelConsumption)); break; case "An-124-100": an_124_100 = readAn124(sr); aircrafts.Add(new An_124_100(an_124_100.ManufactureYear, an_124_100.ID1, an_124_100.AircraftWeight, an_124_100.FuelReserve, an_124_100.AverarageRage, an_124_100.CargoCapacity, an_124_100.ModelName, an_124_100.FuelConsumption)); break; case "Boeing-727-100C": boeing_727_100C = readBoeing_727_100(sr); aircrafts.Add(new Boeing_727_100C(boeing_727_100C.ManufactureYear, boeing_727_100C.ID1, boeing_727_100C.AircraftWeight, boeing_727_100C.FuelReserve, boeing_727_100C.AverarageRage, boeing_727_100C.CargoCapacity, boeing_727_100C.ModelName, boeing_727_100C.FuelConsumption)); break; } } } } catch (Exception e) { Console.WriteLine("The file could not be read: " + e.ToString()); } return(aircrafts); }
private An_2 readAn2(StreamReader sr) { An_2 an_2 = new An_2(); for (;;) { String buffer = sr.ReadLine(); if (buffer.IndexOf(":") > 0) { string[] mbuff = buffer.Split(':'); switch (mbuff[0]) { case "modelName": an_2.ModelName = mbuff[1]; break; case "manufactureYear": an_2.ManufactureYear = Convert.ToInt32(mbuff[1]); break; case "ID": an_2.ID1 = mbuff[1]; break; case "aircraftWeight": an_2.AircraftWeight = Convert.ToInt32(mbuff[1]); break; case "fuelReserve": an_2.FuelReserve = Convert.ToInt32(mbuff[1]); break; case "fuelConsumption": an_2.FuelConsumption = Convert.ToInt32(mbuff[1]); break; case "averarageRage": an_2.AverarageRage = Convert.ToInt32(mbuff[1]); break; case "humanCapacity": an_2.HumanCapacity = Convert.ToInt32(mbuff[1]); break; case "cargoCapacity": an_2.CargoCapacity = Convert.ToInt32(mbuff[1]); break; } } else { return(an_2); } } }