In: Computer Science
C# language Question:
You need to write a program for students who receive bursaries in the department, managing the free hours they have to do.
For each recipient you store the recipient’s name and the number of hours outstanding.
All recipients start with 90 hours.
Implement class Recipients which has the private attributes Name and Hours.
In addition to the constructor, the class has the following methods:
public String getName()
// Returns the name of the recipient
public int getHours()
// Returns the hours outstanding
public void setHours(int P)
// Sets the hours outstanding In the application class (main method),
do the following
• Create three instances of Recipients, for Xola, David and Sandy
• Change their number hours outstanding, after each one worked the following time:
o Xola – 15 hours
o David – 10 hours
o Sandy – 20 hours
• Display the total number of hours due by the three recipients (add them up)
Here I have done code in C# which is as per your requirement, let me know in the comment section if you have any queries regarding the below code.
using System.IO;
using System;
class Recipients
{
// private attributes
private string Name;
private int Hours;
// public constructor
public Recipients(string Name)
{
this.Name=Name;
// Set Default Hours
this.Hours=90;
}
// Returns the name of the recipient
public string getName()
{
return Name;
}
// Returns the hours outstanding
public int getHours()
{
return Hours;
}
// Sets the hours outstanding
public void setHours(int P)
{
Hours=Hours-P;
}
static void Main()
{
// Create three instances of Recipients
Recipients first=new Recipients("Xola");
Recipients second=new Recipients("David");
Recipients third=new Recipients("Sandy");
// Change their number hours outstanding
first.setHours(15);
second.setHours(10);
third.setHours(20);
// Print the total number of hours
Console.Write(first.getHours()+second.getHours()+third.getHours());
}
}
Output: