#nullable disable
using System.Security.Cryptography;
namespace ConsoleIdeaTest
{
public enum Talent
{
天才,
聪明,
愚钝,
抱歉
}
public enum Attitude
{
刻苦,
一般,
吊儿郎当
}
class Program
{
static void Main(string[] args)
{
var family1 = new Family();
var family2 = new Family();
Func fun1 = new Func(family1.GiveBirth);
Func fun2 = new Func(family2.GiveBirth);
var school1 = new School();
var logger1 = new Logger();
Action log1 = new Action(logger1.Log);
Student stu1 = school1.GotoSchool(fun1,log1);
var logger2 = new Logger();
Action log2 = new Action(logger2.Log);
Student stu2 = school1.GotoSchool(fun2,log2);
Console.WriteLine("====================================================================");
Console.WriteLine("学生1的编号为:" + stu1.ID);
Console.WriteLine("学生1的姓名为:" + stu1.Mychild.Name);
Console.WriteLine("学生1本学期的成绩为:{0}", stu1.Score);
Console.WriteLine("学生1学习态度为:{0}", stu1.StudyAttitude);
Console.WriteLine("学生1天赋为:{0}n", stu1.Mychild.MyTalent);
Console.WriteLine("学生2的编号为:" + stu2.ID);
Console.WriteLine("学生2的姓名为:" + stu2.Mychild.Name);
Console.WriteLine("学生2本学期的成绩为:{0}", stu2.Score);
Console.WriteLine("学生2学习态度为:{0}", stu2.StudyAttitude);
Console.WriteLine("学生2天赋为:{0}n", stu2.Mychild.MyTalent);
Console.ReadKey();
}
public static int GetRandomSeed()
{
byte[] bytes = new byte[4];
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(bytes);
return BitConverter.ToInt32(bytes, 0);
}
public static int GetRandomNum(int a, int b)
{
Random random = new Random(GetRandomSeed());
int r = random.Next(a,b);
return r;
}
}
class Logger
{
public void Log(Student stu)
{
Console.WriteLine("{0}同学在{1}的考试中取得了{2}分的成绩。n",stu.Mychild.Name,DateTime.UtcNow,stu.Score);
}
}
class Children
{
public Children(string initName)
{
Name = initName;
}
public string Name { get; set; }
private Talent mytalent;
public Talent MyTalent
{
get { return mytalent; }
set { mytalent = value; }
}
}
class Student
{
public Children Mychild { get; set; }
public Student(int initID)
{
ID = initID;
}
public int ID { get; set; }
private Attitude studyattitude;
public Attitude StudyAttitude
{
get { return studyattitude; }
set { studyattitude = value; }
}
public double Score { get; set; }
}
class Family
{
public Children GiveBirth()
{
Console.WriteLine("请输入小朋友的名字:");
var child = new Children(Console.ReadLine());
int gift = Program.GetRandomNum(0,100);
if (gift <= 25)
{
child.MyTalent = Talent.抱歉;
}
if (gift > 25 && gift <= 50)
{
child.MyTalent = Talent.愚钝;
}
if (gift > 50 && gift <= 75)
{
child.MyTalent = Talent.聪明;
}
if (gift > 75)
{
child.MyTalent = Talent.天才;
}
return child;
}
}
class School
{
public Student GotoSchool(Func goStudy,Action logCallBack)
{
Children child = goStudy.Invoke();
Console.WriteLine("请输入学生的编号:");
var stu = new Student(Convert.ToInt32(Console.ReadLine()));
int studyhard = Program.GetRandomNum(0,100);
if (studyhard >= 66)
{
stu.StudyAttitude = Attitude.刻苦;
}
if (studyhard >= 33 && studyhard < 66)
{
stu.StudyAttitude = Attitude.一般;
}
if (studyhard < 33)
{
stu.StudyAttitude = Attitude.吊儿郎当;
}
stu.Mychild = child;
double grades = 0;
switch (stu.StudyAttitude)
{
case Attitude.刻苦: grades = Program.GetRandomNum(66, 100); break;
case Attitude.一般: grades = Program.GetRandomNum(33, 66); break;
case Attitude.吊儿郎当: grades = Program.GetRandomNum(0, 33); break;
default: grades = Program.GetRandomNum(0, 10); break;
}
double lucky = 0;
switch (child.MyTalent)
{
case Talent.天才: lucky = Program.GetRandomNum(75, 100); break;
case Talent.聪明: lucky = Program.GetRandomNum(50, 75); break;
case Talent.愚钝: lucky = Program.GetRandomNum(25, 50); break;
case Talent.抱歉: lucky = Program.GetRandomNum(0, 25); break;
default: grades = Program.GetRandomNum(0, 10); break;
}
stu.Score = grades * 0.8 + lucky * 0.2;
if(stu.Score > 60)
{
logCallBack(stu);
}
return stu;
}
}
}