Question: Visual Studio C# - Programming Can someone help with Steps 1-3 to be added to my code I have below. Department.cs needs to be created

Visual Studio C# - Programming

Can someone help with Steps 1-3 to be added to my code I have below. Department.cs needs to be created following these instructions. The outcome should be this:

Visual Studio C# - Programming Can someone help with Steps 1-3 to

-Step 1: In your YourInitialsClasses folder, create a C# class named Department with the properties as shown in below:

DeptCode as string (suppose it would the primary key in case of a database table)

DeptName as string

Budget as decimal

Courses as a virtual List : (it means that the Courses property for each department will be a list of Course objects offered by a particular department)

Hints: You may declare the Courses property using the following syntax:

=

public virtual List Courses { get; set; }

You may wonder about the virtual keyword here. In this exercise the virtual declaration is not needed; but we will need it when we develop similar classes in MVC Entity Framework later in our course. So, I recommend that you use the keyword "virtual" here.

-Step 2: After declaring the properties, develop a constructor for the Department class:

This constructor should accept the values of all properties as parameters. Observe the Courses property. Here

the constructor will expect a list of Course objects.

-Step 3: At the least, you need to develop two methods as follows:

An instance method named NumOfListings that will return the number of courses in a Department. This is very simple. Just return the Courses.Count(); inside this method. To be more specific you may also use the syntax this.Courses.Count(); so that you do not get confused between all courses and the courses contained in an instance method of a department object. Note: The word this, though optional, can only be used inside any instance methods of a class.

Create the ToString() method by overriding the inherited ToString() method from the Object class. The overridden ToString method should return a formatted string. Prepare the formatted string such a way so that when the consumer can use Console.WriteLine(aDepartmentObject.ToString()) method of a Department object to display the information as shown below. Hints: In the overridden ToString() method you may return a formatted string as follows:

 public override string ToString() 
 { 
 string deptDesc = string.Format("DeptCode: {0} \tName: {1} \tBudget: {2:C} \t#OfCourses: {3}", 
 DeptCode, DeptName, Budget, NumCourses()); 
 return deptDesc; 
 } 

The code I have so far is 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;

} 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("\t{0} \t{1} \t{2} \t{3} \t{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

{

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 Courses = new List()

{

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 x = new List();

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 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();

}

}

Dept Code ACCT Name Accounting Budget $1,123,456.00 Courses

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!