Create a console application for the department to record information for students who receive bursaries in the department. For each recipient you need to store the recipient’s name and the number of hours outstanding. Most new recipients start with 90 hours, but there are some exceptions. As recipients works in the department, the number of hours left needs to be updated (decreased) from time to time, based on hours already worked. Implement class Recipient which has private attributes for Name and Hours. Create two constructors, one with a default allocation of 90 hours for a recipient, and the other should accept the number of hours for a recipient. In addition to the constructors, the class should have the following methods:
using System;
namespace RecipientApp
{
class Recipient
{
private string Name;
private int Hours;
public Recipient(string Name)
{
this.Name = Name;
this.Hours = 90;
}
public Recipient(string Name, int Hours)
{
this.Name = Name;
this.Hours = Hours;
}
//Returns the name of the recipient
public string getName()
{
return Name;
}
//Returns the hours outstanding
public int getHours()
{
return Hours;
}
//Set the hours outstanding
public void setHours(int H)
{
this.Hours = H;
}
//Display the name and number of hours left for a recipient
public void displayRecipient()
{
Console.WriteLine("Name: {0} ", Name);
Console.WriteLine("{0} hours left for a recipient", Hours);
}
}
class Program
{
static void Main(string[] args)
{
Recipient XolaRecipient = new Recipient("Xola");
Recipient DavidRecipient = new Recipient("David");
Recipient SandyRecipient = new Recipient("Sandy");
XolaRecipient.setHours(20);
DavidRecipient.setHours(10);
SandyRecipient.setHours(16);
XolaRecipient.displayRecipient();
DavidRecipient.displayRecipient();
SandyRecipient.displayRecipient();
Console.ReadLine();
}
}
}
Comments
Leave a comment