static void Main(string[] args) { var book = new Book(); book.AddGrade(52.2); book.AddGrade(52.2); book.AddGrade(52.2); book.AddGrade(52.2); var average = book.GetAverage(); System.Console.WriteLine(average); }
static void Main(string[] args) { var book = new Book("My gradebook"); book.AddGrade(89.1); book.AddGrade(90.6); var average = book.GetAverage(); Console.WriteLine(average); var stats = book.GetStatistics(); Console.WriteLine($"The average grade is: {stats.Average}"); Console.WriteLine($"The lowest grade is: {stats.Low}"); Console.WriteLine($"The highest grade is: {stats.High}"); }
static void Main(string[] args) { var book = new Book("Gym Class"); book.AddGrade(75.2); book.AddGrade(90.2); book.AddGrade(84); book.AddGrade(98.4); var highestGrade = book.GetHighestGrade(); var lowestGrade = book.GetLowestGrade(); var averageGrade = book.GetAverage(); book.ShowStatistics(); // Console.WriteLine($"The highest grade is {highestGrade}; The lowest grade is {lowestGrade}; The average grade is {averageGrade};"); }
static void Main(string[] args) { // Creates a book object with a unique id var book = new Book("Grade"); // Setups up the subscription to the event delegates (Event Listeners, think of this as the socket.io connected message) book.GradeAdded += OnGradeAdded; book.GradeAddedError += OnGradeAddedError; // Constantly loops until q is typed while (true) { // Print out a user message Console.WriteLine("Enter the grade or 'q' to quite"); // Reads the users console input var input = Console.ReadLine(); // Exits the programme flow if (input == "q") { break; } // When an error occurs it throes an error to one of the catch blocks defined below try { var grade = double.Parse(input); book.AddGrade(grade); } // Checks for a formatting exception (Formatting error e.g. ffggsasdsa or qwqeqqeq) catch (FormatException ex) { Console.WriteLine(ex.Message); } // Checks for expections which haven't been accounted for catch (Exception ex) { Console.WriteLine(ex.Message); } } // When the total is not 0 print out the results if (book.GetTotal() != 0) { /* * * Formatting outputs notes: * * Resources: * - https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings * * Formatting options: * * - Math.round(yourValue, MidpointRounding.AwayFromZero) * * - yourValue.toString("N") - N, N[Number of decimal places e.g. 2, 4, 10 etc] * */ Console.WriteLine(book.Name); double total = book.GetTotal(); Console.WriteLine($"The total for the grades are {total}"); double average = book.GetAverage(total); Console.WriteLine($"The average grade is {average.ToString("N2")}"); double lowestValue = book.GetLowestGrade(); Console.WriteLine($"The lowest grade is {lowestValue}"); double highestGrade = book.GetHighestGrade(); Console.WriteLine($"The highest grade is {highestGrade}"); } }