示例#1
0
        public void parseOutput()
        {
            try
            {
                string line;
                StreamReader file = new StreamReader(this.filePath);

                while ((line = file.ReadLine()) != null)
                {
                    string[] parameters = line.Split('|');
                    string[] interstates = parameters[3].Split(';');
                    City city = new City(Int32.Parse(parameters[0]),
                                         parameters[1], parameters[2]);

                    foreach (string interstate in interstates)
                    {
                        Interstate newInterstate = new Interstate(interstate);
                        city.addInterstate(newInterstate);

                        if (!this.output2.Exists(x => x.Name == interstate))
                        {
                            this.output2.Add(newInterstate);
                        }
                        else
                        {
                            int interstateIndex = this.output2.FindIndex(i => i.Name == interstate);
                            this.output2[interstateIndex].incCitiesRun();
                        }
                    }
                    this.output1.Add(city);
                }
                this.output1 = this.output1.OrderByDescending(c => c.Population).ToList();
                this.output2 = this.output2.OrderBy(i => i.Number).ToList();
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Error #1: " + e.Message);
            }
        }
示例#2
0
 public void addInterstate(Interstate newInterstate)
 {
     this.interstates.Add(newInterstate);
 }