Ejemplo n.º 1
0
        private void Report6_Load(object sender, EventArgs e)
        {
            Cow   c = new Cow();
            Goat  g = new Goat();
            Sheep s = new Sheep();

            cowprofit.Text   = c.Profitability().ToString();
            goatprofit.Text  = g.Profitability().ToString();
            sheepprofit.Text = s.Profitability().ToString();
        }
Ejemplo n.º 2
0
        private void Report2_Load(object sender, EventArgs e)
        {
            Cow      c = new Cow();
            JersyCow j = new JersyCow();
            Sheep    s = new Sheep();
            Goat     g = new Goat();

            cowprofit.Text   = c.Profitability().ToString();
            jcowprofit.Text  = j.Profitability().ToString();
            goatprofit.Text  = g.Profitability().ToString();
            sheepprofit.Text = s.Profitability().ToString();
            totalprofit.Text = (c.Profitability() + j.Profitability() + g.Profitability() + s.Profitability()).ToString();
        }
Ejemplo n.º 3
0
        private void Report8_Load(object sender, EventArgs e)
        {
            Database.arr.Clear();//clear the arr hash table as we will fill it again so no duplicate error occurs
            Cow      c  = new Cow();
            JersyCow jc = new JersyCow();
            Goat     g  = new Goat();
            Sheep    s  = new Sheep();

            //fill the hash table named arr with id and profit of all animals
            c.SingleAnimalProfitability();
            jc.SingleAnimalProfitability();
            g.SingleAnimalProfitability();
            s.SingleAnimalProfitability();
            double tempVal; int tempid; int count = 0;

            sorting[] data = new sorting[Database.arr.Count];           //declare a struct array
            foreach (KeyValuePair <int, double> animal in Database.arr) //fill that array with hash table data
            {
                data[count].id     = animal.Key;
                data[count].profit = animal.Value;
                count++;
            }
            for (int i = 0; i < Database.arr.Count; i++)//here is the array sorting algorithm
            {
                for (int j = i + 1; j < Database.arr.Count; j++)
                {
                    if (data[i].profit > data[j].profit)
                    {
                        tempid         = data[i].id;
                        tempVal        = data[i].profit;
                        data[i].id     = data[j].id;
                        data[i].profit = data[j].profit;
                        data[j].id     = tempid;
                        data[j].profit = tempVal;
                    }
                }
            }
            textBox1.Text = textBox1.Text + "Animal ID" + "                    " + "Profitability" + "\r\n";//fill textbox with the array data
            textBox1.Text = textBox1.Text + "----------------------------------------------------" + "\r\n";
            FileStream   fs = new FileStream("sortedData.txt", FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);

            for (int i = 0; i < Database.arr.Count; i++)//save that data into text file
            {
                textBox1.Text = textBox1.Text + data[i].id.ToString() + "                                 " + data[i].profit.ToString() + "\r\n";

                sw.WriteLine(data[i].id);
            }
            sw.Close();
        }