예제 #1
0
    public void doOutputMedian(int menuChoiceOutput, double[] data, int menuChoiceTime, string year, string month, string[] yearLines, string[] monthLines)
    {
        //Creates output object to access the methods of the class
        output outputObject = new output();

        //Finds the midpoint of the list to find the middle element
        int midPoint = data.Length / 2;

        //Initalise text variable
        string text     = "";
        string fileName = "";

        //Display the correct data
        if (menuChoiceOutput != 1)
        {
            //Get the user input for the filename
            fileName = outputObject.nameFile();

            //Create the text to add to files
            if (menuChoiceOutput == 2)
            {
                if (menuChoiceTime == 1)
                {
                    text = "The Median Value for " + year + " is " + data[midPoint];
                }
                else if (menuChoiceTime == 2)
                {
                    text = "The Median Value for " + month + " " + year + " is " + data[midPoint];
                }
                else if (menuChoiceTime == 3)
                {
                    text = "The Median Value for all data is " + data[midPoint];
                }
                else if (menuChoiceTime == 4)
                {
                    text = "The Median Value for " + month + " is " + data[midPoint];
                }
            }

            //Writes to text file
            File.WriteAllText(fileName + ".txt", text);
            Console.WriteLine("Done");
        }
        else if (menuChoiceOutput == 3)
        {
            if (menuChoiceTime == 1)
            {
                text = "The Median Value for " + year + " is " + data[midPoint];
            }
            else if (menuChoiceTime == 2)
            {
                text = "The Median Value for " + month + " " + year + " is " + data[midPoint];
            }
            else if (menuChoiceTime == 3)
            {
                text = "The Median Value for all data is " + data[midPoint];
            }
            else if (menuChoiceTime == 4)
            {
                text = "The Median Value for " + month + " is " + data[midPoint];
            }

            //Writes to HTML file
            File.WriteAllText(fileName + ".html", text);
            Console.WriteLine("Done");
        }
        else
        {
            //Displays the data to the console
            if (menuChoiceTime == 1)
            {
                Console.WriteLine("The Median Value for {0} is {1}", year, data[midPoint]);
            }
            else if (menuChoiceTime == 2)
            {
                Console.WriteLine("The Median Value for {0} {1} is {2}", month, year, data[midPoint]);
            }
            else if (menuChoiceTime == 3)
            {
                Console.WriteLine("The Median Value for all data is {0}", data[midPoint]);
            }
            else
            {
                Console.WriteLine("The Median Value for {0} is {1}", month, data[midPoint]);
            }
        }
    }
예제 #2
0
    public void doOutputMinMax(int menuChoiceOutput, double[] data, int menuChoiceTime, string year, string month, string[] yearLines, string[] monthLines)
    {
        //Initalise the min and max value positions
        int    min          = 0;
        int    max          = data.Length - 1;
        output outputObject = new output();

        //Display the correct data
        if (menuChoiceOutput != 1)
        {
            string text     = "";
            string fileName = outputObject.nameFile();

            if (menuChoiceOutput == 2)
            {
                if (menuChoiceTime == 1)
                {
                    text += year + " " + " Min: " + data[min] + " Max: " + data[max];
                }
                else if (menuChoiceTime == 2)
                {
                    text += year + " " + month + " Min: " + data[min] + "Max: " + data[max];
                }
                else if (menuChoiceTime == 3)
                {
                    text += "All Data Min: " + data[min] + " " + yearLines[min] + " " + monthLines[min] + " Max: " + data[max] + " " + yearLines[max] + " " + monthLines[max];
                }
                else
                {
                    text += month + " " + " Min: " + data[min] + " Max: " + data[max];
                }

                // Writes to text file
                File.WriteAllText(fileName + ".txt", text);
                Console.WriteLine("Done");
            }
            else if (menuChoiceOutput == 3)
            {
                if (menuChoiceTime == 1)
                {
                    text += year + " Min: " + data[min] + " Max: " + data[max];
                }
                else if (menuChoiceTime == 2)
                {
                    text += year + " " + month + " Min: " + data[min] + " " + "Max: " + data[max];
                }
                else if (menuChoiceTime == 3)
                {
                    text += "All Data Min: " + data[min] + " " + yearLines[min] + " " + monthLines[min] + " Max: " + data[max] + " " + yearLines[max] + " " + monthLines[max];
                }
                else
                {
                    text += month + " " + " Min: " + data[min] + " Max: " + data[max];
                }

                //Writes to html file
                File.WriteAllText(fileName + ".html", text);
                Console.WriteLine("Done");
            }
        }
        else
        {
            if (menuChoiceTime == 1)
            {
                Console.WriteLine("{0} Min: {1} Max: {2}", year, data[min], data[max]);
            }
            else if (menuChoiceTime == 2)
            {
                Console.WriteLine("{0} {1} Min: {2} Max: {3}", year, month, data[min], data[max]);
            }
            else if (menuChoiceTime == 3)
            {
                Console.WriteLine("All Data Min: {0} {1} {2} Max: {3} {4} {5}", data[min], yearLines[min], monthLines[min], data[max], yearLines[max], monthLines[max]);
            }
            else
            {
                Console.WriteLine("{0} Min: {1} Max: {2}", month, data[min], data[max]);
            }
        }
    }
예제 #3
0
    public void doOutput(int menuChoiceOutput, double[] data, int menuChoiceTime, string year, string month, string[] yearLines, string[] monthLines)
    {
        //Creates the object to use
        output outputObject = new output();

        //Display the data based on the user input earlier
        if (menuChoiceOutput != 1)
        {
            string text = "";
            //Get filename from user
            string fileName = outputObject.nameFile();

            if (menuChoiceOutput == 2) //If searching for year
            {
                for (int x = 0; x < data.Length; x++)
                {
                    if (menuChoiceTime == 1)
                    {
                        if (yearLines[x] == year)
                        {
                            text += yearLines[x] + " " + monthLines[x] + " " + data[x];
                            text += "\n";
                        }
                    }
                    else if (menuChoiceTime == 2) //If searching for year and month
                    {
                        if (monthLines[x] == month && yearLines[x] == year)
                        {
                            text += yearLines[x] + " " + monthLines[x] + " " + data[x];
                            text += "\n";
                        }
                    }
                    else if (menuChoiceTime == 3) //If searching for all
                    {
                        text += yearLines[x] + " " + monthLines[x] + " " + data[x];
                        text += "\n";
                    }
                    else if (menuChoiceTime == 4)
                    {
                        if (monthLines[x] == month)
                        {
                            text += yearLines[x] + " " + monthLines[x] + " " + data[x];
                            text += "\n";
                        }
                    }
                }

                //Write the variables to the file
                File.WriteAllText(fileName + ".txt", text);
                Console.WriteLine("Done");
            }
            else if (menuChoiceOutput == 3)
            {
                for (int x = 0; x < data.Length; x++)
                {
                    if (menuChoiceTime == 1)
                    {
                        if (yearLines[x] == year)
                        {
                            text += yearLines[x] + " " + monthLines[x] + " " + data[x];
                            text += "<br>";
                        }
                    }
                    else if (menuChoiceTime == 2)
                    {
                        if (monthLines[x] == month && yearLines[x] == year)
                        {
                            text += yearLines[x] + " " + monthLines[x] + " " + data[x];
                            text += "<br>";
                        }
                    }
                    else if (menuChoiceTime == 3)
                    {
                        text += yearLines[x] + " " + monthLines[x] + " " + data[x];
                        text += "<br>";
                    }
                    else if (menuChoiceTime == 4)
                    {
                        if (monthLines[x] == month)
                        {
                            text += yearLines[x] + " " + monthLines[x] + " " + data[x];
                            text += "<br>";
                        }
                    }
                }

                //Write the variable to the html file
                File.WriteAllText(fileName + ".html", text);
                Console.WriteLine("Done");
            }
        }
        else
        {
            //Display the text normally to the console
            for (int x = 0; x < data.Length; x++)
            {
                if (menuChoiceTime == 1)
                {
                    if (yearLines[x] == year)
                    {
                        Console.WriteLine(yearLines[x] + " " + monthLines[x] + " " + data[x]);
                    }
                }
                else if (menuChoiceTime == 2)
                {
                    if (monthLines[x] == month && yearLines[x] == year)
                    {
                        Console.WriteLine(yearLines[x] + " " + monthLines[x] + " " + data[x]);
                    }
                }
                else if (menuChoiceTime == 3)
                {
                    Console.WriteLine(yearLines[x] + " " + monthLines[x] + " " + data[x]);
                }
                else if (menuChoiceTime == 4)
                {
                    if (monthLines[x] == month)
                    {
                        Console.WriteLine(yearLines[x] + " " + monthLines[x] + " " + data[x]);
                    }
                }
            }
        }
    }