Please help, the language is C# and I\'m using VS 2015 Create a class called Cou
ID: 3666271 • Letter: P
Question
Please help, the language is C# and I'm using VS 2015
Create a class called Course that contains 4 pieces of information as instance Variables: courseName (datatype string), roomNum (datatype string), numStudents (datatype int), semester (datatype string). Your class should contain a constructor that initializes the 4 instance variables. The Course class should also contain a property for each instance variable with get andset accessors. The property for numStudents should verify that the enrollment is greater than 0. If a negative value is passed in, the set accessor should set the enrollment to 0. Create a second class CourseTest that creates two course objects using the constructor that you developed in the Course class. Display the : courseName, roomNum, numStudents, semester for each Course object. Increase the numStudents for each course using the properties and display again.
Explanation / Answer
using System;
namespace courseapplication
{
class Course
{
private string courseName;
private string roomNum ;
private int numStudents;
private string semester;
public Course(string course, string room, int room, string sem){
courseName=course;
roomNum=room;
numStudents=room;
semester=sem;
}
public void setCourseName(string course){
courseName = course;
}
public string getCourseName(){
return courseName;
}
public void setRoomNum(string room){
courseName = room;
}
public string getRoomNum(){
return roomNum;
}
public void setSemester(string sem){
semester = sem;
}
public string getSemester(){
return semester;
}
public void setNumStudents(int num){
if(num < 0)
numStudents = 0;
else
numStudents = num;
}
public int getNumStudents(){
return numStudents;
}
}
class CourseTest
{
public static void Main()
{
// Create a new Course object:
Course c1 = new Course("CS","1A",3,"first");
Course c2 = new Course("EEE","2B",2,"second");
Console.WriteLine("Course1 Info: {0}, {1}, {2}, {3}", c1.getCourseName(),c1.getRoomNum()
,c1.getNumStudents(),c1.getSemester());
Console.WriteLine("Course1 Info: {0}, {1}, {2}, {3}", c2.getCourseName(),c2.getRoomNum()
,c2.getNumStudents(),c2.getSemester());
c1.setNumStudents(8);
c2.setNumStudents(1);
Console.WriteLine("Course1 Info: {0}, {1}, {2}, {3}", c1.getCourseName(),c1.getRoomNum()
,c1.getNumStudents(),c1.getSemester());
Console.WriteLine("Course1 Info: {0}, {1}, {2}, {3}", c2.getCourseName(),c2.getRoomNum()
,c2.getNumStudents(),c2.getSemester());
}
}