コード例 #1
0
ファイル: Form1.cs プロジェクト: Nabzi123/Coursework
        //Takes all the selected items and calculate the price of them all, + a build cost of 10%

        //No error checking here, there should be
        private void button1_Click(object sender, EventArgs e)
        {
            double price = 0;

            CPU         c = (CPU)listBoxCPU.SelectedItem;
            Motherboard m = (Motherboard)listBoxMotherBoard.SelectedItem;
            HardDrive   h = (HardDrive)listBoxHardDrive.SelectedItem;
            RAM         r = (RAM)listBoxRam.SelectedItem;

            price = (c.getPrice() + m.getPrice() + h.getPrice() + r.getPrice()) * 1.1;

            MessageBox.Show("Computer costs : " + price.ToString());
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Nabzi123/Coursework
        //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);
        }