From 0435f6592ed3548c76775f3e85112b64f9b7ee30 Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Tue, 23 Feb 2021 00:02:47 +0000 Subject: [PATCH] Finished Using IDisposable --- gradebook/src/GradeBook/Book.cs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/gradebook/src/GradeBook/Book.cs b/gradebook/src/GradeBook/Book.cs index f5d95bc..58a0e03 100644 --- a/gradebook/src/GradeBook/Book.cs +++ b/gradebook/src/GradeBook/Book.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Collections.Generic; namespace GradeBook @@ -39,8 +40,31 @@ namespace GradeBook } public abstract void AddGrade(double grade); - public virtual event GradeAddedDelegate GradeAdded; - public virtual Statistics GetStatistics() + public abstract event GradeAddedDelegate GradeAdded; + public abstract Statistics GetStatistics(); + } + + public class DiskBook : Book + { + public DiskBook(string name) : base(name) + { + } + + public override event GradeAddedDelegate GradeAdded; + + public override void AddGrade(double grade) + { + using(var writer = File.AppendText($"{Name}.txt")) + { + writer.WriteLine("Test"); + if (GradeAdded != null) + { + GradeAdded(this, new EventArgs()); + } + } + } + + public override Statistics GetStatistics() { throw new NotImplementedException(); }