C# Programming Help


have:

program.cs

using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.threading.tasks;

namespace homework_assign_4
{
    class program
    {
        static void main(string[] args)
        {
            student student1 = new student("jack", "black");
            student1.addcourse("cis 150");
            student1.addcourse("cis 151");

            student student2 = new student("john", "smith");
            student1.addcourse("its 150");
            student1.addcourse("its 151");
            student1.addcourse("its 152");
            student1.addcourse("its 153");
            student1.addcourse("its 154");

            student student3 = new student("jane", "doe");
            student1.addcourse("bio 150");
            student1.addcourse("bio 151");
            student1.addcourse("bio 152");
            student1.addcourse("bio 153");
            student1.addcourse("bio 154");
            student1.addcourse("bio 155");
            student1.addcourse("bio 156");

            console.writeline(string.format("{0} in {1} status", student1.getfullname(false), student1.getstudentcourseload()));

            console.writeline(string.format("{0} in {1} status", student2.getfullname(false), student2.getstudentcourseload()));

            console.writeline(string.format("{0} in {1} status", student3.getfullname(false), student3.getstudentcourseload()));

            console.readkey();
        }
    }
}

, student class

using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.threading.tasks;

namespace homework_assign_4
{
    public class student
    {
        public string firstname { get; set; }
        public string lastname { get; set; }

        public list<string> courses { get; set; }

        public student(string _firstname, string _lastname)
        {
            firstname = _firstname;
            lastname = _lastname;
            courses = new list<string>();
        }

        public string getfullname(bool showlastnamefirst)
        {
            string fullname;

            if (showlastnamefirst)
            {
                fullname = string.format("{0}, {1}", lastname, firstname);
            }
            else
            {
                fullname = string.format("{0} {1}", firstname, lastname);
            }

            return fullname;
        }

        public bool addcourse(string coursename)
        {
            bool course = true;

            if (courses.count < 7)
            {
                courses.add(coursename);
                return course = true;
            }
            else
            {
                return course = false;
            }
        }

        public string getstudentcourseload()
        {
            string studentcoursestatus;
            
            switch (courses.count)
            {
                case 1:
                    
                case 2:
                    
                case 3:
                    
                case 4:
                    studentcoursestatus = "part-time";
                    break;
                case 5:
                    
                case 6:
                    studentcoursestatus = "full-time";
                    break;
                case 7:
                    studentcoursestatus = "overload";
                    break;
                default:
                    studentcoursestatus = "unknown";
                    break;
            }
            return studentcoursestatus;
        }
    }
}

get:

should get:

how that?

your previous code(working):

        public bool addcourse(string coursename)         {             bool course = true;              if (courses.count < 7)             {                 courses.add(coursename);                 return course = true;             }             else             {                 return course = false;             }         }

your current code (not working):

        public bool addcourse(string coursename)         {             string course;              if (courses.count < 7)             {                 courses.add(coursename);                 return course = true;             }             else             {                 return course = false;             }         }
see difference?



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

How to Share webservice object to all user