C#无法创建实例! [英] C# trouble creating an instance!

查看:80
本文介绍了C#无法创建实例!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!,

我正在编辑一个项目的代码,我坚持创建一个实例!我需要创建一个实例



1.创建三个学生班级实例,所有实例都有不同的学生ID

2.设置三个学生对象中的每一个的名字,姓氏和中间名首字母

3.在CIS 252中注册前两个学生对象

4.写完整每个学生对象的名称以及这些学生是否注册到控制台窗口

5.为三个学生中的每个学生添加一个成绩,总分为100分,获得分数为50,85,以及98

6.写下每个学生对象的全名和每个学生的课程字母等级





我不知道从哪里开始在Program.cs类中!我希望有人能指出我正确的方向做什么!提前谢谢!



现在这是我的Student_.cs课程的代码



Hello!,
I am editing a code for a project and Im stuck at creating a instance! I need to create an instance that

1. Create three instances of the student class, all with different student ids
2. Set the first name, last name, and middle initial for each of the three student objects
3. Enroll the first two student objects in "CIS 252"
4. Write the full name of each student object and whether those students are enrolled to the console window
5. Add a grade to each of the three students with a total possible points of 100 and earned points of 50, 85, and 98
6. Write the full name of each student object and the course letter grade for each student


I have no idea where to even start in the Program.cs class! Im hoping someone can even point me in the right direction to what to do! Thank You in Advance!

Now this is my code for the Student_.cs class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

 namespace Test1_Student_Enroll
{
    public class Student_
    {
        public string Studentid
        {
            get
        {
            throw new System.NotImplementedException();
        }
        set
        {
        }
    }
    public Student_(string newStuID)
    {
        Studentid = newStuID;
    }

    public string FirstName
    {
        get
        {
            throw new System.NotImplementedException();
        }
        set
        {
        }
    }

    public string LastName
    {
        get
        {
            throw new System.NotImplementedException();
        }
        set
        {
        }
    }

    public string MiddleInitial
    {
        get
        {
            throw new System.NotImplementedException();
        }
        set
        {
        }
    }

    public string FullName
    {
        get
        {
            return FirstName + MiddleInitial + LastName;
        }
    }

    public string CurrentEnrolledCourse
    {
        get
        {
            throw new System.NotImplementedException();
        }
        set
        {

        }
    }

    private int pointsearned { get; set; }
    private int pointspossible { get; set; }

    public int CurrentCourseAverage
    {
        get
        {
            return pointsearned / pointspossible;
        }
        set
        {
            if (value >= 0)

                CurrentCourseAverage = 100;
        }
    }

    public string CurrentCourseGrade
    {

        set
        {
            if (CurrentCourseAverage >= 90)
            {
                Console.WriteLine("A");
            }
            else if (CurrentCourseAverage >= 80)
            { // grade must be B, C, D or F
                Console.WriteLine("B");
            }
            else if (CurrentCourseAverage >= 70)
            { // grade must be C, D or F
                Console.WriteLine("C");
            }
            else if (CurrentCourseAverage >= 60)
            { // grade must D or F
                Console.WriteLine("D");
            }
            else
            {
                Console.WriteLine("F");
            }

        }
    }





    public void Enroll(string CurrentEnrolledCourse)
    {



        Console.WriteLine("Course: {0}", CurrentEnrolledCourse);

    }
    public void Drop()
    {
        //stuff
        CurrentEnrolledCourse = null;
        pointspossible = 0;
        pointsearned = 0;
    }


    public void AddGrade(int totalpointspossible, int totalpointsearned)
    {
        int newGrade = pointsearned + totalpointsearned;
        int NewGrade_ = pointspossible = totalpointspossible;

        if (CurrentEnrolledCourse != null)
        {
            return;
        }
        else { }
    }



    public bool IsEnrolled()
    {
        if (CurrentEnrolledCourse != null)
        {
            return false;
        }
        else
        {
            return true;
            }
        }



    }
}





我尝试过的事情:



我一直无法理解但是我卡住了这里



What I have tried:

I haven't been able to figure it out but im stuck here

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test1_Student_Enroll
{
    class Program
    {
        static void Main(string[] args)
        {
            Student_ 100 = new Student("Karen","Stacey",
        }
    }
}

推荐答案

首先,这是你的课程应该开始的:





To start, this is what your class should start out as:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test1_Student_Enroll
{
    public class Student_
    {
        public string  Studentid { get; set; }
        
        public Student_(string newStuID)
        {
            Studentid = newStuID;
        }

        public string FirstName { get; set; }

        public string LastName { get; set; }
     

        public string MiddleInitial { get; set; }
        

        public string FullName
        {
            get
            {
                return FirstName + MiddleInitial + LastName;
            }
        }

        public string CurrentEnrolledCourse { get; set; }
        
        private int pointsearned { get; set; }
        private int pointspossible { get; set; }

        public int CurrentCourseAverage
        {
            get
            {
                return pointsearned / pointspossible;
            }
            set
            {
                if (value >= 0)

                    CurrentCourseAverage = 100;
            }
        }

        public string CurrentCourseGrade
        {

            set
            {
                if (CurrentCourseAverage >= 90)
                {
                    Console.WriteLine("A");
                }
                else if (CurrentCourseAverage >= 80)
                { // grade must be B, C, D or F
                    Console.WriteLine("B");
                }
                else if (CurrentCourseAverage >= 70)
                { // grade must be C, D or F
                    Console.WriteLine("C");
                }
                else if (CurrentCourseAverage >= 60)
                { // grade must D or F
                    Console.WriteLine("D");
                }
                else
                {
                    Console.WriteLine("F");
                }

            }
        }





        public void Enroll(string CurrentEnrolledCourse)
        {
            Console.WriteLine("Course: {0}", CurrentEnrolledCourse);
        }
        public void Drop()
        {
            //stuff
            CurrentEnrolledCourse = null;
            pointspossible = 0;
            pointsearned = 0;
        }


        public void AddGrade(int totalpointspossible, int totalpointsearned)
        {
            int newGrade = pointsearned + totalpointsearned;
            int NewGrade_ = pointspossible = totalpointspossible;

            if (CurrentEnrolledCourse != null)
            {
                return;
            }
            else { }
        }



        public bool IsEnrolled()
        {
            if (CurrentEnrolledCourse != null)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}







in main






in main

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test1_Student_Enroll
{
class Program
{
static void Main(string[] args)
{
    Student_ one = new Student('Karen');
    Student_ two = new Student('Stacy');
    Student_ three = new Student('Steve');

}
}
}






创建学生班级的对象并分配每个学生所需的详细信息。如果您需要注册3名学生,那么您可以创建3个不同的学生类对象,并将相应的数据分配给类对象的属性,您可以单独使用这些对象来保存详细信息。



谢谢,

Sisir Patro
Hi,

Create object of student classes and assign the details that is required for each students. If you need to enroll for 3 students then you can create 3 different object of the student class and assign the respective data to the properties of the class object and you can use the objects separately to save the details.

Thanks,
Sisir Patro


这篇关于C#无法创建实例!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