Esempio n. 1
0
        //This is the readin function form the lab
        static List <Item> ReadIn()
        {
            string[] data = File.ReadAllLines("Data.txt");
            Console.ReadLine();

            List <Item> Items = new List <Item>();

            for (int i = 0; i < data.Length; i++)
            {
                if (data[i] == "CPU")
                {
                    int      index = i + 1;
                    string[] bits;

                    do
                    {
                        bits = data[index].Split(',');
                        CPU c = new CPU(bits[0], double.Parse(bits[2]), int.Parse(bits[1]));
                        Items.Add(c);
                        index++;

                        if (index == data.Length)
                        {
                            break;
                        }
                    }while (data[index].Split(',').Length > 1);
                }

                if (data[i].ToUpper() == "MotherBoard".ToUpper())
                {
                    int      index = i + 1;
                    string[] bits;

                    do
                    {
                        bits = data[index].Split(',');
                        Motherboard m = new Motherboard(bits[0], double.Parse(bits[4]),
                                                        bits[1], int.Parse(bits[2]), bool.Parse(bits[3]));
                        Items.Add(m);
                        index++;

                        if (index == data.Length)
                        {
                            break;
                        }
                    }while (data[index].Split(',').Length > 1);
                }

                if (data[i].ToUpper() == "Hard Drive".ToUpper())
                {
                    int      index = i + 1;
                    string[] bits;

                    do
                    {
                        bits = data[index].Split(',');
                        HardDrive h = new HardDrive(bits[0], double.Parse(bits[3]),
                                                    bits[1], double.Parse(bits[2]));
                        Items.Add(h);
                        index++;

                        if (index == data.Length)
                        {
                            break;
                        }
                    }while (data[index].Split(',').Length > 1);
                }

                if (data[i].ToUpper() == "RAM".ToUpper())
                {
                    int      index = i + 1;
                    string[] bits;

                    do
                    {
                        bits = data[index].Split(',');
                        RAM r = new RAM(bits[0], double.Parse(bits[3]),
                                        bits[1], int.Parse(bits[2]));
                        Items.Add(r);
                        index++;

                        if (index == data.Length)
                        {
                            break;
                        }
                    }while (data[index].Split(',').Length > 1);
                }
            }

            return(Items);
        }