Question

In: Computer Science

Write a program that utilizes a Professor class. A professor has a first name, last name,...

Write a program that utilizes a Professor class. A professor has a first name, last name, affiliation, easiness grade, and a helpfulness grade. Grades range from 1 (lowest) to 5 (highest). The Professor class has two constructors. The first constructor initiates the object with just the first name, the last name, and the affiliation. The default value for easiness and helpfulness grade is 3. The second constructor initiates the object using the first name, the last name, the affiliation, and two grades.

The Professor class must not allow a first name or last name to be changed after instantiation.

The affiliation should be implemented as a property.

The grades should have both an accessor method and a mutator method. The Professor class should have a display method that prints all member variables in an appropriate format. For example, you can print out the first name, the last name, affiliation, and the two grades from the display method.

The Professor class should have a ToString() method. Make sure to override the ToString() method to present something meaningful.

Lastly, you should use the Main() method to demonstrate how the Professor class works. For example, create an instance of the Professor class with one of its two constructors. And then, invoke the display method on the instance.

Were using Visual Studios C# console.

This is the program requirements we are working on.

Can you write comments that explain the steps? Or how you get the result for the steps you write.

Solutions

Expert Solution

Hi

Please find the code below

// Professor class
class Professor
{
// property for Professor
// make FirstName and LastName as readonly to restrict the changes after initialisation
private readonly string FirstName;
private readonly string LastName;
// Affiliation is implemented as property
public string Affiliation { get; set; }
// default value for grades as per the requirement
private int EasinessGrade = 3;
private int HelpfulnessGrade = 3;

// first constructor which takes three parameters
public Professor(string firstName, string lastName, string affiliation)
{
this.FirstName = firstName;
this.LastName = lastName;
this.Affiliation = affiliation;
}

// second constructor which takes five parameters
public Professor(string firstName, string lastName, string affiliation, int easinessGrade, int helpfulnessGrade)
{
this.FirstName = firstName;
this.LastName = lastName;
this.Affiliation = affiliation;
// check for the valide easinesgrade as per the given condition
if (easinessGrade < 1 || easinessGrade > 5)
Console.Write("Grade should be greater than or equal to 1 and less than or equal to 5");
else
this.EasinessGrade = easinessGrade;
// check for the valide helpfullessgrade as per the given condition
if (helpfulnessGrade < 1 || helpfulnessGrade > 5)
Console.Write("Grade should be greater than or equal to 1 and less than or equal to 5");
else
this.HelpfulnessGrade = helpfulnessGrade;
}

//accessor method and a mutator method for Grades
public int GetEasinessGrade()
{
return this.EasinessGrade;
}

//mutator
public void GetEasinessGrade(int easinessGrade)
{
if(easinessGrade <1 || easinessGrade > 5)
{
Console.Write("Grade should be greater than or equal to 1 and less than or equal to 5");
}
else
{
this.EasinessGrade = easinessGrade;
}

}
//accessor
public int GetHelpfulnessGrade()
{
return this.HelpfulnessGrade;
}

//mutator
public void GetHelpfulnessGrade(int helpfulnessGrade)
{
if (helpfulnessGrade < 1 || helpfulnessGrade > 5)
{
Console.Write("Grade should be greater than or equal to 1 and less than or equal to 5");
}
else
{
this.HelpfulnessGrade = helpfulnessGrade;
}

}

// display method to show the content of professor
// this method doesn't return any value
public void Display()
{
//use string interpolation
// print all the details for professor
Console.WriteLine($"First Name:- {this.FirstName}");
Console.WriteLine($"Last Name:- {this.LastName}");
Console.WriteLine($"Affiliation:- {this.Affiliation}");
Console.WriteLine($"Helpfulness Grade:- {this.HelpfulnessGrade}");
Console.WriteLine($"Easiness Grade:- {this.EasinessGrade}");
}

// override ToString method and return a string containing information about professor
public override string ToString()
{
// again use string interpolation
return $"{this.FirstName} {this.LastName} is {this.Affiliation} Professor having Easiness Grade {this.EasinessGrade} and Helpfulness Grade {this.HelpfulnessGrade}";
}
}

// main function to demonstrate the working of professor class

namespace ConsoleApp1
{

class Program
{
// main function
static void Main(string[] args)
{
// create object of professor
Professor professor = new Professor("Mark", "Taylor", "Research", 2, 4);
// use display function to display the professor information
professor.Display();
// use ToString to get the string
var professorString = professor.ToString();
// Print the professorstring
Console.WriteLine(professorString);
}

}

OUTPUT:-

Thanks !

Hope it helps...


Related Solutions

Write a class named Person with data attributes for a person’s first name, last name, and...
Write a class named Person with data attributes for a person’s first name, last name, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number and a Boolean data attribute indicating whether the customer wishes to be on a calling list. Demonstrate an instance of the Customer class in a simple program. Using python
C++ Write a program that asks a teacher to input a student’s first name, last name,...
C++ Write a program that asks a teacher to input a student’s first name, last name, and four test scores. The program should find the average of the four test scores and should then write the following information to a file named “students.txt” last_name first_name average A student's first name of “XX” should be used as a sentinel value and no numeric grades less than 0 or greater than 100 should be accepted.  The program should then read the information in...
Python Code: Write a program to prompt the user to enter a first name, last name,...
Python Code: Write a program to prompt the user to enter a first name, last name, student ID, number of hours completed and GPA for 5 students. Use a loop to accept the data listed below. Save the records in a text file. Write a second program that reads the records from your new text file, then determines if the student qualifies for Dean’s list or probation. Display the records read from the file on screen with appropriate headings above...
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other.
java programming write a program with arrays to ask the first name, last name, middle initial,...
java programming write a program with arrays to ask the first name, last name, middle initial, IDnumber and 3 test scores of 10 students. calculate the average of the 3 test scores. show the highest class average and the lowest class average. also show the average of the whole class. please use basic codes and arrays with loops the out put should look like this: sample output first name middle initial last name    ID    test score1 test score2...
Write a complete C++ program that defines, implements, and utilizes a Lion class and a Pine...
Write a complete C++ program that defines, implements, and utilizes a Lion class and a Pine class. Definition of classes from the implementation of the classes should be split. The program is made of five files: Lion.h, Lion.cpp, Pine.h, Pine.cpp, and TestLionPine.cpp. The components of Lion class are defined in the Lion.h file; however, all constructors and methods should not have any implementation code in this header file. All implementation code, i.e. constructor body and method body, should be written...
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name, that does the following: Create two arrays that will hold related information. You can choose any information to store, but here are some examples: an array that holds a person's name and an array that hold's their phone number an array that holds a pet's name and an array that holds what type of animal that pet is an array that holds a student's...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name, that does the following: Declare an array reference variable called myFavoriteSnacks for an array of String type. Create the array so that it is able to hold 10 elements - no more, no less. Fill the array by having each array element contain a string stating one of your favorite foods/snacks. Note: Only write the name of the snack, NO numbers (i.e. Do not...
Write the pseudocode that prompts the user for their first and last name. Display the first...
Write the pseudocode that prompts the user for their first and last name. Display the first initial of their first name and their last name to the user. Ask the user to input a phone number. The program checks which part of Colorado a phone number is from using the values below. If the second digit of the phone number is one of the below digits, print the phone number and which part of Colorado it is from. If none...
C++ Change the program to take user input for first name and last name for five...
C++ Change the program to take user input for first name and last name for five employees. Add a loop to read the first name and last name. // EmployeeStatic.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <string> #include <iostream> #include <string> using namespace std; class Employee { public:    Employee(const std::string&, const std::string&); // constructor    ~Employee(); // destructor    std::string getFirstName() const; // return first name    std::string getLastName() const; // return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT