Answer to Question #233937 in C# for Phamela

Question #233937

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:

public string getName()

//Returns the name of the recipient

public int getHours()

//Returns the hours outstanding

public void setHours(int H)

//Set the hours outstanding

public void displayRecipient()

//Display the name and number of hours left for a recipient

In the application class (main method in the program.cs file), do the following:

 Create three instances of Recipient, for Xola, David and Sandy. Xola and Sandy will start 

with 90 hours, while David starts with 60 hours.

 Change the number of hours outstanding, after each have worked the following number of 

hours

o Xola – 20 hours

o David – 10 hours

o Sandy – 16 hours

 Use the displayRecipient() method to display the names and hours left for each 

Recipient


1
Expert's answer
2021-09-06T14:14:04-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;


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("{0}, {1} hours left for a recipient.", Name, Hours);
        }
    }




    class Program
    {
        static void Main(string[] args)
        {
            //In the application class (main method in the program.cs file), do the following:


            //Create three instances of Recipient, for Xola, David and Sandy. Xola and Sandy will start  
            //with 90 hours, while David starts with 60 hours.
            Recipient Xola = new Recipient("Xola");
            Recipient David = new Recipient("David");
            Recipient Sandy = new Recipient("Sandy");
            
            //Change the number of hours outstanding, after each have worked the following number of hours


            //Xola – 20 hours
            Xola.setHours(20);
            //David – 10 hours
            David.setHours(10);
            //Sandy – 16 hours
            Sandy.setHours(16);
            //Use the displayRecipient() method to display the names and hours left for each  Recipient 
            Xola.displayRecipient();
            David.displayRecipient();
            Sandy.displayRecipient();




            Console.ReadLine();
        }
    }
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS