This questions pertains to useing C# programming Create a class called average t
ID: 3680826 • Letter: T
Question
This questions pertains to useing C# programming
Create a class called average that includes three pieces of information as automatic properties—a score1 (type int), a score2 (type int), and a score3 (type int). Your class should have a constructor that initializes the three automatic properties and assumes that the values provided are correct. In the constructor you should assign the three values passed into the constructor to Score1, Score2 and Score3. Provide a method calculateAverage that adds all three together and computes an average of the three entries and computes any remainder of the integer division. Provide a method DisplayAverage that displays the output as shown in the example below. Note that there are no values input to the console, the three score values are passed into the constructor from Main.
In the default wrapper class named averageTest and containing Main write the code in Main that demonstrates class average’s capabilities.
The output might look like this:
The average of 3, 6, 4 is 4 with a remainder of 1
Press any key to continue . . .
Explanation / Answer
using System;
class Average
{
private int score1;
private int score2;
private int score3;
int avg, r;
public Average(int a,int b, int c)
{
score1=a;
score2=b;
score3=c;
}
public int _Score1
{
get
{
return this.score1;
}
set
{
this.score1 = value;
}
}
public int _Score2
{
get
{
return this.score2;
}
set
{
this.score2 = value;
}
}
public int _Score3
{
get
{
return this.score3;
}
set
{
this.score3 = value;
}
}
public void calculateAverage()
{
this.avg= (_Score1+_Score2+_Score3)/3;
this.r=(_Score1+_Score2+_Score3)%3;
}
public void displayAverage()
{
calculateAverage();
Console.WriteLine("Average of: {0}, {1}, {2} is {3} with remainder of {4} ", this.score1,this.score2, this.score3 ,this.avg, this.r);
}
}
public class Test
{
public static void Main()
{
Average a=new Average(3,6,4);
a.displayAverage();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.