Exemplo n.º 1
0
        public static void Hire(Company comp)
        {
            // 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" };

            // printing the names to choose from and organizing
            Console.WriteLine("You posted a hiring poster and these want to be hired:");
            Console.WriteLine();
            int exp;

            string[] noticed = new string[rand.Next(2, 6)];
            for (int i = 0; i < noticed.Length; i++)
            {
                noticed[i] = names[rand.Next(names.Length)];
                exp        = rand.Next(7);

                Console.WriteLine("Name: {0} \nExperience: {1} years \n", noticed[i], exp);
            }

            // choosing the employee
            Console.WriteLine("Which one do you want to choose? (index)");
            int ind = int.Parse(Console.ReadLine());

            Console.WriteLine("And in which group would you like to put him/her? (0 - {0})", comp.GetLowestEmployees().GetValue().BossCount() + 1);
            Console.WriteLine("0 - Manager");
            Console.WriteLine("{0} - Subordinate of a rookie", comp.GetLowestEmployees().GetValue().BossCount() + 1);
            int position = int.Parse(Console.ReadLine());

            Console.WriteLine("What would be his/her salary?");
            double   salary = double.Parse(Console.ReadLine());
            Employee newOne = new Employee(noticed[ind], comp.GenerateID(), salary, comp);



            if (position == 0)
            {
                comp.GetManagers().GetLast().SetNext(new Node <Employee>(newOne));
            }
            else
            {
                Node <Employee>      possibleBosses = new Node <Employee>(null);
                Del <object, object> okBoss         = delegate(object nothing, Employee emp1)
                {
                    if (position - 1 == emp1.BossCount())
                    {
                        possibleBosses.GetLast().SetNext(new Node <Employee>(emp1));
                    }
                    return(null);
                };
                comp.ForEveryEmployee <object, object>(okBoss);
                possibleBosses = possibleBosses.GetNext();

                possibleBosses.GetNext(rand.Next(possibleBosses.GetLength())).GetValue().AddSubordinate(new Node <Employee>(newOne));
            }
        }
Exemplo n.º 2
0
        public static void Plague(Company comp)
        {
            Console.WriteLine("A terrible plague happened and a lot of employees are sick!");
            Console.WriteLine("Would you like to treat them or save the money?");
            Console.WriteLine("1. Treat them");
            Console.WriteLine("2. Save the Money");
            double numOfDead = 0;

            if (int.Parse(Console.ReadLine()) == 1) // option 1
            {
                Console.WriteLine("You successfully saved nearly all of them");
                Console.WriteLine("Here's the company now:");
                comp.SetWorth(comp.GetWorth() - comp.EmployeeCount() * 100);
                numOfDead = comp.EmployeeCount() * 0.05;
            }
            else // option 2
            {
                Console.WriteLine("You are really evil but you did save a lot of money...");
                Console.WriteLine("Most of the company is dead now... Here's who is left:");
                numOfDead = comp.EmployeeCount() * 0.6;
            }
            for (int i = 0; i < numOfDead; i++) // killing
            {
                Employee unlucky = comp.GetRandomEmployee();
                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);
                }
            }
            Console.WriteLine();
            Console.WriteLine(comp);
        }
Exemplo n.º 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();
                    }
                }
            }
        }
Exemplo n.º 4
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));
     }
 }
Exemplo n.º 5
0
        public static Company CreateCompany()
        {
            // Defining Company with name and worth
            Console.WriteLine("How would you like to call your company?");
            string name = Console.ReadLine();

            Console.WriteLine("What is the company's worth?");
            double  worth = double.Parse(Console.ReadLine());
            Company comp  = new Company(name, worth, null);

            // Definining managers of company
            Console.WriteLine("Who are the managers of the company? (manager1, manager2, etc...)");
            string[] managerNames = Console.ReadLine().Split(new string[] { ", " }, StringSplitOptions.None);
            Console.WriteLine("What will be their salary?");
            double salary = double.Parse(Console.ReadLine());

            Node <Employee> p1 = new Node <Employee>(null), l1 = p1;

            for (int i = managerNames.Length; i > 0; i--)
            {
                p1.SetNext(new Node <Employee>(new Employee(managerNames[i], comp.GenerateID(), salary, comp)));
                p1 = p1.GetNext();
            }
            l1 = l1.GetNext();
            comp.SetManagers(l1);
            return(comp);
        }
Exemplo n.º 6
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();
                }
            }
        }
Exemplo n.º 7
0
        public override string ToString()
        {
            string   answer = "";
            Node <T> p1     = this;

            while (p1 != null)
            {
                answer += p1.value.ToString();
                if (p1.GetNext() != null)
                {
                    answer += "\n\n";
                }
                p1 = p1.GetNext();
            }
            return(answer);
        }
Exemplo n.º 8
0
        public int GetLength()
        {
            int      length = 0;
            Node <T> p1     = this;

            while (p1 != null)
            {
                length++;
                p1 = p1.GetNext();
            }
            return(length);
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        public bool IsManager()
        {
            Node <Employee> managers = this.company.GetManagers();

            while (managers != null)
            {
                if (managers.GetValue() == this)
                {
                    return(true);
                }
                managers = managers.GetNext();
            }
            return(false);
        }
Exemplo n.º 13
0
        public Node <Employee> FindEmployee(string name)
        {
            Node <Employee>      rights = new Node <Employee>(null), p1 = rights;
            Del <object, object> addNames = delegate(object nothing, Employee emp1)
            {
                if (emp1.GetName() == name)
                {
                    p1.SetNext(new Node <Employee>(emp1));
                    p1 = p1.GetNext();
                }
                return(null);
            };

            ForEveryEmployee <object, object>(addNames);
            return(rights.GetNext());
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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));
            }
        }
Exemplo n.º 16
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);
            }
        }
Exemplo n.º 17
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);
            }
        }
Exemplo n.º 18
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()));
        }
Exemplo n.º 19
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(@"   {}  /  \_/\=/\_/  \");
        }
Exemplo n.º 20
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);
            }
        }