Beispiel #1
0
        public void ForEveryEmployee(Del foo)
        // there is a sub function
        {
            // foo - the custom function

            Node <Employee> p2 = this.managers;

            while (p2 != null)
            {
                EverySub(p2.GetValue());
                p2 = p2.GetNext();
            }

            void EverySub(Employee current)
            {
                foo(current);
                Node <Employee> p1 = current.GetSubordinates();

                while (p1 != null)
                {
                    EverySub(p1.GetValue());
                    p1 = p1.GetNext();
                }
            }
        }
Beispiel #2
0
        public static void TopPaid(Company comp)
        {
            Node <Employee>      topPaid    = new Node <Employee>(comp.GetManagers().GetValue());
            Del <object, object> higherPaid = delegate(object nothing, Employee emp1)
            {
                if (emp1.GetSalary() > topPaid.GetValue().GetSalary())
                {
                    topPaid = new Node <Employee>(emp1);
                    return(null);
                }
                if (emp1.GetSalary() == topPaid.GetValue().GetSalary() && topPaid.GetValue() != emp1)
                {
                    topPaid.GetLast().SetNext(new Node <Employee>(emp1));
                }
                return(null);
            };

            comp.ForEveryEmployee <object, object>(higherPaid);

            Console.WriteLine("The top paid employees are:");
            Console.WriteLine();
            while (topPaid != null)
            {
                Console.WriteLine(topPaid.GetValue().ToStringWithoutSubs());
                topPaid = topPaid.GetNext();
            }
        }
Beispiel #3
0
        public int EmployeeCount()
        // There is a sub function
        {
            int             counter = 0;
            Node <Employee> p2      = this.managers;

            while (p2 != null)
            {
                EmployeeCounter(p2.GetValue());
                p2 = p2.GetNext();
            }
            return(counter);

            void EmployeeCounter(Employee current)
            {
                counter++;
                if (current.GetSubordinates() != null)
                {
                    Node <Employee> p1 = current.GetSubordinates();
                    while (p1 != null)
                    {
                        EmployeeCounter(p1.GetValue());
                        p1 = p1.GetNext();
                    }
                }
            }
        }
Beispiel #4
0
        public override string ToString()
        {
            string answer = $"Name: {this.name}\nWorth: {this.worth}\nManagers:";

            Node <Employee> p1 = this.managers;

            while (p1 != null)
            {
                answer += "\n\n" + p1.GetValue().ToString();
                p1      = p1.GetNext();
            }
            return(answer);
        }
Beispiel #5
0
        public Employee GetBoss1()
        // There is a sub function
        {
            Node <Employee> p2 = this.company.GetManagers();

            while (p2 != null)
            {
                if (ReturnBoss(p2.GetValue(), this) != null)
                {
                    return(ReturnBoss(p2.GetValue(), this));
                }
                p2 = p2.GetNext();
            }

            return(null); // tried to find unknown boss

            throw new Exception($"Tried to find unknown boss of {this.id}");

            Employee ReturnBoss(Employee current, Employee target)
            {
                if (target.IsSubordinateOf(current))
                {
                    return(current);
                }

                Node <Employee> p1 = current.GetSubordinates();

                while (p1 != null)
                {
                    if (ReturnBoss(p1.GetValue(), target) != null)
                    {
                        return(ReturnBoss(p1.GetValue(), target));
                    }
                    p1 = p1.GetNext();
                }
                return(null);
            }
        }
Beispiel #6
0
        public bool IsManager()
        {
            Node <Employee> managers = this.company.GetManagers();

            while (managers != null)
            {
                if (managers.GetValue() == this)
                {
                    return(true);
                }
                managers = managers.GetNext();
            }
            return(false);
        }
Beispiel #7
0
        public bool IsSubordinateOf(Employee emp1)
        {
            Node <Employee> p1 = emp1.GetSubordinates();

            while (p1 != null)
            {
                if (p1.GetValue() == this)
                {
                    return(true);
                }
                p1 = p1.GetNext();
            }
            return(false);
        }
