C# Case_3 考试评级

达成效果:
用户输入一门成绩,然后根据成绩来判断是什么等级的
用户输入两门成绩,然后根据成绩来判断是什么等级的
用户输入三门成绩,然后根据成绩来判断是什么等级的

提示用户输入哪门成绩
提示用户需要输入数字
输出等级成绩

    class Program
    {
        static void Main(string[] args)
        {
            Student stu = new Student();
            int x, y, z;
            while (true)
            {
                Console.WriteLine("请输入科目的个数(1-3):");
                string num = Console.ReadLine();
                switch (num)
                {
                    case "1":
                        Console.WriteLine("请输入一门成绩:");
                        x = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("成绩的等级是:{0}",stu.lvl(x));
                        Console.WriteLine();
                        break;
                    case "2":
                        Console.WriteLine("请输入两门成绩:");
                        x = Convert.ToInt32(Console.ReadLine());
                        y = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("成绩的等级是:{0}", stu.lvl(x, y));
                        Console.WriteLine();
                        break;
                    case "3":
                        Console.WriteLine("请输入三门成绩:");
                        x = Convert.ToInt32(Console.ReadLine());
                        y = Convert.ToInt32(Console.ReadLine());
                        z = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("成绩的等级是:{0}", stu.lvl(x, y, z));
                        Console.WriteLine();
                        break;
                }
            }
        }
    }
    class Student
    {
        public string lvl(int x)
        {
            if (x >= 90)
            {
                return "A";
            }
            else if (x >= 60)
            {
                return "B";
            }
            else
            {
                return "C";
            }
        }
        public string lvl(int x, int y)
        {
            int z = x + y;
            if (z >= 180)
            {
                return "A";
            }
            else if (z >= 120)
            {
                return "B";
            }
            else
            {
                return "C";
            }
        }
        public string lvl(int x,int y,int z)
        {
            if (x + y + z >= 270)
            {
                return "A";
            }
            else if (x + y + z >= 180)
            {
                return "B";
            }
            else
            {
                return "C";
            }
        }
    }

运行结果;

 

posted @ 2020-09-24 17:54  ___lucky  阅读(158)  评论(0)    收藏  举报