Untitled

mail@pastecode.io avatar
unknown
plain_text
22 days ago
6.4 kB
3
Indexable
Never
using System;
using System.Collections.Generic;

public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }

    public virtual void DisplayInfo()
    {
        Console.WriteLine($"Name: {Name}, Age: {Age}");
    }
}

public class Teacher : Person
{
    public string Subject { get; set; }

    public override void DisplayInfo()
    {
        base.DisplayInfo();
        Console.WriteLine($"Subject: {Subject}");
    }
}

public class Student : Person
{
    public int Grade { get; set; }

    public override void DisplayInfo()
    {
        base.DisplayInfo();
        Console.WriteLine($"Grade: {Grade}");
    }
}

public class Employee : Person
{
    public string JobTitle { get; set; }

    public override void DisplayInfo()
    {
        base.DisplayInfo();
        Console.WriteLine($"Job Title: {JobTitle}");
    }
}

public class Principal : Person
{
    public int YearsOfExperience { get; set; }

    public override void DisplayInfo()
    {
        base.DisplayInfo();
        Console.WriteLine($"Years of Experience: {YearsOfExperience}");
    }
}

public class Peon : Person
{
    public string Duty { get; set; }

    public override void DisplayInfo()
    {
        base.DisplayInfo();
        Console.WriteLine($"Duty: {Duty}");
    }
}

class Program
{
    static void Main(string[] args)
    {
        List<Teacher> teachers = new List<Teacher>();
        List<Student> students = new List<Student>();
        List<Employee> employees = new List<Employee>();
        List<Principal> principals = new List<Principal>();
        List<Peon> peons = new List<Peon>();

        bool continueRunning = true;

        while (continueRunning)
        {
            Console.WriteLine("\nWhat would you like to do? (teacher/student/employee/principal/peon/show record/nothing): ");
            string choice = Console.ReadLine().ToLower();

            switch (choice)
            {
                case "teacher":
                    AddTeacher(teachers);
                    break;

                case "student":
                    AddStudent(students);
                    break;

                case "employee":
                    AddEmployee(employees);
                    break;

                case "principal":
                    AddPrincipal(principals);
                    break;

                case "peon":
                    AddPeon(peons);
                    break;

                case "show record":
                    ShowRecord(teachers, students, employees, principals, peons);
                    break;

                case "nothing":
                    continueRunning = false;
                    break;

                default:
                    Console.WriteLine("Invalid choice.");
                    break;
            }
        }

        Console.WriteLine("Program ended.");
    }

    static void AddTeacher(List<Teacher> teachers)
    {
        Console.WriteLine("\nEnter details for Teacher:");
        Teacher teacher = new Teacher
        {
            Name = GetInput("Name: "),
            Age = int.Parse(GetInput("Age: ")),
            Subject = GetInput("Subject: ")
        };
        teachers.Add(teacher);
    }

    static void AddStudent(List<Student> students)
    {
        Console.WriteLine("\nEnter details for Student:");
        Student student = new Student
        {
            Name = GetInput("Name: "),
            Age = int.Parse(GetInput("Age: ")),
            Grade = int.Parse(GetInput("Grade: "))
        };
        students.Add(student);
    }

    static void AddEmployee(List<Employee> employees)
    {
        Console.WriteLine("\nEnter details for Employee:");
        Employee employee = new Employee
        {
            Name = GetInput("Name: "),
            Age = int.Parse(GetInput("Age: ")),
            JobTitle = GetInput("Job Title: ")
        };
        employees.Add(employee);
    }

    static void AddPrincipal(List<Principal> principals)
    {
        Console.WriteLine("\nEnter details for Principal:");
        Principal principal = new Principal
        {
            Name = GetInput("Name: "),
            Age = int.Parse(GetInput("Age: ")),
            YearsOfExperience = int.Parse(GetInput("Years of Experience: "))
        };
        principals.Add(principal);
    }

    static void AddPeon(List<Peon> peons)
    {
        Console.WriteLine("\nEnter details for Peon:");
        Peon peon = new Peon
        {
            Name = GetInput("Name: "),
            Age = int.Parse(GetInput("Age: ")),
            Duty = GetInput("Duty: ")
        };
        peons.Add(peon);
    }

    static string GetInput(string prompt)
    {
        Console.Write(prompt);
        return Console.ReadLine();
    }

    static void ShowRecord(List<Teacher> teachers, List<Student> students, List<Employee> employees, List<Principal> principals, List<Peon> peons)
    {
        Console.WriteLine("\nWhich record would you like to see? (teacher/student/employee/principal/peon): ");
        string classChoice = Console.ReadLine().ToLower();

        switch (classChoice)
        {
            case "teacher":
                DisplayList(teachers, "Teachers");
                break;

            case "student":
                DisplayList(students, "Students");
                break;

            case "employee":
                DisplayList(employees, "Employees");
                break;

            case "principal":
                DisplayList(principals, "Principals");
                break;

            case "peon":
                DisplayList(peons, "Peons");
                break;

            default:
                Console.WriteLine("Invalid class choice.");
                break;
        }
    }

    static void DisplayList<T>(List<T> list, string className) where T : Person
    {
        Console.WriteLine($"\n--- {className} ---");
        if (list.Count == 0)
        {
            Console.WriteLine("No records found.");
        }
        else
        {
            foreach (var person in list)
            {
                person.DisplayInfo();
                Console.WriteLine();
            }
        }
    }
}
Leave a Comment