<repo_name>BrianRuszkowski/ConsoleApps15<file_sep>/ConsoleAppProject/ConsoleHelper.cs
﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleAppProject
{
    public static class ConsoleHelper
    {
        /// <summary>
        /// This method makes sure that the user doesn't input the wrong value
        /// and repeats the process until a correct value is given
        /// </summary>
        /// <param name="choices"></param>
        /// <returns></returns>
        public static int SelectChoice(string[] choices)
        {
            int choiceNo = 0;

            //Display all the choices

            foreach (string choice in choices)
            {
                choiceNo++;
                Console.WriteLine($"|{choiceNo}. {choice}");
            }

            choiceNo = InputNumberWithin(choiceNo - choiceNo + 1, choices.Length);

            return choiceNo;
        }

        /// <summary>
        /// This method checks that the number is within limit 
        /// </summary>
        /// <param name="prompt"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public static double InputNumber(string prompt, double min, double max)
        {
            bool isValid;
            double number;

            do
            {
                number = InputNumber(prompt);

                if (number < min || number > max)
                {
                    isValid = false;
                    Console.WriteLine($"Number must be between {min} and {max}");
                }
                else isValid = true;

            } while (!isValid);

            return number;

        }

        /// <summary>
        /// This method checks the input number and if number
        /// is false the method will ask for a different number
        /// </summary>
        /// <returns></returns>
        public static double InputNumber()
        {
            double number = 0;
            bool Isvalid = false;

            do
            {
                Console.Write(">");
                string value = Console.ReadLine();

                try
                {
                    number = Convert.ToDouble(value);
                    Isvalid = true;
                }
                catch (Exception)
                {
                    Isvalid = false;
                    Console.WriteLine("Number is INVALID!!!");
                }
            }
            while (!Isvalid);
            return number;

        }
        
        /// <summary>
        /// This method checks the input number and if number
        /// is false the method will ask for a different number
        /// </summary>
        /// <param name="prompt"></param>
        /// <returns></returns>
        public static double InputNumber(string prompt)
        {
            double number = 0;
            bool Isvalid = false;

            do
            {
                Console.Write(">");
                string value = Console.ReadLine();

                try
                {
                    number = Convert.ToDouble(value);
                    Isvalid = true;
                }
                catch (Exception)
                {
                    Isvalid = false;
                    Console.WriteLine("Number is INVALID!!!");
                }
            }
            while (!Isvalid);
            return number;

        }

        /// <summary>
        /// This method checks the value of the number
        /// </summary>
        /// <param name="value"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public static bool InRange(double value, double from, double to)
        {
            if (value >= from && value <= to)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// This method checks the input number and keeps it within the value
        /// any number that is greater than will not count
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public static int InputNumberWithin(int from, int to)
        {
            int number;
            bool Isvalid;

            do
            {
                double value = InputNumber();

                number = Convert.ToInt32(value);
                Isvalid = true;

                if (number < from || number > to)
                {
                    Console.WriteLine($"Number must be between {from} and {to} !");
                    Isvalid = false;
                }
            }
            while (!Isvalid);

            return number;
        }

        /// <summary>
        /// This method displays the student name and the name of the application
        /// </summary>
        /// <param name="heading"></param>
        public static void OutputHeading(string heading)
        {
            Console.WriteLine("\n--------------------------------------------");
            Console.WriteLine("              {heading}         ");
            Console.WriteLine("           By <NAME>              ");
            Console.WriteLine("--------------------------------------------\n");
        }
    }
}
<file_sep>/ConsoleAppProject/App03/StudentGrades.cs
﻿using System;

namespace ConsoleAppProject.App03
{
    /// <summary>
    /// This method contains all the information for the program
    /// such how many marks you need for a certain grade
    /// </summary>
    public class StudentGrades
    {
        // Constants (Grade Boundaries)

        public const int LowestMark = 0;
        public const int LowestGradeD = 40;
        public const int LowestGradeC = 50;
        public const int LowestGradeB = 60;
        public const int LowestGradeA = 70;
        public const int HighestMark = 100;

        // Properties
        public string[] Students { get; set; }

        public int[] Marks { get; set; }

        public int[] GradeProfile { get; set; }

        public double Mean { get; set; }

        public int Minimum { get; set; }

        public int Maximum { get; set; }

        /// <summary>
        /// This method is for the list of student names whithin the
        /// application
        /// </summary>
        public StudentGrades()
        {
            Students = new string[]
            {
                "Brian", "Blend", "Eliott",
                "Tom", "Ash", "Lian",
                "Jack", "Liam", "Jess",
                "Shamial"
            };

            GradeProfile = new int[(int)Grades.A + 1];
            Marks = new int[Students.Length];
        }

        /// <summary>
        /// This method outputs the choices for the user and allows them 
        /// to choose what they want to do after a number has been entered
        /// it will take them to that choice
        /// </summary>
        public void OutputMenu()
        {
            string[] choices = new string[]
            {
                "Input Marks", "Output Marks", "Output Grade Profile", "Quit", "giveMarksTesting()", "giveMarksTo()"
            };

            bool finished = false;
            do
            {
                Console.WriteLine();
                switch (ConsoleHelper.SelectChoice(choices))
                {
                    case 1:
                        InputMarks();
                        break;

                    case 2:
                        OutputMarks();
                        break;


                    case 3:
                        CalculateGradeProfile();
                        OutputGradeProfile();
                        break;

                    case 4:
                        Console.WriteLine(@"Now quitting Student Grades");

                        finished = true;
                        break;

                    case 5:
                        giveMarksTesting();
                        break;

                    case 6:
                        giveMarksTo(Console.ReadLine(), (int)ConsoleHelper.InputNumber());
                        break;
                }
            } while (!finished);
        }

        /// <summary>
        /// This method allows the user to input marks for all students
        /// </summary>
        public void InputMarks()
        {
            int i = 0;

            foreach (string student in Students)
            {
                Console.WriteLine($"Enter the marks for {student} >");
                Marks[i] += ConsoleHelper.InputNumberWithin(LowestMark, HighestMark);
                i++;
            }
        }

        /// <summary>
        /// This method allows the user to input marks for a specific student
        /// and checks if the name is correct for the student they wish to add
        /// marks for
        /// </summary>
        /// <param name="name"></param>
        /// <param name="mark"></param>
        /// <returns></returns>
        public int giveMarksTo(string name, int mark)
        {
            int i = 0;

            foreach (string student in Students)
            {
                if (!ConsoleHelper.InRange(mark, LowestMark, HighestMark))
                {
                    return -1;
                }

                string correctName = student;
                if (correctName == name)
                {
                    Marks[i] += mark;
                    break;
                }
                else
                {
                    i++;
                }
            }

            return Marks[i];
        }

        /// <summary>
        /// This method displays all marks that each student has
        /// </summary>
        public void OutputMarks()
        {
            Console.WriteLine("Output Marks :");
            Console.WriteLine();
            int i = 0;

            foreach (string student in Students)
            {
                Console.WriteLine($" Marks for {student} :| {Marks[i]} |");
                i++;
            }
        }

        /// <summary>
        /// This method converts the amount of marks a student has into
        /// a specific grade that corresponds with their amount of marks
        /// </summary>
        /// <param name="mark"></param>
        /// <returns></returns>
        public Grades ConvertToGrade(int mark)
        {
            if (ConsoleHelper.InRange(mark, LowestGradeA, HighestMark) || mark > 100)
            {
                return Grades.A;
            }
            else if (ConsoleHelper.InRange(mark, LowestGradeB, LowestGradeA - 1))
            {
                return Grades.B;
            }
            else if (ConsoleHelper.InRange(mark, LowestGradeC, LowestGradeB - 1))
            {
                return Grades.C;
            }
            else if (ConsoleHelper.InRange(mark, LowestGradeD, LowestGradeC - 1))
            {
                return Grades.D;
            }
            else
            {
                return Grades.F;
            };
        }

        /// <summary>
        /// This method calculates the students stats and marks
        /// </summary>
        public void CalculateStats()
        {
            double total = 0;

            foreach (int mark in Marks)
            {
                total = total = mark;
            }

            Mean = total / Marks.Length;

            Maximum = 0;
            foreach (int mark in Marks)
            {
                if (mark > Maximum)
                {
                    Maximum = mark;
                }
            }

            Minimum = 100;
            foreach (int mark in Marks)
            {
                if (mark < Minimum)
                {
                    Minimum = mark;
                }
            }
        }

        /// <summary>
        /// This method calculates mark to grade
        /// </summary>
        public void CalculateGradeProfile()
        {
            for (int i = 0; i < GradeProfile.Length; i++)
            {
                GradeProfile[i] = 0;
            }

            foreach (int mark in Marks)
            {
                Grades grade = ConvertToGrade(mark);
                GradeProfile[(int)grade]++;
            }
        }

        /// <summary>
        /// This method displays grade profile for the student
        /// </summary>
        public void OutputGradeProfile()
        {
            Grades grade = Grades.F;
            Console.WriteLine();

            foreach (int count in GradeProfile)
            {
                int percentage = count * 100 / Marks.Length;
                Console.WriteLine($"Grade {grade} {percentage}% Count {count}");
                grade++;
            }

            Console.WriteLine();

        }

        /// <summary>
        /// This method gives the user the ability to add marks for testing
        /// </summary>
        public void giveMarksTesting()
        {
            int i = 0;
            Random r = new Random();
            foreach (string student in Students)
            {
                Marks[i] += r.Next(0, 100);
                Console.WriteLine($"{student} marks : {Marks[i]}");
                i++;
            }
        }
    }
}<file_sep>/ConsoleAppProject/Program.cs
﻿using ConsoleAppProject.App01;
using ConsoleAppProject.App02;
using ConsoleAppProject.App03;
using ConsoleAppProject.App04;
using System;

namespace ConsoleAppProject
{
    /// <summary>
    /// The main method in this class is called first
    /// when the application is started.  It will be used
    /// to start Apps 01 to 05 for CO453 CW1
    /// 
    /// This Project has been modified by:
    /// <NAME> 09/03/2021
    /// </summary>
    public static class Program
    {
        private static DistanceConverter converter = new DistanceConverter();

        private static BMI calculator = new BMI();

        private static StudentGrades grades = new StudentGrades();

        private static NetworkApp app04 = new NewtworkApp();

        public static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;

            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("BNU CO453 Applications Programming 2020-2021!");
            Console.WriteLine("           By <NAME>");
            Console.WriteLine("-----------------------------------------------"); 
            Console.WriteLine();

            Console.WriteLine("1. Distance Converter");
            Console.WriteLine("2. BMI Calculator");
            Console.WriteLine("3. Student Grades");

            Console.Write("Please enter your choice of App > ");
            string choice = Console.ReadLine();

            if (choice == "1")
            {
                converter.ConvertDistance();
            }
            else if(choice == "2")
            {
                calculator.CalculateIndex();
            }
            else if(choice == "3")
            {
                grades.OutputMenu();
            }
            else if(choice == "4")
            {

                App04.NetwortApp();
            }
        }
    }
}
<file_sep>/ConsoleAppProject/App02/BMI.cs
﻿using System;

namespace ConsoleAppProject.App02
{
    /// <summary>
    /// This method allows the program to calculate metric and imperial measurements
    /// </summary>
    public enum UnitSystems
    {
        Metric,
        Imperial
    }

    /// <summary>
    /// This class contains methods for calculating
    /// the user's BMI (Body Mass Index) using
    /// imperial or metric units
    /// </summary>
    /// <author>
    /// <NAME> App02: version 2.0
    /// </author>
    public class BMI
    {
        public const double Underweight = 18.5;
        public const double NormalRange = 24.9;
        public const double Overweight = 29.9;

        public const double ObeseLevel1 = 34.9;
        public const double ObeseLevel2 = 39.9;
        public const double ObeseLevel3 = 40.0;

        public const int InchesInFeet = 12;
        public const int PoundsInStones = 14;

        private double index;

        // Metric Details

        private double kilograms;
        private double metres;

        // Imperial Details

        private double pounds;
        private int inches;

        /// <summary>
        /// This method outputs the heading for BMI and calculates the either imperial or 
        /// metric and outputs the health message
        /// </summary>
        public void CalculateIndex()
        {
            ConsoleHelper.OutputHeading("Body Mass Undex Calculator");

            UnitSystems unitSystems = SelectUnits();

            if (unitSystems == UnitSystems.Metric)
            {
                InputMetricDetails();
                CalculateMetricBMI();
            }
            else
            {
                InputImperialDetails();
                CalculateImperialBMI();
            }

            OutputHealthMessage();
        }

        /// <summary>
        /// This method calculates the metric measurements kilograms and metres
        /// </summary>
        public void CalculateMetricBMI()
        {
            index = kilograms / (metres * metres);
        }

        /// <summary>
        /// This method calculates the imperial measurements pounds and inches
        /// </summary>
        public void CalculateImperialBMI()
        {
            index = pounds * 703 / (inches * inches);
        }

        /// <summary>
        /// This method shows the user two choices that he can choose between
        /// either metric or imperial measurements and choose between one or the other
        /// </summary>
        private UnitSystems SelectUnits()
        {
            Console.WriteLine("1. Metric");
            Console.WriteLine("2. Imperial");
            int choice = (int)ConsoleHelper.InputNumber("Please Enter your choice > ", 1, 2);

            if (choice == 1)
            {
                return UnitSystems.Metric;
            }
            return UnitSystems.Imperial;
        }

        /// <summary>
        /// This method has the input details for metric details
        /// this method will output the message for the user to enter his metric details
        /// </summary>
        private void InputMetricDetails()
        {
            metres = ConsoleHelper.InputNumber(
                " \n Enter your height in metres > ", 1, 3);

            kilograms = ConsoleHelper.InputNumber(
                " Enter your weight in kilograms > ");
        }

        /// <summary>
        /// This method has all the measurement details for
        /// the imperial measurements and the output message for imperial details
        /// </summary>
        private void InputImperialDetails()
        {
            int stones = (int)ConsoleHelper.InputNumber(
                " Enter your weight in stones > ");

            pounds = (int)ConsoleHelper.InputNumber(
                " Enter your weight in pounds > ");

            pounds = pounds + stones * PoundsInStones;

            int feet = (int)ConsoleHelper.InputNumber("Please Enter your height in feet > ");

            inches = (int)ConsoleHelper.InputNumber(
                " Enter your hight in inches > ", 0, 12);
        }

        /// <summary>
        /// This method outputs the health message dependant
        /// on what your weight is 
        /// </summary>
        private void OutputHealthMessage()
        {
            Console.WriteLine();

            if (index < Underweight)
            {
                Console.WriteLine($" Your BMI is {index:0.00}, " +
                    $"You are underweight! ");
            }
            else if (index <= NormalRange)
            {
                Console.WriteLine($" Your BMI is {index:0.00}, " +
                    $"You are in the normal range! ");
            }
            else if (index <= Overweight)
            {
                Console.WriteLine($" Your BMI is {index:0.00}, " +
                    $"You are overweight! ");
            }
            else if (index <= ObeseLevel1)
            {
                Console.WriteLine($" Your BMI is {index:0.00}, " +
                    $"You are obese class I! ");
            }
            else if (index <= ObeseLevel2)
            {
                Console.WriteLine($" Your BMI is {index:0.00}, " +
                    $"You are obese class II! ");
            }
            else if (index <= ObeseLevel3)
            {
                Console.WriteLine($" Your BMI is {index:0.00}, " +
                    $"You are obese class III! ");
            }
            else
                Console.WriteLine("Something Has Gone Very Wrong!!!");

            OutputBameMessage();
        }

        /// <summary>
        /// This method outputs the bame message at the end when the calculation
        /// finishes the bame messages shows the user who is at risk
        /// </summary>
        private void OutputBameMessage()
        {
            Console.WriteLine();
            Console.WriteLine(" If you are Black, Asian or other minority");
            Console.WriteLine(" ethnic groups, you have a higher risk");
            Console.WriteLine();
            Console.WriteLine("\t Adults 23.0 or more are at increased risk");
            Console.WriteLine("\t Adults 27.5 or more are at high risk");
            Console.WriteLine();
        }
    }
}<file_sep>/ConsoleAppProject/App01/DistanceConverter.cs
﻿using System;

namespace ConsoleAppProject.App01
{
    /// <summary>
    /// This is my mesurement converter which you can can convert units from and to a 
    /// certain mesurment and get the output and the calculation for the mesurement
    /// </summary>
    /// <author>
    /// <NAME> 21717237 version 1.0
    /// </author>   
    
    ///<summary>
    ///This code is for the value of each of the mesurement from and to value
    /// </summary>
    public class DistanceConverter
    {
        public const double FEET_IN_FEET = 1.0;

        public const double METRES_IN_MILES = 1609.34;

        public const double FEET_IN_METRES = 3.28084;

        public const double FEET_IN_MILES = 5280;

