Created Book.cs for class creation

csharp_fundamentals
Jason Zhu 2021-02-16 22:27:58 +00:00
parent bafaa1b11e
commit 6d919686df
2 changed files with 35 additions and 8 deletions

View File

@ -0,0 +1,22 @@
using System.Collections.Generic;
namespace GradeBook
{
class Book
{
private List<double> grades;
private string name;
public Book(string name)
{
this.name = name;
grades = new List<double>();
}
public void AddGrade(double grade)
{
this.grades.Add(grade);
}
}
}

View File

@ -7,24 +7,29 @@ namespace GradeBook
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
var book = new Book("Scott's Grade Book");
book.AddGrade(89.1);
book.AddGrade(90.5);
List<double> grades = new List<double>() {12.7, 10.3, 6.11, 4.1}; List<double> grades = new List<double>() {12.7, 10.3, 6.11, 4.1};
grades.Add(56.1); grades.Add(56.1);
double result = 0; double result = 0;
var highGrade = double.MinValue;
var lowGrade = double.MaxValue;
foreach (var number in grades) foreach (var number in grades)
{ {
highGrade = Math.Max(number, highGrade);
lowGrade = Math.Min(number, lowGrade);
result += number; result += number;
} }
result /= grades.Count; result /= grades.Count;
System.Console.WriteLine($"The average grade is {result}"); Console.WriteLine($"The average grade is {result:N1}");
Console.WriteLine($"The highest grade is {highGrade:N1}");
if (args.Length > 0) Console.WriteLine($"The lowest grade is {lowGrade:N1}");
{
Console.WriteLine($"Hello, {args[0]}!");
} else{
Console.WriteLine("Where is the name?");
}
} }
} }
} }