private static void SaveGrades(GradeTracker book) { using (StreamWriter outputFile = File.CreateText("grades.txt")) { book.WriteGrades(outputFile); } }
private static void AddingGrades(GradeTracker book) { book.AddGrade(91); book.AddGrade(89); book.AddGrade(98); book.AddGrade(60); }
static void Main(string[] args) { //GradeBook Book = new GradeBook(); //GradeStatistics Stats = new GradeStatistics(); //Book.NameChanged += new NameChangedDelegate(OnNameChanged); // overwritten with OnNameChanged2 except with += //Book.NameChanged += new NameChangedDelegate(OnNameChanged2); // event keyword not = only += //Book.NameChanged = null; //don't use //Book.NameChanged += OnNameChanged; //automatically create the delegate instance behind the scene will know it is a NameChangedDelegate //Book.NameChanged += OnNameChanged2; //automatically create the delegate instance behind the scene will know it is a NameChangedDelegate //Book.NameChanged += OnNameChanged2; //Book.NameChanged -= OnNameChanged2; //will subscribe twice and remove once -= unscubscribe GradeTracker book = CreateGradeBook(); GradeStatistics Stats = new GradeStatistics(); book.NameChanged += OnNameChanged; // Subscribe to event. //GetBookName(Book); AddGrades(book); //Book.WriteGrades(Console.Out); Stats = Save(book); WriteResults(book, Stats); }
static void Main(string[] args) { GradeTracker book = CreateGradeBook(); AddGrades(book); SaveGrades(book); WriteResults(book); }
// Becuase of the use of the virtual keyword in GradeBook.cs // The behaviour of this method will depend on the type of GradeBook // being passed to this method, that is of course assuming that we // have overridden the ComputeStatistics method private static void WriteResults(GradeTracker book) { GradeStatistics stats = book.ComputeStatistics(); WriteResult("Average", stats.AverageGrade); WriteResult("Highest", stats.HighestGrade); WriteResult("Lowest", stats.LowestGrade); WriteResult(stats.Description, stats.LetterGrade); }
private static void AddGrades(GradeTracker book) { book.NameChanged += OnNameChanged; book.Name = "Nathan's Grade Book"; //writing a reference to a string into this field book.Name = "Grade Book"; book.AddGrade(91); book.AddGrade(89.5f); book.AddGrade(75); }
private static void GetBookName(GradeTracker book) { try { Console.WriteLine("Enter a name"); book.Name = Console.ReadLine(); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } }
private static void WriteResults(GradeTracker book) { GradeStatistics stats = book.ComputeStatistics(); Console.WriteLine(book.Name); WriteResult("Average", stats.AverageGrade); WriteResult("Highest", (int)stats.HighestGrade); WriteResult("Lowest", stats.LowestGrade); WriteResult(stats.Description, stats.LetterGrade); WriteResult("Params", stats.LowestGrade, 5, 6, 7); //Params - can pass an array of variable length Console.Read(); }
/* * private static void WriteGradesInBytes(GradeTracker book) * { * * foreach (float grade in book.grades) * { * WriteasBytes((int)grade); * } * }*/ private static void WriteResults(GradeTracker book) { GradeStatistics stats = book.ComputeStatistics(); WriteResult("Average", (int)stats.AverageGrade); WriteResult("AverageFloat", stats.AverageGrade); WriteResult("AverageLetterGrade", stats.LetterGrade); WriteResult("AverageLetterDescription", stats.Description); WriteResult(stats.Description, stats.LetterGrade); Console.WriteLine(stats.AverageGrade); Console.WriteLine(stats.LowestGrade); Console.WriteLine(stats.HighestGrade); }
private static void WriteResults(GradeTracker Book, GradeStatistics Stats) { foreach (float grade in Book) { Console.WriteLine(grade); } Console.WriteLine(Book.Name); WriteResult("Average", Stats.AverageGrade); WriteResult("Low", Stats.LowGrade); WriteResult("High", (int)Stats.HighGrade); //float will be truncated not rounded. WriteResult("", Stats.LetterGrade); Console.ReadLine(); }
static void Main(string[] args) { GradeTracker book = CreateGradeBook(); book.AddGrades(new List <double>() { 91, 90, 87.5 }); book.WriteGrades(); GradeStatistics stats = book.ComputeStats(); WriteResult("Average", stats.AverageGrade); }
private static void GetBookName(GradeTracker book) { try { Console.WriteLine("Enter a name"); book.Name = Console.ReadLine(); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } catch (NullReferenceException) { Console.WriteLine("Something went wrong"); } }
static void Main(string[] args) { GradeTracker book = CreateGradeBook(); book.NameChanged += new NameChangedDelegate(OnNameChanged); // Add methods to delegate with += book.NameChanged += OnNameChanged2; // Can also be written like this. //book.NameChanged = null; NameChanged is an event. Events can only add or subtract a subscriber. book.Name = null; book.Name = "Stephen's Grade Book"; AddGrades(book); StreamWriter outputFile = File.CreateText("grades.txt"); book.WriteGrades(outputFile); WriteResults(book); }
static void Main(string[] args) { GradeTracker book = CreateGradeBook(); NewMethod(book); //book.NameChanged += new NameChangedDelegate(OnNameChanged); // book.NameChanged = null; //Error because of event. A example to not use delegate //book.NameChanged += OnNameChanged; //book.NameChanged += OnNameChanged2; // No need to use new NameChangedDelegate //book.Name = "Ravi's Grade Book"; //book.Name = null; AddGrades(book); WriteResults(book); SaveGrades(book); }
private static void GetBookName(GradeTracker book) { try { Console.WriteLine("What would you like to call your grade book?"); book.Name = Console.ReadLine(); } catch (AggregateException ex) { Console.WriteLine(ex.Message); } catch (NullReferenceException) { Console.WriteLine("Something went wrong"); } catch (Exception) { Console.WriteLine("Something went wrong"); } finally { Console.WriteLine("Finished"); } }
private static void AddGrades(GradeTracker book) { book.AddGrade(91); book.AddGrade(89.5f); book.AddGrade(75); }
private static void AddGrades(GradeTracker book) { book.AddGrade(100); book.AddGrade(95); book.AddGrade(60); }
private static void GetBookName(GradeTracker Book) { Book.Name = "Scott's Grade Book"; Book.Name = "Grade Book"; }
private static GradeStatistics Save(GradeTracker Book) { return(Book.ComputeStatistics()); }
private static void AddGrades(GradeTracker Book) { Book.AddGrade(100); Book.AddGrade(50.5f); Book.AddGrade(75); }