Объяснения:
Описаны три класса: Student [Базовый], MaleStudent, FemaleStudent.
Реализована логика расчета стипендии, учтена возможность смены параметров студентами (в том числе и пола).
Код:
using System;
namespace Durka
{
class Program
{
static void Main(string[] args)
{
var male = Student.CreateMaleStudent("Cidodzy Ohlazhdai Blackjackovich", "1GT-b", 5f);
var female = Student.CreateFemaleStudent("Viktoria Nya Victorovna", "1ZT-b", 4.8f);
Console.WriteLine(male.GetPaymentAmount());
Console.WriteLine(female.GetPaymentAmount());
}
}
///
/// Class which describes students in general
///
public abstract class Student
{
public string Names { get; set; }
public string Group { get; set; }
public float MeanGrade {
get => _meanGrade;
set
{
if (value > 5f || value < 0f)
{
throw new ArgumentException("MeanGrade must be in [0; 5] range");
}
_meanGrade = value;
}
}
private float _meanGrade;
///
/// Method for calculating amount of students payment depending on inner class params such as sex, etc.
///
/// double
public abstract double GetPaymentAmount();
///
/// Method for changing current sex to Male
///
/// MaleStudent class object
public abstract MaleStudent changeSexToMale();
///
/// Method for changing current sex to Female
///
/// FemaleStudent class object
public abstract FemaleStudent changeSexToFemale();
public static MaleStudent CreateMaleStudent(string names, string group, float meanGrade)
{
return new MaleStudent(names, group, meanGrade);
}
public static FemaleStudent CreateFemaleStudent(string names, string group, float meanGrade)
{
return new FemaleStudent(names, group, meanGrade);
}
///
/// Class which describes Male students
///
public class MaleStudent : Student
{
protected internal MaleStudent(string names, string group, in float meanGrade)
{
Names = names;
Group = group;
MeanGrade = meanGrade;
}
public static float mul = 2000f;
public override double GetPaymentAmount()
{
return MeanGrade > 4 ? mul : 0;
}
public sealed override MaleStudent changeSexToMale()
{
return this;
}
public sealed override FemaleStudent changeSexToFemale()
{
return new FemaleStudent(Names, Group, MeanGrade);
}
}
///
/// Class which describes Female students
///
public class FemaleStudent : Student
{
protected internal FemaleStudent(string names, string group, in float meanGrade)
{
Names = names;
Group = group;
MeanGrade = meanGrade;
}
public static float mul = 500f;
public override double GetPaymentAmount()
{
return mul * MeanGrade;
}
public sealed override MaleStudent changeSexToMale()
{
return new MaleStudent(Names, Group, MeanGrade);
}
public sealed override FemaleStudent changeSexToFemale()
{
return this;
}
}
}
}