Esempio n. 1
0
        static void Main(string[] args)
        {
            /*Declaring a variable of type Employee (which is a class) and instanciating
             * a new instance of Employee and assigning it to the variable using
             * the NEW keyword means that memory will get allocated on the Heap for that class
             * */
            Employee myEmployee = new Employee();

            /*use the properties to assign values.
             * */
            myEmployee.FirstName    = "Patrick";
            myEmployee.LastName     = "Lankford";
            myEmployee.WeeklySalary = 2010.56m;

            //Output the first name of the employee using the property
            Console.WriteLine(myEmployee.FirstName);

            //Output the entire employee, which will call the ToString method implicitly
            //This would work even without overriding the ToString method in the Employee class
            //however it would spit out the namespace and the name of the class instead of something useful.
            Console.WriteLine(myEmployee);

            //Create the array of type Employee to hold a bunch of employees
            Employee[] employees = new Employee[10];

            //Assign values to the array. Each spot needs to contain an instance of an Employee
            employees[0] = new Employee("James", "Kirk", 453.00m);
            employees[1] = new Employee("Alice", "Cooper", 290.00m);
            employees[2] = new Employee("Tonya", "Harding", 800.00m);
            employees[3] = new Employee("Tony", "Danza", 750.00m);
            employees[4] = new Employee("Leroy", "Jenkins", 320.00m);

            /*A Foreach loop. It is useful for doing a collection of object
             * Each object in the array 'employees' will get assigned to the local
             * variable 'employee' inside the loop.
             * */
            foreach (Employee employee in employees)
            {
                // Run a check to make sure the spot in the arrau is not empty
                if (employee != null)
                {
                    //Print the employee
                    Console.WriteLine(employee.ToString() + " " + employee.YearlySalary());
                }
            }



            //Use the CSVProcessor method that we wrote into main to load the employees from the csv file
            //if it is not in the bin folder
            // "..//..//folder it is in"
            ImportCSV("employees.csv", employees);



            //Instantiate a new UI class
            UserInterface ui = new UserInterface();

            //StaticUserInterface.GetUserInput();

            //Get the user input from the UI class
            //int choice = ui.GetUserInput();
            //Could use the instance one above, but to demonstrate using a static class we are calling the static version
            //If you hate static classes and want to avoid them, feel free to comment the below line out and uncomment
            //line above
            int choice = StaticUserInterface.GetUserInput();

            //While the choice the user entered is not 2, we will loop to continue
            //to get the next choice of what they want to do
            while (choice != 2)
            {
                //If the choice they made is 1, (which for us is the only choice)
                if (choice == 1)
                {
                    //Create a string to concatinate the output
                    string allOutput = "";

                    //Loop through all of the employees just like above only instead of
                    //writing out the employees we are concating them together
                    foreach (Employee employee in employees)
                    {
                        if (employee != null)
                        {
                            //Create the string for printing the output
                            allOutput += employee.ToString() + " " + employee.YearlySalary() + Environment.NewLine;
                        }
                    }
                    //Send the string over to the UI class to print the output
                    ui.PrintAllOutput(allOutput);
                }
                //Get the input choice from the user
                choice = ui.GetUserInput();
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Employee myEmployee = new Employee();

            myEmployee.FirstName    = "Jordan";
            myEmployee.LastName     = "Koehler";
            myEmployee.WeeklySalary = 200.00m;

            Console.WriteLine(myEmployee.FirstName);
            Console.WriteLine(myEmployee);

            Employee[] employees = new Employee[10];

            employees[0] = new Employee("Bob", "Jenkins", 500.00m);
            employees[1] = new Employee("Bill", "Jenkins", 570.00m);
            employees[2] = new Employee("Ben", "Jenkins", 506.00m);
            employees[3] = new Employee("Bull", "Jenkins", 502.00m);
            employees[4] = new Employee("Betty", "Jenkins", 504.00m);
            employees[5] = new Employee("Barbara", "Jenkins", 520.00m);
            employees[6] = new Employee("Butch", "Jenkins", 50.00m);

            foreach (Employee employee in employees)
            {
                if (employee != null)
                {
                    Console.WriteLine(employee.ToString() + " " + employee.YearlySalary());
                }
            }


            ImportCSV("employees.csv", employees);


            UserInterface ui = new UserInterface();



            //int choice = ui.GetUserInput();

            int choice = StaticUserInterface.GetUserInput();

            while (choice != 2)
            {
                if (choice == 1)
                {
                    string allOutput = "";

                    foreach (Employee employee in employees)
                    {
                        if (employee != null)
                        {
                            allOutput += employee.ToString() + " " + employee.YearlySalary() + Environment.NewLine;
                        }
                    }

                    ui.PrintAllOutput(allOutput);

                    choice = ui.GetUserInput();
                }
            }
        }
        static void Main(string[] args)
        {
            //Declaring a variable of type Employee(whic is a class) and instanciating a new instance of Employee and
            //assigning it to the variable using the NEW keywork means that memory will get allocated on the Heap for that class.
            Employee myEmployee = new Employee();

            //Use the properties to assign values.
            myEmployee.FirstName    = "David";
            myEmployee.LastName     = "Barnes";
            myEmployee.WeeklySalary = 2048.34m;

            //Output the first name of the employee using the property
            Console.WriteLine(myEmployee.FirstName);
            //Output the entre employee, which will cal the TooString method implicitly
            //This would work even without overriding the ToString method in the Employee class,
            //however it would only spit out the namespace and the name of the class instead of something useful.
            Console.WriteLine(myEmployee);

            //Create an array of type Employee to hold a bunch of Employees
            Employee[] employees = new Employee[10];

            //Assing values to the array. Each spot needs to contain an instance of an Employee
            employees[0] = new Employee("James", "Kirk", 453.00m);
            employees[1] = new Employee("Jean-Luc", "Picard", 290.00m);
            employees[2] = new Employee("Benjamin", "Sisko", 530.00m);
            employees[3] = new Employee("Kathryn", "Janeway", 350.00m);
            employees[4] = new Employee("Johnathan", "Archer", 743.00m);

            //A foreach loop.  It is usefull for doing a collection of objects.
            //Each object in the array 'employees' will get assigned to the local
            //variable 'employee' inside the loop.
            foreach (Employee employee in employees)
            {
                //Run a check to make sure the spot in the array is not empty
                if (employee != null)// Error checking to make sure each record exists
                {
                    //Print the employee
                    Console.WriteLine(employee.ToString() + " " + employee.YearlySalary());
                }
            }

            //Use the SCVProcessor method that we wrote into main to load the
            //employees from the scv file
            ImportCSV("employees.csv", employees);

            //Instanciate a new UI class
            UserInterface ui = new UserInterface();


            //Get the user input from the UI Class
            //int choice = ui.GetUserInput();
            //could use the instance one above, but to demonstrate using a static
            //class, we are calling the statice version.
            //If you HATE staic classes and want to avoid them, feel free to
            //cmmnet the below line and uncomment the above line.
            int choice = StaticUserInterface.GetUserInput();

            //While the choice that was entered is not 2, we will loop to
            //continue to get the next choice of what they want to do.
            while (choice != 2)
            {
                // If the choice they made is 1, (which for us is the only choice)
                if (choice == 1)
                {
                    //Create a string to concat the output
                    string allOutput = "";

                    //Loop through all the employees just like above only instead of
                    //writing out the employees, we are concating them together.
                    foreach (Employee employee in employees)
                    {
                        if (employee != null)
                        {
                            allOutput += employee.ToString() + employee.YearlySalary() + Environment.NewLine;
                        }
                    }
                    //Once the concat is done, have the UI class print out the result
                    ui.PrintAllOutput(allOutput);
                }
                //Get the next choice from the user.
                choice = ui.GetUserInput();
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            //Declaring a variable of type Employee (which is a class) and
            //instanciating a new instance of Employee and assigning it to
            //a variable using the NEW keywordd means that the memory will get allocate on the Heap
            //for that class
            Employee myEmployee = new Employee();

            //use the properties to assign values
            myEmployee.FirstName    = "Marty";
            myEmployee.LastName     = "Russon";
            myEmployee.WeeklySalary = 2048.34m;

            //Output the first name of the employee using the property.
            Console.WriteLine(myEmployee.FirstName);

            //Output the entire employee which will call the ToString method implicitly.
            //This would work even without overriding the ToString method in the Employee class.
            //however it would only spit out the namespace and name of the class instead of something useful.
            Console.WriteLine(myEmployee);

            //Creat an array of type Employee to hold a bunch of Employees
            Employee[] employees = new Employee[12];

            //Assign values to the array. Each spot needs to contain an instance of an Employee
            employees[0] = new Employee("James", "Kirk", 453.00m);
            employees[1] = new Employee("Jen-Luc", "Picard", 453.00m);
            employees[2] = new Employee("Benjamin", "Sisko", 453.00m);
            employees[3] = new Employee("Katheryn", "Janeway", 1253.00m);
            employees[4] = new Employee("Jonathon", "Archer", 953.00m);
            employees[5] = new Employee("Bob", "Kirk", 253.00m);
            employees[6] = new Employee("Bill", "Kirk", 353.00m);
            employees[7] = new Employee("Steve", "Kirk", 553.00m);
            employees[8] = new Employee("Maggy", "Kirk", 653.00m);
            employees[9] = new Employee("Wilbur", "Kirk", 753.00m);

            //A foreach loop. It is useful for doing a collection of objects.
            //Each object in the array'employees' will get assigned to the local
            //variable 'employee' inside the loop.
            foreach (Employee employee in employees)
            {
                //Run a check to make sure the spot in the array is not empty
                if (employee != null)
                {
                    //print the employee
                    Console.WriteLine(employee.ToString() + " " + employee.YearlySalary());
                }
            }


            //Use the CSVProcessor method that we wrote into main to load the
            //employees from the csv file
            ImportCSV("employees.csv", employees);
            //ImportCSV("../../employees.csv", employees); Relative path to csv file

            //Instanciate a new UI class
            UserInterface ui = new UserInterface();


            //Get the user input from the ui class
            //int choice = ui.GetUserInput();

            //Could use the instance one above but to demonstrate using a static
            //class we are calling the static version
            //If you hate static classes and want to avoid them feel free
            //to comment the below line and uncomment above line
            int choice = StaticUserInterface.GetUserInput();


            //While the choice that they entered is not 2, we will loop to
            //continue to get the next choice of what they want to do.
            while (choice != 2)
            {
                //if the choice they made is 1, (which for us is the only choice)
                if (choice == 1) //May be better to use a switch statement
                {
                    //Create a string to concat the output
                    string allOutput = "";

                    //Loop through the employees just like above only instead of
                    //writing out the employees, we are concating them together
                    foreach (Employee employee in employees)
                    {
                        if (employee != null)
                        {
                            allOutput += employee.ToString() + " " + employee.YearlySalary() + Environment.NewLine;
                        }
                    }
                    //Once the concat is done, have the UI class print out the result
                    ui.PrintAllOutput(allOutput);
                }
                //Get the next choice from user
                choice = ui.GetUserInput();
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            // Create a variable of type Employee called myEmployee:
            Employee myEmployee = new Employee();

            // Assign values to the properties of myEmployee:
            myEmployee.FirstName    = "Alyssa";
            myEmployee.LastName     = "Strand";
            myEmployee.WeeklySalary = 2000.00m;

            // Display values:
            Console.WriteLine(myEmployee.FirstName);
            Console.WriteLine(myEmployee);

            // Create and populate an array of Employee objects:
            Employee[] employees = new Employee[10];
            employees[0] = new Employee("James", "Kirk", 453m);
            employees[1] = new Employee("Jessica", "Holmes", 700m);
            employees[2] = new Employee("Alan", "Jones", 1000m);
            employees[3] = new Employee("Tara", "Richards", 800m);
            employees[4] = new Employee("Ella", "Fitzgerald", 520m);

            foreach (Employee employee in employees)
            {                         // Loop to display the employee's name and yearly salary for each employee....
                if (employee != null) // As long as the employee in the array is not null (5-9)
                {
                    Console.WriteLine(employee.ToString() + " " + employee.YearlySalary());
                }
            }

            // Use the CSVProcessor method to load the employee information from the CSV file:
            ImportCSV("employees.csv", employees);

            // Create a variable of type UserInterface:
            UserInterface ui = new UserInterface();

            /// NEW - How to call a static class method:
            StaticUserInterface.GetUserInput();

            // Get the user input and assign to variable choice:
            //int choice = ui.GetUserInput();
            // Can use static class instead:
            int choice = StaticUserInterface.GetUserInput();

            while (choice != 2) // If choice is not 2 (to exit), loop:
            {
                if (choice == 1)
                {   // If choice is to output the info, clear allOutput before adding more information:
                    string allOutput = "";
                    // Loop to add each employee's information as a line to the string allOutput...
                    foreach (Employee employee in employees)
                    {
                        if (employee != null)   // As long as the employee isn't null.
                        {
                            // Concatenate the employee's name and yearly salary and add to allOutput:
                            allOutput += employee.ToString() + " " + employee.YearlySalary() + Environment.NewLine;
                        }
                    }
                    // Output allOutput to user:
                    ui.PrintAllOutput(allOutput);
                }
                // Get user input again:
                choice = ui.GetUserInput();
            }
        }