        public const double METRES_IN_METRES = 1.0;

        public const double MILES_IN_MILES = 1.0;

        public const double MILES_IN_FEET = 0.000189393939;

        public const double METRES_IN_FEET = 0.3048;

        public const double MILES_IN_METRES = 0.000621371192;

        public const string FEET = "Feet";
        public const string METRES = "Metres";
        public const string MILES = "Miles";

        private double fromDistance;
        private double toDistance;

        private string fromUnit;
        private string toUnit;

        public DistanceConverter()
        {
            fromUnit = MILES;
            toUnit = FEET;
        }

        /// <summary>
        /// Distance converter this code outputs the comment to select mesurment to and from 
        /// and shows which mesurments you have selected it also calculates both mesurments selected
        /// </summary>
        public void ConvertDistance()
        {
            ConsoleHelper.OutputHeading("DistanceConverter");

            fromUnit = SelectUnit(" Please select the from distance unit > ");
            toUnit = SelectUnit(" Please select the to distance unit > ");

            Console.WriteLine($"\n Converting {fromUnit} to {toUnit}");

            fromDistance = InputDistance($" Please enter the number of {fromUnit} > ");

            CalculateDistance();

            OutputDistance();
        }

        /// <summary>
        /// Distance calculator this code allows the user to select the to and from unit
        /// and giving them the convertion calculation 
        /// </summary>
        private void CalculateDistance()
        {
            if(fromUnit == FEET && toUnit == FEET)
            {
                toDistance = fromDistance * FEET_IN_FEET;
            }
            else if(fromUnit == FEET && toUnit == MILES)
            {
                toDistance = fromDistance / FEET_IN_MILES;
            }
            else if(fromUnit == FEET && toUnit == METRES)
            {
                toDistance = fromDistance / FEET_IN_METRES;
            }
            else if (fromUnit == MILES && toUnit == FEET)
            {
                toDistance = fromDistance / MILES_IN_FEET;
            }
            else if (fromUnit == MILES && toUnit == MILES)
            {
                toDistance = fromDistance / MILES_IN_MILES;
            }
            else if (fromUnit == MILES && toUnit == METRES)
            {
                toDistance = fromDistance / MILES_IN_METRES;
            }
            else if (fromUnit == METRES && toUnit == FEET)
            {
                toDistance = fromDistance / METRES_IN_FEET;
            }
            else if (fromUnit == METRES && toUnit == METRES)
            {
                toDistance = fromDistance / METRES_IN_METRES;
            }
            else if (fromUnit == METRES && toUnit == MILES)
            {
                toDistance = fromDistance / METRES_IN_MILES;
            }
        }

        /// <summary>
        /// This code displays which choice the user has selected the to and from measurements
        /// and shows both units chosen
        /// </summary>
        private string SelectUnit(string prompt)
        {
            string choice = DisplayChoices(prompt);

            string unit = ExecuteChoice(choice);
            Console.WriteLine($"\n You have chosen {unit}");
            return unit;
        }

        /// <summary>
        /// This code is for the choices which allow the user to input which 
        /// conversion of measurement they want to choose to and from
        /// </summary>
        private static string ExecuteChoice(string choice)
        {
            if (choice.Equals("1"))
            {
                return FEET;
            }
            else if (choice == "2")
            {
                return METRES;
            }
            else if (choice.Equals("3"))
            {
                return MILES;
            }

            return null;
        }


        /// <summary>
        /// This code displays options of conversion for the user to unit and from unit
        /// </summary>
        private static string DisplayChoices(string prompt)
        {
            Console.WriteLine();
            Console.WriteLine($" 1. {FEET}");
            Console.WriteLine($" 2. {METRES}");
            Console.WriteLine($" 3. {MILES}");
            Console.WriteLine();

            Console.Write(prompt);
            string choice = Console.ReadLine();
            return choice;
        }

        /// <summary>
        /// This code is for the input of the measurement
        /// </summary>
        private double InputDistance(string prompt)
        {
            Console.Write(prompt);
            string value = Console.ReadLine();
            return Convert.ToDouble(value);
        }

        /// <summary>
        /// This code is for the output of the measurement 
        /// </summary>
        private void OutputDistance()
        {
            Console.WriteLine($"\n {fromDistance} {fromUnit}" + 
                $" is {toDistance} {toUnit}!\n");
        }
    }
}