C# Write a program that creates a ProfessorRating class consisting of professor
ID: 3911406 • Letter: C
Question
C#
Write a program that creates a ProfessorRating class consisting of professor ID and three ratings. The three ratings are used to evaluate easiness, helpfulness, and clarity. The value for each rating is in the range of 1 to 5, with 1 is the lowest and 5 is the highest. Test this class in Program class, Main() method, allow the user to enter the value for each rating. Include appropriate constructors and properties in ProfessorRating class. Do not allow the ID to be changed after an object has been constructed. Provide a method in the ProfessorRating class to compute and return the overall rating average, and ToString() method to display all ratings and the average rating formatted with no decimal points
Explanation / Answer
using System;
class ProfessorRating
{
private int professorID;
private int rating1,rating2,rating3;
public ProfessorRating(int professorID,int rating1,int rating2,int rating3)//constructor
{
this.professorID = professorID;
this.rating1 = rating1;
this.rating2 = rating2;
this.rating3 = rating3;
}
//properties
public int ProfessorID
{
get{ return professorID;}
}
public int Rating1
{
set{ rating1 = value; }
get{ return rating1;}
}
public int Rating2
{
set{ rating2 = value; }
get{ return rating2;}
}
public int Rating3
{
set{ rating3 = value; }
get{ return rating3;}
}
public double averageRating()
{
return (double)(rating1 +rating2+rating3)/3;
}
public string ToString()
{
string s = string.Format(" Overall Average Rating : {0:0}", averageRating());
return "Professor ID : "+ ProfessorID +" Rating 1 : "+Rating1 +" Rating 2 : "+Rating2 +" Rating 3 : "+Rating3+ s;
}
}
public class Test
{
public static void Main()
{
Console.WriteLine("Enter the professor ID : ");
int pId = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the rating 1 for easiness : ");
int rating1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the rating 2 for helpfulness : ");
int rating2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the rating 3 for clarity : ");
int rating3 = Convert.ToInt32(Console.ReadLine());
ProfessorRating pr = new ProfessorRating(pId,rating1,rating2,rating3);
Console.WriteLine(pr.ToString());
}
}
Output:
Enter the professor ID :1006
Enter the rating 1 for easiness :4
Enter the rating 2 for helpfulness :3
Enter the rating 3 for clarity :4
Professor ID : 1006
Rating 1 : 4
Rating 2 : 3
Rating 3 : 4
Overall Average Rating : 4
Do ask if any doubt. Please upvote.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.