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

Can someone help write the code in the Program.cs, getting a sublist of MKGT fro

ID: 3797405 • Letter: C

Question

Can someone help write the code in the Program.cs, getting a sublist of MKGT from the existing List. I am getting an error that says" inaccessible due to its protection level" The outcome should be this:

Here my code I wrote below

Course.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace CGAsn1.cgClasses

{

class Course

{

int CourseID;

string CourseCode;

string Title;

int CreditHour;

string DeptCode;

public Course(int id, string code, string t, int h, string d)

{

CourseID = id;

CourseCode = code;

Title = t;

CreditHour = h;

DeptCode = d;

}

//Override the Tostring method

public override string ToString()

{

string CourseDesc =

String.Format(" {0} {1} {2} {3} {4}", CourseID, CourseCode, Title, CreditHour, DeptCode);

return CourseDesc;

}

}

}

Program.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using CGAsn1.cgClasses;

namespace CGAsn1.cgClasses

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("Asn1 Part1 Task2: Testing the Course ");

Console.WriteLine("These courses are: ");

Course c1 = new Course(1, "ACCT2000", "Intro to Accounting", 4, "ACCT");

Console.WriteLine(c1.ToString());

{

Course c2 = new Course(2, "ACCT4000", "Cost Accounting", 5, "ACCT");

Console.WriteLine(c2.ToString());

//==============================================================

// Part 2 starts here

// ==========================================================

Console.WriteLine("================================================================================");

Console.WriteLine("Part 2 starts here ");

List<Course> Courses = new List<Course>()

{

new Course(1, "ACCT2000", "Intro to Accounting", 4, "ACCT"),

new Course(2, "ACCT4000", "Cost Accounting", 5, "ACCT"),

new Course(3, "INFS3000", "Intro to Programming", 3, "INFS"),

new Course(4, "INFS3700", "Database System", 4, "INFS"),

new Course(5, "INFS4010", "System Analysis", 6, "IFNS"),

new Course(6, "MKTG1000", "Intro to Marketing", 3, "MKTG"),

new Course(7, "MKTG2000", "Transportation Theory", 4, "MKTG"),

};

Console.WriteLine("Part 2 Task2");

Console.WriteLine("The courses in the List are:");

foreach (Course h in Courses)

{

Console.WriteLine(h.ToString());

}

Console.WriteLine("================================================================================");

Console.WriteLine("Part2 Task3 ");

Console.WriteLine("Create a sublist of courses for DeptCode MKTG from Courses:");

//Run a "LINQ Where" query for DeptCode "MKTG" on Courses and store the result in a List object.

// Name the sublist as MktgCourse

List<Course> x = new List<Course>();

Console.WriteLine("The courses in MktgCourses are: ");

foreach ())

{

Console.WriteLine(h.ToString());

}

Console.ReadLine();

}

}

}

}

}

The courses in the MktgCourses are MKT G1000 Intro to Marketing MKT G2000 Transportation Theory Please hit Enter key to exit MKTG MKTG

Explanation / Answer

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace CGAsn1.cgClasses

{

class Course

{

int CourseID;

string CourseCode;

string Title;

int CreditHour;

string DeptCode;

public Course(int id, string code, string t, int h, string d)

{

CourseID = id;

CourseCode = code;

Title = t;

CreditHour = h;

DeptCode = d;

}
  
    public string getCourseCode(){return CourseCode;}
    public string getDeptCode(){return DeptCode;}
    public int getCourseID(){return CourseID;}

//Override the Tostring method

public override string ToString()

{

string CourseDesc =

String.Format(" {0} {1} {2} {3} {4}", CourseID, CourseCode, Title, CreditHour, DeptCode);

return CourseDesc;

}

}
  
  
    class Program

{

public static void Main(string[] args)

{

Console.WriteLine("Asn1 Part1 Task2: Testing the Course ");

Console.WriteLine("These courses are: ");

Course c1 = new Course(1, "ACCT2000", "Intro to Accounting", 4, "ACCT");

Console.WriteLine(c1.ToString());

{

Course c2 = new Course(2, "ACCT4000", "Cost Accounting", 5, "ACCT");

Console.WriteLine(c2.ToString());

//==============================================================

// Part 2 starts here

// ==========================================================

Console.WriteLine("================================================================================");

Console.WriteLine("Part 2 starts here ");

List<Course> Courses = new List<Course>()

{

new Course(1, "ACCT2000", "Intro to Accounting", 4, "ACCT"),

new Course(2, "ACCT4000", "Cost Accounting", 5, "ACCT"),

new Course(3, "INFS3000", "Intro to Programming", 3, "INFS"),

new Course(4, "INFS3700", "Database System", 4, "INFS"),

new Course(5, "INFS4010", "System Analysis", 6, "IFNS"),

new Course(6, "MKTG1000", "Intro to Marketing", 3, "MKTG"),

new Course(7, "MKTG2000", "Transportation Theory", 4, "MKTG"),

};

Console.WriteLine("Part 2 Task2");

Console.WriteLine("The courses in the List are:");

foreach (Course h in Courses)

{

Console.WriteLine(h.ToString());

}

Console.WriteLine("================================================================================");

Console.WriteLine("Part2 Task3 ");

Console.WriteLine("Create a sublist of courses for DeptCode MKTG from Courses:");

//Run a "LINQ Where" query for DeptCode "MKTG" on Courses and store the result in a List object.

// Name the sublist as MktgCourse

List<Course> x = new List<Course>();

Console.WriteLine("The courses in MktgCourses are: ");
    // the attributes are by default private, so we need to use getter methods

    // instead of directly accessing them
    IEnumerable<Course> queriedCourses = from course in Courses
                               where course.getDeptCode().Equals("MKTG")
                               orderby course.getCourseID()
                               select course;

foreach (Course course in queriedCourses)

{

Console.WriteLine(course.ToString());

}

Console.ReadLine();

}

}

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