Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // create a couple instances of the Employee class
            Employee employee1 = new Employee("Dave", "Barnes", 537.00m);
            Employee employee2 = new Employee("Joe", "Somebody", 125.50m);

            // create a simple int that will be used for value vs reference
            int myNumber = 5;

            // write the value of the int before the method, call the method, print after call.
            Console.WriteLine(myNumber);
            ChangeAnInt(myNumber);
            Console.WriteLine(myNumber);

            // write the value of the employee before the method, call the method, print after call.
            Console.WriteLine(employee1.ToString());
            ChangeAnObject(employee1);
            Console.WriteLine(employee1.ToString());

            //Console.WriteLine(employee.GetFullName());
            //Console.WriteLine(employee.ToString());

            // showing how to use an array with objects
            Employee[] employees = new Employee[10];

            /*
            // instanciate some employees into the array
            employees[0] = new Employee("James", "Kirk", 453.00m);
            employees[1] = new Employee("Jean-Luc", "Picard", 290.00m);
            employees[2] = new Employee("Benjamin", "Sisko", 587.00m);
            employees[3] = new Employee("Kathryn", "Janeway", 194.00m);
            employees[4] = new Employee("Johnathan", "Archer", 394.00m);

             */

            // Let's use the new CSVProcessor we made!
            CSVProcessor csvProcessor = new CSVProcessor();

            // Call the ImportCSV method passing the path and the employees array
            // over so they can be used. 
            csvProcessor.ImportCSV("../data/employees.csv", employees);

            //a for each loop that will loop through each element of the employees array
            foreach (Employee employee in employees)
            {
                // check to make sure that the current object is null.
                // we know that the first 5 have values because we assigned them right above
                // but the last 5 are null, so we better put in a check.
                if (employee != null)
                {
                    // output the information of the employees.
                    Console.WriteLine(employee.ToString());
                }
            }

            // We are creating a new UserInterface class, and it's okay
            // that the UserInterface class does not have a defined
            // constructor. It will have a default one provided to us that
            // we can take advantage of by just not passing in any parameters.
            UserInterface ui = new UserInterface();

            // This is not a valid statement. Because we are trying to make 
            // an instance of a static class, it won't work.
            //StaticUserInterface stui = new StaticUserInterface();

            // Call the GetUserInput method of the UI class. It will return
            // a valid integer that represents the choice they want to do. 
            int choice = ui.GetUserInput();

            // To use a static class to execute methods we simply call the
            // method on the class name (or type). Since it is not possible
            // to use the 'new' keyword and make an instance, the only way
            // we can access the class is through the class name, so that 
            // is what we do. Here we are calling the GetUserInterface method
            // on the class name to get it to run. 
            //choice = StaticUserInterface.GetUserInput();

            // While the choice is not the exit choice (which in this class is 2)
            while (choice != 2)
            {
                // If the choice is 1, which in this case has to be, but if there
                // were more menus options it might not be so obvious.
                if (choice == 1)
                {
                    // Create an empty string to concat to.
                    string allOutPut = "";

                    //For each employee in the employees array.
                    foreach(Employee employee in employees)
                    {
                        // So long as the spot in the array is not null
                        if (employee != null)
                        {
                            // Concat the employee changed to a string plus a new line
                            // to the allOutput string.
                            allOutPut += employee.ToString() + Environment.NewLine;
                        }
                    }
                    // Now that the large string containing what I would like to output
                    // is created, I can output it to the screen using the
                    // PrintAllOutput method of the UI class.
                    ui.PrintAllOutput(allOutPut);
                }

                // Now that the "Work" that we wanted to do is done,
                // we need to reprompt the user for some input
                choice = ui.GetUserInput();
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Here is some text");
            //Console.WriteLine("Here is some more text");
            //Console.ReadKey();
            // Control F5 to run and pause automatically

            Employee employee1 = new Employee("Dave", "Barnes", 537.00m);
            Employee employee2 = new Employee("Joe", "Somebody", 125.50m);

            //Create simple int that will be used for value vs reference.
            Int32 myNumber = 5;

            //Write the value of the int before the method, call the method, print after call.
            Console.WriteLine(myNumber);
            changeAnInt(myNumber); // need to add ref to pass by refeence
            Console.WriteLine(myNumber);

            //Write the value of the employee before the method, call the method, print after call.
            Console.WriteLine(employee1.ToString());
            changeAnObject(employee1);
            Console.WriteLine(employee1.ToString());


            //Console.WriteLine(employee.GetFullName());
            //Console.WriteLine(employee.ToString());

            //Showing how to use an array with objects
            Employee[] employees = new Employee[10];

            // Instanciate some employees into the array
            //employees[0] = new Employee("James", "Kirk", 453.00m);
            //employees[1] = new Employee("Jean-Luc", "Picard", 290.00m);
            //employees[2] = new Employee("Benjamin", "Sisko", 587.00m);
            //employees[3] = new Employee("Kathryn", "Janeway", 194.00m);
            //employees[4] = new Employee("Johnathan", "Archer", 394.00m);

            //Lets use the new CSVProcessor we made!
            CSVProcessor csvProcessor = new CSVProcessor();

            //Call the ImportCSV method passing the path, and the employees array
            //ove so they can be used
            csvProcessor.ImportCSV("../data/employees.csv", employees);


            //A fo each loop that will loop through each element of the employees array
            foreach (Employee employee in employees)
            {
                //Check to make sure that the current object is not null.
                //we know that the first 5 have values because we assigned them right above
                //but the last 5 are null, so we better put in a check.
                if (employee != null)
                {
                    //output the information of the employee
                    Console.WriteLine(employee.ToString());
                }
            }
            //We are creating a new UserInterface class, and it's okay
            //that the UserInterface class does not have a defined
            //constructor. It will have a default one provided to us that
            //we can take advantage of by just passing in any parameters
            UserInterface ui = new UserInterface();


            //This is not a valid statement. Because we are trying to make
            //an instance of a statice class. it won't work.
            //SaticUserInterface stui = new StaticUserInterface();

            //Call the GetUserInput method of the UI class. It will return
            //a valid integer that represents the choice they want to do.
            int choice = ui.GetUserInput();

            //To use a static class to execute methods we simply call the
            //method on the class name, (or type). Since it is not possible
            //to use the 'new' keyword and make an instance, the only way
            //we can access the class is through the class name, so that
            //is what we do. Here we are calling the GetUserInterface method
            //on the class name to get it to run.

            //choice = StaticUserInterface.GetUserInput();

            //While the choice is not the exit choice (which in this case is 2)
            while (choice != 2)
            {
                //If the choice is 1, which in this case it has to be, but if there
                //were more menu options it might not be so obvious.
                if (choice == 1)
                {
                    //Create a empty string to concat to.
                    string allOutput = "";
                    //For each employee in the employees array.
                    foreach (Employee employee in employees)
                    {
                        //So long as the spot in the array is not null
                        if (employee != null)
                        {
                            //Concat the employee changed to a string plus a new line
                            //to the allOutput string.
                            allOutput += employee.ToString() + Environment.NewLine;
                        }
                    }


                    //Now that the large string containing what I would like to output
                    //is created, I can output it to the screeen using the
                    //PrintAllOutput method of the UI class
                    ui.PrintAllOutput(allOutput);
                }

                //Now that the "Work" that we wanted to do is done,
                //we need to re-prompt the user for some input
                choice = ui.GetUserInput();
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Employee employee1 = new Employee("Alysia", "Zimmerman", 435.00m);
            Employee employee2 = new Employee("Jesse", "Smith", 120.00m);

            int myNumber = 5;

            //Write the Value of the int before the method, call the method, print after call/
            Console.WriteLine(myNumber);
            changeAnInt(myNumber);
            Console.WriteLine(myNumber);

            Console.WriteLine(employee1);
            changeAnObject(employee1);
            Console.WriteLine(employee1.ToString());


          //  Console.WriteLine(employee.GetFullName());
          //  Console.WriteLine(employee.ToString());
           

            //Showing how to use an array with objects
            Employee[] employees = new Employee[10];

            //Instanciates some employees into array
            //employees[0] = new Employee("James", "Bailey", 543.00m);
            //employees[1] = new Employee("Justin", "Aaron", 344.00m);
            //employees[2] = new Employee("Ashley", "Nick", 546.00m);
            //employees[3] = new Employee("Meagan", "Combe", 364.00m);
            //employees[4] = new Employee("Rene", "Base", 583.00m);
            //employees[5] = new Employee("Tyler", "Anderson", 344.00m);
            //employees[6] = new Employee("Bret", "Band", 573.00m);
            //employees[7] = new Employee("Kyle", "Andrew", 224.00m);
            //employees[8] = new Employee("Kelsey", "Drew", 563.00m);
          //  employees[9] = new Employee("Morgan", "Amber", 347.00m);


            //Lets use the new CSVProcessor we made
            CSVProcessor csvProcessor = new CSVProcessor();

            //Call the importCSV method passing the path and the employees array
            // over so they can be used
            csvProcessor.ImportCSV("../data/employees.csv", employees);



            
            //For each loop that will loop through each element of the employees array
            foreach (Employee employee in employees)
            {
                // Check to make sure that the current object is not null.
                if (employee != null)
                {
                    Console.WriteLine(employee.ToString());
                }
            }

            //We are creating a new UserInterface class and it's okay 
            // that the UserInterface calss does not have a defined 
            // constructor. It will have a default one provide to us that
            // we can take advantage of by just not passing in any parameters
            UserInterface ui = new UserInterface();



            // Call the GetUserInput method of the UI class. It will return 
            // a valid integer that represents the choice they want to do. 
            int choice = ui.GetUserInput();

            // To use a static class to execute methods we simply call the method
            // on the class name, or type, Since it is not possible to use the 'new'
            // keyword and make an instance, the only way we can access the class
            // is through the class name, that is what we do. Here we are calling
            // the GetUserInterface method on the calss name to get it to run.
            //choice = StaticUserInterface.GetUserInput();

            // While the choice is not the exit choice (which in this case is 2)
            while (choice != 2)
            {
                // If the choice is 1, which in this case has to be true
                if (choice == 1)
                {
                    //Create an empty string
                    string allOutput = "";
                    // For each Employee in the employees array.
                    foreach (Employee employee in employees)
                    {
                        //So long as the spot in the array is not null
                        if (employee != null)
                        {
                            //Concatenate the employee changed to a string plus a new line
                            allOutput += employee.ToString() + Environment.NewLine;
                        }
                    }
                    ui.PrintAllOutput(allOutput);
                }

                //Now that "work" that we wanted to do is done,
                // we need to re-prompt the user for input
                choice = ui.GetUserInput();
            }

        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            //lets make a new ui class that we can use below
            //commented to use the Static version
            //UserInterface ui = new UserInterface();



            //Here is new Employee being created just to make sure
            //that our Employee class works
            Employee myEmployee = new Employee("David", "Barnes", 835.00m);


            Console.WriteLine(myEmployee);
            Console.WriteLine(myEmployee.FirstAndLastName());

            //lets make an array to hold a of instances of the employee class
            //we have the new keyword that means memory allocation
            //the array is going to be in the heap
            Employee[] employees = new Employee[10];


            //commented since we are using the CSV now
            //employees[0] = new Employee("James", "Kirk", 1701.00m);
            //employees[1] = new Employee("Jean-Luc", "Picard", 1701.00m);
            //employees[2] = new Employee("Benjamin", "Sisko", 587.00m);
            //employees[3] = new Employee("Kathryn", "Janeway", 287.00m);
            //employees[4] = new Employee("Johnathan", "Archer", 127.00m);

            //make the string for the path to the csv file
            string pathtoCSV = "employees.csv";

            //make instance of the csvProcessor

            CSVProcessor csvProcessor = new CSVProcessor();

            //call the imporCSV method sending over the path and
            //the array to the store the read in records too
            csvProcessor.ImportCsv(pathtoCSV, employees);


            //get some inpur from the user
            int choice = StaticUserInterface.GetUserInput();

            //while the user has chosen somthing other than 2
            //which for us is only 1
            while (choice != 2)
            {
                //Create a string that can be concated to
                string outputString = "";

                //Print our the employees in the array
                foreach (Employee employee in employees)
                {
                    if (employee != null)
                    {
                        //concat the employee to the outputString
                        outputString += employee.ToString() + Environment.NewLine;
                    }
                }
                //Outpur the ourputString to the console
                StaticUserInterface.Output(outputString);

                //reprompt the user for some input
                choice = StaticUserInterface.GetUserInput();
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            // Lets make a new UI Class that we can use below

            // Commented to use the static version
            //UserInterface ui = new UserInterface();

            // Her is a new Employee being created just to make sure that our Employee class works
            Employee myEmployee = new Employee("Thomas", "Wold", 835.0m);

            Console.WriteLine(myEmployee);
            Console.WriteLine(myEmployee.FirstAndLastName());

            // Let's make an array to hold a bunch of instances of the Employee class (this should be done in WineItemCollection)
            // We have the new keyword. That means memory allocation.
            //The array is going to be in the Heap.
            Employee[] employees = new Employee[10];

            // Commented since we are using CSV file now

            //employees[0] = new Employee("James", "Kirk", 1701.00m);
            //employees[1] = new Employee("Jean-Luc", "Picard", 1701.00m);
            //employees[2] = new Employee("Benjamin", "Sisko", 587.00m);
            //employees[3] = new Employee("Kathryn", "Janeway", 287.00m);
            //employees[4] = new Employee("Johnathan", "Archer", 127.00m);

            // Make the string for the path to the csv file
            string pathToCsv = "employees.csv";

            // Instanciate the csvProcessor
            CSVProcessor csvProcessor = new CSVProcessor();

            // Call the importCSV method sending over the path and the array to store the read in records to.
            csvProcessor.ImportCsv(pathToCsv, employees);

            // Get some input from the user
            int choice = StaticUserInterface.GetUserInput();

            // While the user has chosen something other than 2
            while (choice != 2)
            {
                //Create a string that can be concatenaited
                string outputString = "";

                // Print out the employees i nthe array
                foreach (Employee employee in employees)
                {
                    if (employee != null)
                    {
                        //Concat the employee to the outputString
                        outputString += employee.ToString() + Environment.NewLine;
                    }
                }

                // Output the outputString to the console
                StaticUserInterface.Output(outputString);

                // Re-promt the uer for some new input
                choice = StaticUserInterface.GetUserInput();
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Employee employee1 = new Employee("Alysia", "Zimmerman", 435.00m);
            Employee employee2 = new Employee("Jesse", "Smith", 120.00m);

            int myNumber = 5;

            //Write the Value of the int before the method, call the method, print after call/
            Console.WriteLine(myNumber);
            changeAnInt(myNumber);
            Console.WriteLine(myNumber);

            Console.WriteLine(employee1);
            changeAnObject(employee1);
            Console.WriteLine(employee1.ToString());


            //  Console.WriteLine(employee.GetFullName());
            //  Console.WriteLine(employee.ToString());


            //Showing how to use an array with objects
            Employee[] employees = new Employee[10];

            //Instanciates some employees into array
            //employees[0] = new Employee("James", "Bailey", 543.00m);
            //employees[1] = new Employee("Justin", "Aaron", 344.00m);
            //employees[2] = new Employee("Ashley", "Nick", 546.00m);
            //employees[3] = new Employee("Meagan", "Combe", 364.00m);
            //employees[4] = new Employee("Rene", "Base", 583.00m);
            //employees[5] = new Employee("Tyler", "Anderson", 344.00m);
            //employees[6] = new Employee("Bret", "Band", 573.00m);
            //employees[7] = new Employee("Kyle", "Andrew", 224.00m);
            //employees[8] = new Employee("Kelsey", "Drew", 563.00m);
            //  employees[9] = new Employee("Morgan", "Amber", 347.00m);


            //Lets use the new CSVProcessor we made
            CSVProcessor csvProcessor = new CSVProcessor();

            //Call the importCSV method passing the path and the employees array
            // over so they can be used
            csvProcessor.ImportCSV("../data/employees.csv", employees);



            //For each loop that will loop through each element of the employees array
            foreach (Employee employee in employees)
            {
                // Check to make sure that the current object is not null.
                if (employee != null)
                {
                    Console.WriteLine(employee.ToString());
                }
            }

            //We are creating a new UserInterface class and it's okay
            // that the UserInterface calss does not have a defined
            // constructor. It will have a default one provide to us that
            // we can take advantage of by just not passing in any parameters
            UserInterface ui = new UserInterface();



            // Call the GetUserInput method of the UI class. It will return
            // a valid integer that represents the choice they want to do.
            int choice = ui.GetUserInput();

            // To use a static class to execute methods we simply call the method
            // on the class name, or type, Since it is not possible to use the 'new'
            // keyword and make an instance, the only way we can access the class
            // is through the class name, that is what we do. Here we are calling
            // the GetUserInterface method on the calss name to get it to run.
            //choice = StaticUserInterface.GetUserInput();

            // While the choice is not the exit choice (which in this case is 2)
            while (choice != 2)
            {
                // If the choice is 1, which in this case has to be true
                if (choice == 1)
                {
                    //Create an empty string
                    string allOutput = "";
                    // For each Employee in the employees array.
                    foreach (Employee employee in employees)
                    {
                        //So long as the spot in the array is not null
                        if (employee != null)
                        {
                            //Concatenate the employee changed to a string plus a new line
                            allOutput += employee.ToString() + Environment.NewLine;
                        }
                    }
                    ui.PrintAllOutput(allOutput);
                }

                //Now that "work" that we wanted to do is done,
                // we need to re-prompt the user for input
                choice = ui.GetUserInput();
            }
        }