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 (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(); } }
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(); } }
static void Main(string[] args) { //Declaring a variable of type EMployee( which is a class) and //instantiating a new instance of Employee and assigning it to the variable. //Using the NEW keywoek means that memory will get allocated on the Heap for that class. Employee myEmployee = new Employee(); //Use the properties to assign values. myEmployee.FirstName = "Robert"; myEmployee.LastName = "Cooley"; myEmployee.WeeklySalary = 2048.54m; //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 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]; //Create an array //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("Jean-Luc", "Picard", 200m); employees[2] = new Employee("Benjamin", "Sisko", 190.00m); employees[3] = new Employee("Kathryn", "Janeway", 897.00m); employees[4] = new Employee("Johnathan", "Archer", 425.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); //Instantiate a new UI class UserInterface ui = new UserInterface(); //staticUserInterface.GetUserInput(); //Get the user input from the UI class //int choice = ui.GetUserInput(); //Using static class/method here, could use the one aboive but won't. 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) { //Create a string to concatenate the output string allOutput = ""; //Loop through all the employees just like above only instead of //writing out the employees, we are concatenting them together. foreach (Employee employee in employees) { if (employee != null) { allOutput += employee.ToString() + " " + employee.YearlySalary() + Environment.NewLine; } } //Once the concatenation is done, have the UI class print out the result. ui.PrintAllOutput(allOutput); } //Get the next choice from the user. 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(); } }
static void Main(string[] args) { // Declaring a variable of type Employee (which is a class) // instancing a new instance of employee and assigning it to the variable // isomg the New keyword means that memory will get allocated on the Heap for that class Employee myEmployee = new Employee(); // references the default constructor of the Employee class // use the properties to assign values //myEmployee.FirstNameString = "Kyle"; //myEmployee.LastNameString = "Sherman"; //myEmployee.WeeklySalaryDecimal = 3000m; // output the information collected // Console.WriteLine(" Name: " + myEmployee.FirstNameString + " " + myEmployee.LastNameString + "\n" + "Weekly Salary: " + myEmployee.WeeklySalaryDecimal.ToString("C")); //Console.WriteLine(" Name: " + myEmployee + "\n" + "Weekly Salary: " + myEmployee.WeeklySalaryDecimal.ToString("C")); // 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 class instead of something useful. // Console.WriteLine(myEmployee); // prints out the class name // create an array of type employee to hold a bunch of Employees Employee[] employees = new Employee[10]; // create an array of 10 indexes // assign values to the array. Each spot needs to contain an instance of an Employee // call the constructor of the Employee class and store the info into the array indexes //employees[0] = new Employee("James", "Cameron", 1200m); // index 1 //employees[1] = new Employee("Seba", "Weber", 5000m); // index 2 //employees[2] = new Employee("John", "Hampton", 5000m); // index 3 //employees[3] = new Employee("RIP", "Harambe", 2500m); // index 4 //employees[4] = new Employee("James", "Kirk", 1500.25m); // index 5 // instantiate the CSVProcessor method that we wrote into main to load the // employees from the csv file ImportCSV("employees.csv", employees); // instanciate a new UI class UserInterface UI = new UserInterface(); // Static version of the UI class // we don't have to instantiate this class since it's static // it's instantiated at the beginning of the class //StaticUserInterface.GetUserInput(); // get the user input from the UI class int choice = UI.GetUserInput(); // int choice = StaticUserInterface.GetUserInput(); // example with using the static UI class // continue until 2(exit) is entered as the menue value while (choice != 2) { // if the user enters the 1(print out employees) do the required work if (choice == 1) { Console.Clear(); string allOutPut = ""; // 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) // foreach(Employee(Type;like int) employee(pointer to Employee class) in employees(array)) { // run a check to make sure the spot in the array is not empty if (employee != null) { // print the employee allOutPut += employee.ToString() + " " + employee.YearlySalary().ToString("c") + Environment.NewLine; //Console.WriteLine(" Name: " + employee + "\n" + "YearlySalary: " + employee.YearlySalary().ToString("C")); } } UI.PrintAllOutput(allOutPut); // print the concatinated line of accumulated values } Console.WriteLine("Press any Key to continue."); Console.ReadKey(); // wait for the user to press a key Console.Clear(); choice = UI.GetUserInput(); // prompt the user to enter some input again } }
static void Main(string[] args) { // Declaring a variable of type Employee (Which is a class) and // instantiating 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 = "Daniel"; myEmployee.LastName = "Richards"; myEmployee.WeeklySalary = 2048.34m; // Output the first name of the employee Console.WriteLine(myEmployee.FirstName); // Output the entire employee, calling the ToString method by implicitly Console.WriteLine(myEmployee); // Create an 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("Frank", "Fontaine", 53.00m); employees[1] = new Employee("Corvo", "Attano", 1280.00m); employees[2] = new Employee("Emily", "Kaldwin", 3840.00m); employees[3] = new Employee("Booker", "Dewitt", 453.00m); employees[4] = new Employee("Andrew", "Ryan", 4633.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) { if (employee != null) { 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); // Instantiate a new UI class UserInterface ui = new UserInterface(); // Get the user input from the UI class int choice = ui.GetUserInput(); // While the choice entered is not 2, we will loop to // continue to get the next choice of what they want to do. while (choice != 2) { 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 concatenating 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(); } }
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 = "David"; myEmployee.LastName = "Barnes"; 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 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]; //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("Jean-Luc", "Picard", 290.00m); employees[2] = new Employee("Benjamin", "Sisko", 530.00m); employees[3] = new Employee("Kathryn", "Janeway", 359.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) { //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); //Instanciate a ne 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 the 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 chioce 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(); } }
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(); } }