Answer to Question #239395 in C# for Phamela

Question #239395

In the application class (Program.cs), do the following:

Implement the following methods:

static void addRecipient(RecipientList List)

// Requests the name of the student and adds that student to the List

// You may assume that all students are added as Recipients starting with 90 hours

static void updateHours(RecipientList List)

// Requests the name of the student as well as the number of hours worked

// It then updates the hours left

Implement the main method which does the following:

 Ask the user for the number of recipients’ details that needs to be recorded (you can assume

a valid number between 1 and 10).

 Use a loop to obtain the required details from the user (uses addRecipient()).

 Allows the user to update the number of hours for a single student (uses updateHours())

 Displays all the student details from the list


1
Expert's answer
2021-09-20T16:46:20-0400
using System;
using System.Collections.Generic;
namespace RecipientApp
{
    class Recipient
    {
        private string Name;
        private int Hours;




        public Recipient(string n)
        {
            this.Name = n;
            this.Hours = 90;
        }
        public Recipient(string n, int рours)
        {
            this.Name = n;
            this.Hours = рours;
        }




        public void setHours(int H)
        {
            this.Hours = H;
        }




        public string getName()
        {
            return Name;
        }




        public int getHours()
        {
            return Hours;
        }
        public void updateHours(int H)
        {
            this.Hours += H;
        }




       
    }
    class RecipientList
    {
        private List<Recipient> recipients = new List<Recipient>(10);
        public void Add(Recipient addNew)
        {
            if (recipients.Count <= 10)
            {
                recipients.Add(addNew);
            }
        }
        
        public int Count()
        {
            return recipients.Count;
        }
        public void Display()
        {
            for (int i = 0; i < Count(); i++)
            {
                Console.WriteLine("Name: " + recipients[i].getName() + "\n" + "Hours: " + recipients[i].getHours() + "\n");
            }
        }
        public int Find(string Wanted)
        {
            return LinearSearch(Wanted);
        }
        private int LinearSearch(string Wanted)
        {
            for (int i = 0; i < Count(); i++)
            {
                if (recipients[i].getName().CompareTo(Wanted) == 0)
                {
                    return i;
                }
            }
            return -1;
        }
    }



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
APPROVED BY CLIENTS