Skip to content
Open

18/6 #32

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions GradeBook/GradeBooks/BaseGradeBook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@

namespace GradeBook.GradeBooks
{
public class BaseGradeBook
public abstract class BaseGradeBook
{
public GradeBookType Enum { get; set; }
public GradeBookType Type { get; set; }
public string Name { get; set; }
public List<Student> Students { get; set; }
public bool IsWeighted { get; set; }

public BaseGradeBook(string name)
public BaseGradeBook(string name, bool isWeighted)
{
Name = name;
Students = new List<Student>();
IsWeighted = isWeighted;
}

public void AddStudent(Student student)
Expand Down Expand Up @@ -106,20 +110,30 @@ public void Save()

public virtual double GetGPA(char letterGrade, StudentType studentType)
{
double gpa = 0;
switch (letterGrade)
{
case 'A':
return 4;
gpa = 4;
break;
case 'B':
return 3;
gpa = 3;
break;
case 'C':
return 2;
gpa = 2;
break;
case 'D':
return 1;
gpa = 1;
break;
case 'F':
return 0;
gpa = 0;
break;
default:
throw new ArgumentException("Invalid letter date");
}
return 0;
if (IsWeighted && (studentType == StudentType.Honors || studentType == StudentType.DualEnrolled))
gpa += 1;
return gpa;
}

public virtual void CalculateStatistics()
Expand Down Expand Up @@ -247,7 +261,7 @@ from type in assembly.GetTypes()
if (string.IsNullOrEmpty(gradeBookType))
gradeBookType = "Standard";
else
gradeBookType = Enum.GetName(gradebookEnum, int.Parse(gradeBookType));
gradeBookType = Enums.GradeBookType.GetName(gradebookEnum, int.Parse(gradeBookType));
}

// Get GradeBook from the GradeBook.GradeBooks namespace
Expand Down
61 changes: 61 additions & 0 deletions GradeBook/GradeBooks/GradeBooks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GradeBook.GradeBooks
{
public class StandardGradeBook : BaseGradeBook
{
public StandardGradeBook(string name, bool isWeighted) : base(name, isWeighted)
{
Type = Enums.GradeBookType.Standard;
}
}
public class RankedGradeBook : BaseGradeBook
{
public RankedGradeBook(string name, bool isWeighted) : base(name, isWeighted)
{
Type = Enums.GradeBookType.Ranked;
}

public override char GetLetterGrade(double averageGrade)
{
if (Students.Count < 5)
{
throw new InvalidOperationException("Ranked grading requires at least 5 students.");
}
var sortedGrades = Students.Select(s => s.AverageGrade).OrderByDescending(g => g).ToList();
int threshold = (int)Math.Ceiling(Students.Count * 0.2);
if (averageGrade >= sortedGrades[threshold - 1])
return 'A';
if (averageGrade >= sortedGrades[threshold *2 - 1])
return 'B';
if (averageGrade >= sortedGrades[threshold *3 - 1])
return 'C';
if (averageGrade >= sortedGrades[threshold * 4 - 1])
return 'D';
return 'F';
}
public override void CalculateStatistics()
{
if (Students.Count < 5)
{
Console.WriteLine("Ranked grading requires at least 5 students.");
return;
}
else base.CalculateStatistics();
}
public override void CalculateStudentStatistics(string name)
{
if (Students.Count < 5)
{
Console.WriteLine("Ranked grading requires at least 5 students.");
return;
}
else base.CalculateStudentStatistics(name);
}

}
}
30 changes: 24 additions & 6 deletions GradeBook/UserInterfaces/StartingUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,31 @@ public static void CommandRoute(string command)
public static void CreateCommand(string command)
{
var parts = command.Split(' ');
if (parts.Length != 2)
if (parts.Length != 4)
{
Console.WriteLine("Command not valid, Create requires a name.");
Console.WriteLine("Command not valid, Create requires a name, type of gradebook, if it's weighted (true / false).");
return;
}
var name = parts[1];
BaseGradeBook gradeBook = new BaseGradeBook(name);
Console.WriteLine("Created gradebook {0}.", name);
GradeBookUserInterface.CommandLoop(gradeBook);
string type = parts[2].ToLower();
bool isWeighted = bool.Parse(parts[3].ToLower());
if (type == "standard")
{
BaseGradeBook gradeBook = new StandardGradeBook(name, isWeighted);
Console.WriteLine($"Created {type} gradebook named {name} (weighted: {isWeighted})");
GradeBookUserInterface.CommandLoop(gradeBook);
}
else if (type == "ranked")
{
BaseGradeBook gradeBook = new RankedGradeBook(name, isWeighted);
Console.WriteLine($"Created {type} gradebook named {name} (weighted: {isWeighted})");
GradeBookUserInterface.CommandLoop(gradeBook);
}
else
{
Console.WriteLine($"{type} is not a supported type of gradebook, please try again");
return;
}
}

public static void LoadCommand(string command)
Expand All @@ -67,7 +83,9 @@ public static void HelpCommand()
Console.WriteLine();
Console.WriteLine("GradeBook accepts the following commands:");
Console.WriteLine();
Console.WriteLine("Create 'Name' - Creates a new gradebook where 'Name' is the name of the gradebook.");
Console.WriteLine("Create 'Name' 'Type' 'Weighted' - Creates a new gradebook where 'Name' is the name of the gradebook, " +
"'Type' is what type of grading it should use, " +
"and 'Weighted' is whether or not grades should be weighted (true or false).");
Console.WriteLine();
Console.WriteLine("Load 'Name' - Loads the gradebook with the provided 'Name'.");
Console.WriteLine();
Expand Down