Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create class Course. Add two self-implemented properties CourseName and Instruct

ID: 3710229 • Letter: C

Question

Create class Course. Add two self-implemented properties CourseName and Instructor. Create a publicly accessible method DisplayInfo to display data stored in these two properties. Do not write any constructors. We will use an object initializer to initialize the properties when a Course object is instantiated. Write a test program to test this class. Create two instances of Courses: csc153 and csc152. Use object initializers to initialize CourseName and Instructor when these two courses are created. For csc153, initialize CourseName to Intro C# and Instructor to Leung. For csc152, initialize CourseName to SAS and Instructor to Orazem. Also write statements to invoke the DisplayInfo method for both courses. Your should get the following output

Course: Intro C#    Instructor: Leung

Course: SAS    Instructor: Orazem

Explanation / Answer

using System;

class Course
{
//self implemented properties
public string CourseName { get; set; }
public string Instructor { get; set; }

public void DisplayInfo()
{
Console.WriteLine("Course : "+CourseName+" Instructor : "+Instructor);
}

public void setProperties(string courseName,string instructor) //object initializer
{
CourseName = courseName;
Instructor = instructor;
}
}
public class Test
{
public static void Main()
{

Course csc153 = new Course();
csc153.setProperties("Intro C#","Leung");
csc153.DisplayInfo();
Course csc152= new Course();
csc152.setProperties("SAS","Orazem");
csc152.DisplayInfo();
}
}

Output:

Course : Intro C# Instructor : Leung
Course : SAS Instructor : Orazem

Do ask if any doubt. Please upvote.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote