Commit 93b2d34b authored by Ahmad Abd's avatar Ahmad Abd

Remove unnecessary files

parent a2915dde
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OOPLab.Exams
{
public class StudentExam
{
private int _score;
public void SetScore(int score)
{
if (score < 0 || score > 100)
{
throw new ArgumentException("Score must be between 0 and 100.");
}
_score = score;
}
public int GetScore()
{
return _score;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OOPLab.Exams
{
public class StudentExamV1
{
public int Grade;
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
using OOPLab;
using OOPLab.Exams;
using System;
Console.WriteLine("ENCAPSULATION — Student portal");
// Before: any caller can assign an invalid value.
StudentExamV1 studentV1 = new StudentExamV1();
studentV1.Grade = 50;
Console.WriteLine($"Initial Grade: {studentV1.Grade}");
studentV1.Grade = 999;
Console.WriteLine($"Invalid Grade is accepted: {studentV1.Grade}");
// After: validated access through public methods.
StudentExam student = new StudentExam();
student.SetScore(90);
Console.WriteLine($"Validated score: {student.GetScore()}");
try
{
student.SetScore(999);
}
catch (ArgumentException ex)
{
Console.WriteLine($"Invalid score rejected: {ex.Message}");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment