0% found this document useful (0 votes)
4 views6 pages

Code-Requirements-Markings

Uploaded by

NITHISH PU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Code-Requirements-Markings

Uploaded by

NITHISH PU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

using System;

using System.Collections.Generic;

interface IVolunteer
{
string Name { get; }
int HoursLogged { get; set; }
string GetDescription();
}

class Volunteer : IVolunteer


{
public string Name { get; set; }
public int HoursLogged { get; set; }

public string GetDescription()


{
return $"{Name} - Hours logged: {HoursLogged}";
}
}

abstract class VolunteerDecorator : IVolunteer


{
protected IVolunteer _volunteer;

public VolunteerDecorator(IVolunteer volunteer)


{
_volunteer = volunteer;
}

public virtual string Name => _volunteer.Name;


public virtual int HoursLogged
{
get => _volunteer.HoursLogged;
set => _volunteer.HoursLogged = value;
}

public abstract string GetDescription();


}

class LeaderVolunteer : VolunteerDecorator


{
public LeaderVolunteer(IVolunteer volunteer) : base(volunteer) { }
public override string GetDescription()
{
return $"{_volunteer.GetDescription()} - Role: Leader";
}
}

class NewcomerVolunteer : VolunteerDecorator


{
public NewcomerVolunteer(IVolunteer volunteer) : base(volunteer) { }

public override string GetDescription()


{
return $"{_volunteer.GetDescription()} - Status: Newcomer";
}
}

// The other classes remain unchanged but will now use IVolunteer
sealed class RegisterVolunteer
{
public void Reg()
{
Console.Write("Enter volunteer name: ");
string name = Console.ReadLine();
// Register a basic volunteer initially
Program.volunteers.Add(new Volunteer { Name = name, HoursLogged = 0 });
Console.WriteLine("Volunteer registered successfully!");
}
}

sealed class CreateEvent


{
public void Create()
{
Console.Write("Enter event title: ");
string title = Console.ReadLine();
Program.events.Add(new Event { Title = title });
Console.WriteLine("Event created successfully!");
}
}

sealed class VolunteerSignUp


{
public void Sign()
{
Console.Write("Enter event title to sign up: ");
string eventTitle = Console.ReadLine();
Console.Write("Enter volunteer name: ");
string volunteerName = Console.ReadLine();

Event evnt = Program.events.Find(e => e.Title.Equals(eventTitle,


StringComparison.OrdinalIgnoreCase));
if (evnt != null)
{
// Here you can add logic to decide if the volunteer is a Leader or Newcomer
IVolunteer volunteer = new Volunteer { Name = volunteerName, HoursLogged = 0 };
// For example, we can decorate the volunteer as a Leader
volunteer = new LeaderVolunteer(volunteer);
evnt.Volunteers.Add(volunteer);
Console.WriteLine("Volunteer signed up for event!");
}
else
{
Console.WriteLine("Event not found!");
}
}
}

sealed class LogHours


{
public void Log()
{
Console.Write("Enter event title: ");
string eventTitle = Console.ReadLine();
Console.Write("Enter volunteer name: ");
string volunteerName = Console.ReadLine();
Console.Write("Enter hours logged: ");
int hours = Convert.ToInt32(Console.ReadLine());

Event evnt = Program.events.Find(e => e.Title.Equals(eventTitle,


StringComparison.OrdinalIgnoreCase));
if (evnt != null)
{
IVolunteer volunteer = evnt.Volunteers.Find(v => v.Name.Equals(volunteerName,
StringComparison.OrdinalIgnoreCase));
if (volunteer != null)
{
volunteer.HoursLogged += hours;
Console.WriteLine("Hours logged successfully!");
}
else
{
Console.WriteLine("Volunteer not found in this event!");
}
}
else
{
Console.WriteLine("Event not found!");
}
}
}

sealed class ViewCurrentEvents


{
public void Cur()
{
Console.WriteLine("Current Events:");
foreach (var evnt in Program.events)
{
Console.WriteLine(evnt.Title);
}
}
}

sealed class GenerateReport


{
public void Rep()
{
Console.Write("Enter event title for report: ");
string eventTitle = Console.ReadLine();

Event evnt = Program.events.Find(e => e.Title.Equals(eventTitle,


StringComparison.OrdinalIgnoreCase));
if (evnt != null)
{
Console.WriteLine($"Volunteers for {eventTitle}:");
foreach (var volunteer in evnt.Volunteers)
{
Console.WriteLine(volunteer.GetDescription());
}
}
else
{
Console.WriteLine("Event not found!");
}
}
}

class Event
{
public string Title { get; set; }
public List<IVolunteer> Volunteers { get; set; } = new List<IVolunteer>();
}

class Program
{
public static List<IVolunteer> volunteers = new List<IVolunteer>();
public static List<Event> events = new List<Event>();

static void Main(string[] args)


{
int choice;
do
{
Console.WriteLine("\nVolunteer Management System");
Console.WriteLine("1. Register Volunteer");
Console.WriteLine("2. Create Event");
Console.WriteLine("3. Volunteer Sign Up");
Console.WriteLine("4. Log Hours");
Console.WriteLine("5. View Current Events");
Console.WriteLine("6. Generate Report");
Console.WriteLine("7. Exit");
Console.Write("Enter your choice: ");
choice = Convert.ToInt32(Console.ReadLine());

switch (choice)
{
case 1:
RegisterVolunteer regVolunteer = new RegisterVolunteer();
regVolunteer.Reg();
break;
case 2:
CreateEvent createEvent = new CreateEvent();
createEvent.Create();
break;
case 3:
VolunteerSignUp volunteerSignUp = new VolunteerSignUp();
volunteerSignUp.Sign();
break;
case 4:
LogHours logHours = new LogHours();
logHours.Log();
break;
case 5:
ViewCurrentEvents viewEvents = new ViewCurrentEvents();
viewEvents.Cur();
break;
case 6:
GenerateReport generateReport = new GenerateReport();
generateReport.Rep();
break;
case 7:
Console.WriteLine("Exiting...");
break;
default:
Console.WriteLine("Invalid choice. Please try again.");
break;
}
} while (choice != 7);
}
}

You might also like