Created Book.cs for class creation
parent
4fe8c1f2bb
commit
eedc0c5329
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -7,24 +7,29 @@ namespace GradeBook
|
|||
{
|
||||
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};
|
||||
grades.Add(56.1);
|
||||
double result = 0;
|
||||
var highGrade = double.MinValue;
|
||||
var lowGrade = double.MaxValue;
|
||||
|
||||
foreach (var number in grades)
|
||||
{
|
||||
highGrade = Math.Max(number, highGrade);
|
||||
lowGrade = Math.Min(number, lowGrade);
|
||||
|
||||
result += number;
|
||||
}
|
||||
result /= grades.Count;
|
||||
|
||||
System.Console.WriteLine($"The average grade is {result}");
|
||||
|
||||
if (args.Length > 0)
|
||||
{
|
||||
Console.WriteLine($"Hello, {args[0]}!");
|
||||
} else{
|
||||
Console.WriteLine("Where is the name?");
|
||||
}
|
||||
Console.WriteLine($"The average grade is {result:N1}");
|
||||
Console.WriteLine($"The highest grade is {highGrade:N1}");
|
||||
Console.WriteLine($"The lowest grade is {lowGrade:N1}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue