コード例 #1
0
 public Livestock(int ID, String type, double amountOfWater, double dailyCost, double weight, int age, String colour) //constructor
 {
     this.ID            = ID;
     this.type          = type;
     this.amountOfWater = amountOfWater;
     this.dailyCost     = dailyCost;
     this.weight        = weight;
     this.age           = age;
     this.colour        = colour;
     left  = null;
     right = null;
 }
コード例 #2
0
        private Livestock bst()                                           //Report 8 - store hash table data into binary tree
        {
            List <Livestock> livestocksList = allAnimals.Values.ToList(); //retrieve data from hashtable and store into list
            Livestock        livestockTree  = new Livestock();

            for (int i = 0; i < livestocksList.Count; i++)
            {
                if (livestocksList[i].getType() == "Dogs")
                {
                }
                else
                {
                    livestockTree.insertToTree(livestocksList[i]);
                }
            }
            return(livestockTree);
        }
コード例 #3
0
        }                                                //Government tax getter

        public void insertToTree(Livestock newLivestock) //To insert livestock into binary tree
        {
            Livestock pointer = livestock;               //set livestock to pointer

            if (pointer == null)
            {
                livestock = newLivestock; //if tree is empty, newLivestock will become the root.
                return;
            }

            while (true)
            {
                if (newLivestock.getProfit() < pointer.getProfit()) //if inserted profit is < pointer
                {
                    if (pointer.left == null)                       //insert to left if pointer.left is empty
                    {
                        pointer.left = newLivestock;
                        break;
                    }
                    else
                    {
                        pointer = pointer.left;
                    }                                //reset pointer.left to pointer
                }
                else //if inserted data is > pointer
                {
                    if (pointer.right == null) //insert to right if pointer.right is empty
                    {
                        pointer.right = newLivestock;
                        break;
                    }
                    else
                    {
                        pointer = pointer.right;
                    }                                 //reset pointer.right to pointer
                }
            }
        }
コード例 #4
0
        private void Form1_Load(object sender, EventArgs e) //auto load
        {
            readData();                                     //read data

            double totalProfit     = 0;                     //Report 2: Display the total profitability/loose of the farm per day
            double totalTax        = 0;                     //Report 3: Display the total tax paid to the governement per month
            double totalMilk       = 0;                     //Report 4: Display the total amount of milk per day for goats and cows
            double totalAge        = 0;                     //Report 5: Display the average age of all animal farms (DOG excluded)
            int    excludeDogCount = 0;                     //Report 5 & 8
            double totalMilkProfit = 0;                     //Report 6: Display the average profitability of “Goats and Cow” Vs. Sheep
            double totalWoolProfit = 0;                     //Report 6
            int    milkAnimalCount = 0;                     //Report 6
            int    woolAnimalCount = 0;                     //Report 6
            double dogCost         = 0;                     //Report 7: Display the ratio of Dogs’ cost compared to the total cost
            double animalCost      = 0;                     //Report 7
            double redCount        = 0;                     //Report 9: Display the ratio of livestock with the color red
            double taxPaid         = 0;                     //Report 10: Display the total tax paid for Jersey Cows
            double profit          = 0;                     //Report 12: Display the total profitability of all Jersey Cows.

            foreach (var animal in allAnimals)
            {
                if (allAnimals.TryGetValue(animal.Key, out livestock))
                {
                    totalProfit += livestock.getProfit();       //Report 2
                    totalTax    += livestock.getGovTax();       //Report 3
                    totalMilk   += livestock.getAmountOfMilk(); //Report 4

                    switch (livestock.getType())
                    {
                    case "Dogs":
                        dogCost += livestock.getDailyCost();     //Report 7
                        break;

                    case "Sheep":
                        totalAge        += livestock.getAge();       //Report 5
                        totalWoolProfit += livestock.getProfit();    //Report 6
                        animalCost      += livestock.getDailyCost(); //Report 7
                        excludeDogCount++;                           //Report 5 & 8
                        woolAnimalCount++;                           //Report 6
                        break;

                    default:
                        totalAge        += livestock.getAge();       //Report 5
                        totalMilkProfit += livestock.getProfit();    //Report 6
                        animalCost      += livestock.getDailyCost(); //Report 7
                        excludeDogCount++;                           //Report 5 & 8
                        milkAnimalCount++;                           //Report 6
                        break;
                    }

                    switch (livestock.getColour().ToLower())
                    {
                    case "red":
                        redCount++;     //Report 9
                        break;
                    }

                    if (livestock.getIsJersy() == true)
                    {
                        taxPaid += (livestock.getAmountOfMilk() * RatesAndPrices.jersyCowTax); //Report 10
                        profit  += livestock.getProfit();                                      //Report 12
                    }
                }
            }
            farmProfitLabel.Text     = totalProfit.ToString();                                                                                //Report 2
            taxPaidLabel.Text        = totalTax.ToString();                                                                                   //Report 3
            totalMilkLabel.Text      = totalMilk.ToString();                                                                                  //Report 4
            aveAgeLabel.Text         = Math.Round((totalAge / excludeDogCount), 2).ToString();                                                //Report 5
            aveProfitRLabel.Text     = Math.Round(((totalMilkProfit / milkAnimalCount) / (totalWoolProfit / woolAnimalCount)), 2).ToString(); //Report 6
            dogCostRLabel.Text       = Math.Round((dogCost / (animalCost + dogCost)), 2).ToString();                                          //Report 7
            redLSRLabel.Text         = Math.Round((redCount / allAnimals.Count), 2).ToString();                                               //Report 9
            totalTaxJerLabel.Text    = Math.Round((taxPaid * 30), 2).ToString();                                                              //Report 10
            totalProfitJerLabel.Text = Math.Round((profit * 30), 2).ToString();                                                               //Report 12

            /* Report 8: Generate a file that contains the ID of all animal ordered by their
             * profitability(You are not allowed to use built -in sorting algorithm – Your
             * code must do the sorting). Dogs are excluded.
             */
            livestockTree = bst();
        }