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

Create a class that provides a property for an instance variable based on the ex

ID: 3764035 • Letter: C

Question

Create a class that provides a property for an instance variable based on the example in this question.

(Please integrate it into the code so I know where it goes)

Here is the example:

// Fig. 4.7: GradeBook.cs
2 // GradeBook class that contains a courseName instance variable,
3 // and a property to get and set its value.
4 using System;
5
6 public class GradeBook
7 {
8 private string courseName; // course name for this GradeBook
9
10 // property to get and set the course name
11 public string CourseName
12 {
13 get
14 {
15 return courseName;
16 } // end get
17 set
18 {
19 courseName = value;
20 } // end set
21 } // end property CourseName
22
23 // display a welcome message to the GradeBook user
24 public void DisplayMessage()
25 {
26 // use property CourseName to get the
27 // name of the course that this GradeBook represents
28 Console.WriteLine( "Welcome to the grade book for {0}!", CourseName); // display property CourseName
29
30 } // end method DisplayMessage
31 } // end class GradeBook

Explanation / Answer

See the below C# source code for a property for an instance variable created in GradeBookTest and written comment for to understand the main method calling in below method.

public class GradeBookTest
{
// Main method begins program execution
public static void Mainstring[] args )
{
// create a GradeBook object and assign it to myGradeBook
GradeBook myGradeBook = new GradeBook();

// display initial value of CourseName
Console.WriteLine( "Initial course name is: '{0}' ", myGradeBook.CourseName );

// prompt for and read course name
Console.WriteLine( "Please enter the course name:" );
myGradeBook.CourseName = Console.ReadLine(); // set CourseName
Console.WriteLine(); // output a blank line

// display welcome message after specifying course name
myGradeBook.DisplayMessage();
} // end Main
} // end class GradeBookTest

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