Student 类
(1)字段与属性:姓名、学号、成绩
(2)构造方法:无参、有参(学号姓名2个参、3个参)
(3)方法:学习——每学习1小时,成绩+1;运动——输出谁正在运动
代码如下,其中run不知道是不是这个意思。有帮助麻烦点个采纳【本回答右上角】,谢谢~~有其他问题可以继续交流~
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp1
{
class Student
{
public string Name { get; set; }
public string No { get; set; }
public double Score { get; set; }
public Student() : this(null, null, 0) { }
public Student(string Name, string No) : this(Name, No, 0)
{ }
public Student(string Name, string No, double Score)
{
this.No = No;
this.Name = Name;
this.Score = Score;
}
public void Learning()
{
this.Score += 1;
}
public void Run()
{
Console.WriteLine($"{Name}正在运动");
}
}
class Program
{
static void Main(string[] args)
{
var stu = new Student("小明", "111", 60);
Console.WriteLine(stu.Name + "成绩:" + stu.Score);
stu.Learning();
Console.WriteLine(stu.Name + "成绩:" + stu.Score);
stu.Run();
Console.ReadKey();
}
}
}