Beispiel #8
0
        public Employee FindEmployee(double id)
        // There is a sub function
        {
            Node <Employee> p2 = this.GetManagers();

            while (p2 != null)
            {
                if (FarSubordinate(p2.GetValue()) != null)
                {
                    return(FarSubordinate(p2.GetValue()));
                }
                p2 = p2.GetNext();
            }
            return(null);

            Employee FarSubordinate(Employee current)
            {
                if (current.GetID() == id)
                {
                    return(current);
                }
                Node <Employee> p1 = current.GetSubordinates();
                Employee        emp1;

                while (p1 != null)
                {
                    emp1 = FarSubordinate(p1.GetValue());
                    if (emp1 != null)
                    {
                        return(emp1);
                    }
                    p1 = p1.GetNext();
                }
                return(null);
            }
        }
Beispiel #9
0
        public override string ToString()
        {
            string answer = $"Name: {this.name}\nID: {this.id}\nSalary: {this.salary}\nCompany: {this.company.GetName()}";

            if (this.subordinates != null)
            {
                Node <Employee> p1 = this.subordinates;
                while (p1 != null)
                {
                    answer += "\n\n" + Tool.PadParagraph(p1.GetValue().ToString(), 6);

                    p1 = p1.GetNext();
                }
            }
            return(answer);
        }
Beispiel #10
0
 public void RemoveSub(Employee unlucky)
 {
     if (unlucky == subordinates.GetValue())
     {
         subordinates = subordinates.GetNext();
     }
     else
     {
         Node <Employee> p1 = subordinates;
         while (p1.GetNext().GetValue() != unlucky)
         {
             p1 = p1.GetNext();
         }
         p1.SetNext(p1.GetNext(2));
     }
 }
Beispiel #11
0
        public static void PrintEmployee(Company comp)
        {
            Console.WriteLine("Whats his name / id?");
            string name = Console.ReadLine();

            if (double.TryParse(name, out double id))
            {
                Console.WriteLine(comp.FindEmployee(id).ToStringWithoutSubs());
            }
            else
            {
                Node <Employee> p1 = comp.FindEmployee(name);
                while (p1 != null)
                {
                    Console.WriteLine(p1.GetValue().ToStringWithoutSubs());
                }
            }
        }
Beispiel #12
0
        public R ForEveryEmployee <T, R>(Del <T, R> foo, T par = default(T))
        // there is a sub function
        {
            // T - Parameter Class
            // R - returning class
            // foo - The custom function

            R result;
            Node <Employee> p2 = this.managers;

            while (p2 != null)
            {
                result = EverySub(p2.GetValue());
                if (!object.Equals(result, default(R)))
                {
                    return(result);
                }
                p2 = p2.GetNext();
            }
            return(default(R));

            R EverySub(Employee current)
            {
                result = foo(par, current);
                if (!object.Equals(result, default(R)))
                {
                    return(result);
                }
                Node <Employee> p1 = current.GetSubordinates();

                while (p1 != null)
                {
                    result = EverySub(p1.GetValue());
                    if (!object.Equals(result, default(R)))
                    {
                        return(result);
                    }
                    p1 = p1.GetNext();
                }
                return(default(R));
            }
        }
Beispiel #13
0
        public static Company RandomComp(int depth, int numOfSubordinates)
        // Depth cant be positive if num of subordinates isnt positive...
        // The maximum amount of workers is: (subordinates ^ depth) - 1
        // There is a sub function here.
        {
            Company  comp = new Company("cmp", 0, null);
            Employee epic = new Employee("epic", -1, 0, comp);

            RandomSubordinates(depth, epic);
            comp.SetManagers(epic.GetSubordinates());
            return(comp);


            void RandomSubordinates(int low, Employee boss)
            {
                boss.SetSubordinates(new Node <Employee>(null));
                Node <Employee> p1 = boss.GetSubordinates();

                for (int i = rand.Next(1, numOfSubordinates + 1); i > 0; i--)
                {
                    double id = comp.GenerateID();
                    p1.SetValue(new Employee(id.ToString(), id, rand.Next(500, 1001) * (low + 1), comp));

                    if (rand.Next(low + 1) != 0)
                    {
                        RandomSubordinates(low - 1, p1.GetValue());
                    }

                    p1.SetNext(new Node <Employee>(null));
                    p1 = p1.GetNext();
                }

                p1 = boss.GetSubordinates();
                while (p1.GetNext().GetNext() != null)
                {
                    p1 = p1.GetNext();
                }
                p1.SetNext(null);
            }
        }
Beispiel #14
0
        public static void ChangeSalary(Company comp)
        {
            Console.WriteLine("Who's salary would you like to change?");
            string   answer = Console.ReadLine();
            Employee lucky;

            if (double.TryParse(answer, out double id))
            {
                lucky = comp.FindEmployee(id);
            }
            else
            {
                Node <Employee> p1 = comp.FindEmployee(answer);
                Console.WriteLine("Which one? (index)");
                while (p1 != null)
                {
                    Console.WriteLine(p1.GetValue().ToStringWithoutSubs());
                }
                lucky = p1.GetNext(int.Parse(Console.ReadLine())).GetValue();
            }

            Console.WriteLine($"His/Hers current salary is {lucky.GetSalary()}, what would be his/hers new one?");
            lucky.SetSalary(double.Parse(Console.ReadLine()));
        }
Beispiel #15
0
        public static Company CreateRandomCompany()
        {
            // A list of possible names
            string[] names = new string[] { "Aiden Fuller", "Mikolaj Maldonado", "Nichola Correa", "Jobe Kemp", "Finnian Cano", "Dawn Clements", "Giovanni Craft", "Charity Keenan", "Evie-Rose Potts", "Maxim Delgado", "Luis Ware", "Aleksander Bowers", "Ameena Velazquez", "Rylan Regan", "Riaz Cook", "Keenan Conroy", "Suzanne Mcdermott", "Kyron Odonnell", "Dotty Hensley", "Kamile Knights", "Konrad Bloggs", "Orlando Sheehan", "Moses Davenport", "Nimrah Anthony", "Milton Dean", "Tamara Wills", "Hywel Clay", "Andreea Quinn", "Abdi Watson", "Abdur Rose", "Elysia Peacock", "Ammara Flynn", "June Gilmour", "Brittany Coffey", "Marwah Mccullough", "Adam Donald", "Cheryl Hodge", "Oakley Martins", "Marshall Hess", "Aleisha Childs", "Marcus Davidson", "Oluwatobiloba Hawkins", "Indigo Swift", "Yasser Ventura", "Osama Guevara", "Domonic Cameron", "Amanda Hoover", "Lexie Jacobson", "Buddy Davies", "Shyam John", "Wilf Rudd", "Keane Hickman", "Greg Petersen", "Francisco Adamson", "Uzma Williams", "Leila Millar", "Garin Day", "Alara Noble", "Sebastian East", "Russell Gay", "Humzah Cooke", "Amy Hansen", "Kimberley Bouvet", "Zander Vaughan", "Lulu Wilde", "Zacharia Paine", "Aurelia Dunkley", "Niko Simon", "Haydon Carey", "James Norton", "Christopher Townsend", "Nigel Hooper", "Elaine Fraser", "Daisie Harding", "Ihsan Frederick", "Rimsha Barrett", "Cassie Bone", "Massimo Allen", "Lynn Andrew", "Conah Perez", "Viktor Couch", "Shawn Downs", "Kali Kay", "Clarke Vo", "Kayla Sparrow", "Darcie Atkinson", "Eryn Davila", "Azaan Garza", "Sunil Callaghan", "Layton Mcneill", "Farhana Feeney", "Myles Kirk", "Maksymilian Carroll", "Elisha Melia", "Aizah Lake", "Gracie-Mae Galloway", "Kaiser Randolph", "Josh Mueller", "Kasper Woodard", "Said Power" };

            Console.WriteLine("What would be the company's name?");
            string name = Console.ReadLine();

            Console.WriteLine("What would be its worth?");
            double worth = double.Parse(Console.ReadLine());

            Console.WriteLine("How many subordinates will a manager have?");
            int numOfSubordinates = int.Parse(Console.ReadLine());
            int depth             = 0;

            if (numOfSubordinates != 0)
            {
                Console.WriteLine("How low will the hierarchy go?");
                depth = int.Parse(Console.ReadLine());
            }
            Console.WriteLine("In what range will the lowest salary be? (num-num)");
            string[] temp = Console.ReadLine().Split('-');
            double   salary1 = double.Parse(temp[0]), salary2 = double.Parse(temp[1]);

            Company  comp = new Company(name, worth, null);
            Employee epic = new Employee("epic", -1, 0, comp);

            RandomSubordinates(depth, epic);
            comp.SetManagers(epic.GetSubordinates());

            Console.WriteLine(comp);
            return(comp);


            void RandomSubordinates(int low, Employee boss)
            {
                boss.SetSubordinates(new Node <Employee>(null));
                Node <Employee> p1 = boss.GetSubordinates();

                for (int i = rand.Next(1, numOfSubordinates + 1); i > 0; i--)
                {
                    double id = comp.GenerateID();
                    p1.SetValue(new Employee(names[rand.Next(names.Length)], id, rand.Next(Math.Min((int)salary1, (int)salary2), Math.Max((int)salary1, (int)salary2)) * (low + 1), comp));

                    if (rand.Next(low + 1) != 0)
                    {
                        RandomSubordinates(low - 1, p1.GetValue());
                    }

                    p1.SetNext(new Node <Employee>(null));
                    p1 = p1.GetNext();
                }

                p1 = boss.GetSubordinates();
                while (p1.GetNext().GetNext() != null)
                {
                    p1 = p1.GetNext();
                }
                p1.SetNext(null);
            }
        }
Beispiel #16
0
        public static void Fire(Company comp)
        {
            // finding the unlucky
            Console.WriteLine("Who would you like to fire?");
            string   answer = Console.ReadLine();
            Employee unlucky;

            if (double.TryParse(answer, out double id))
            {
                unlucky = comp.FindEmployee(id);
            }
            else
            {
                Node <Employee> p1 = comp.FindEmployee(answer);
                Console.WriteLine("Which one? (index)");
                while (p1 != null)
                {
                    Console.WriteLine(p1.GetValue().ToStringWithoutSubs());
                }
                unlucky = p1.GetNext(int.Parse(Console.ReadLine())).GetValue();
            }

            // firing the unlucky
            if (unlucky.GetSubordinates() != null) // if the unlucky has subordinates
            {
                Console.WriteLine("What would you like to do with his subordinates?");
                Console.WriteLine("1. Spread them within the company's bosses");
                Console.WriteLine("2. Give them to his boss (if he's a manager, make them managers)");
                if (int.Parse(Console.ReadLine()) == 1)
                {
                    Node <Employee> p1 = unlucky.GetSubordinates();
                    unlucky.GetBoss().RemoveSub(unlucky);
                    while (p1 != null)
                    {
                        comp.GetRandomEmployee().AddSubordinate(new Node <Employee>(p1.GetValue()));
                        p1 = p1.GetNext();
                    }
                }
                else // option 2
                {
                    if (unlucky.BossCount() == 0) // the unlucky is a manager
                    {
                        comp.GetManagers().GetLast().SetNext(unlucky.GetSubordinates());
                        if (comp.GetManagers().GetValue() == unlucky)
                        {
                            comp.SetManagers(comp.GetManagers().GetNext());
                        }
                        else
                        {
                            Node <Employee> p1 = comp.GetManagers();
                            while (p1.GetNext().GetValue() != unlucky)
                            {
                                p1 = p1.GetNext();
                            }
                            p1.SetNext(p1.GetNext(2));
                        }
                    }
                    else
                    {
                        unlucky.GetBoss().AddSubordinate(unlucky.GetSubordinates());
                        unlucky.GetBoss().RemoveSub(unlucky);
                    }
                }
            }
            else
            {
                unlucky.GetBoss().RemoveSub(unlucky);
            }
            Console.WriteLine("DONE");
            Console.WriteLine("MUHAHAHA");
            Console.WriteLine();
            Console.WriteLine(@" ,    ,    /\   /\  ");
            Console.WriteLine(@"/( /\ )\  _\ \_/ /_ ");
            Console.WriteLine(@"|\_||_/| < \_   _/ >");
            Console.WriteLine(@"\______/  \|0   0|/ ");
            Console.WriteLine(@"  _\/_   _(_  ^  _)_ ");
            Console.WriteLine(@" ( () ) /`\|V'''V|/`\");
            Console.WriteLine(@"   {}   \  \_____/  /");
            Console.WriteLine(@"   ()   /\   )=(   /\");
            Console.WriteLine(@"   {}  /  \_/\=/\_/  \");
        }