Esempio n. 1
0
        static void Main(string[] args)
        {
            string name, address, employeeType;
            double pay;

            Console.WriteLine("Enter The first Employee's Details:");// Collects data of first employee
            Console.Write("Name: ");
            bool check = false;

            name = Console.ReadLine();            // collects name
            for (int i = 0; i < name.Length; i++) // checks for numbers and outputs error messige if name contains numbers
            {
                if (name[i] >= 'a' && name[i] <= 'z' || name[i] == ' ')
                {
                    check = true;
                }
                else
                {
                    check = false;
                }
            }
            if (check == false)
            {
                Console.WriteLine("Names do not contain numbers please try again");
                Console.WriteLine("");
                name = Console.ReadLine();
            }// checks for numbers and outputs error messige if name contains numbers
            Console.Write("Address: ");
            address = Console.ReadLine();//collects dev 1 Address
            Console.Write("Employee Type: ");
            employeeType = Console.ReadLine();
            employeeType = validateEmployeeType(employeeType); //collects dev 1 1099 or w2
            Console.Write("Gross Monthly Pay: ");
            try                                                // collects pay data and verifys its a number
            {
                pay = double.Parse(Console.ReadLine());
            }
            catch
            {
                Console.WriteLine("Gross Monthly Pay must be a number. Please try again!");
                pay = double.Parse(Console.ReadLine());
            }// collects pay data and verifys its a number
            SoftwareDeveloper emp1 = new SoftwareDeveloper(name, address, employeeType, pay);//stores developer 1

            Console.WriteLine("\nEnter The Second Employee's Details:"); //Collects data of second employee
            Console.Write("Name: ");
            name = Console.ReadLine();                                   //collects name
            for (int i = 0; i < name.Length; i++)                        // checks for numbers and outputs error messige if name contains numbers
            {
                if (name[i] >= 'a' && name[i] <= 'z' || name[i] == ' ')
                {
                    check = true;
                }
                else
                {
                    check = false;
                }
            }
            if (check == false)
            {
                Console.WriteLine("Names do not contain numbers please try again");
                Console.WriteLine("");
                name = Console.ReadLine();
            }// checks for numbers and outputs error messige if name contains numbers
            Console.Write("Address: ");
            address = Console.ReadLine();//collects dev 2 address
            Console.Write("Employee Type: ");
            employeeType = Console.ReadLine();//collects dev 2 1099 or w2
            employeeType = validateEmployeeType(employeeType);
            Console.Write("Gross Monthly Pay: ");
            try// collects pay data and verifys its a number
            {
                pay = double.Parse(Console.ReadLine());
            }
            catch
            {
                Console.WriteLine("Gross Monthly Pay must be a number. Please try again!");
                pay = double.Parse(Console.ReadLine());
            }// collects pay data and verifys its a number
            SoftwareDeveloper emp2 = new SoftwareDeveloper(name, address, employeeType, pay);//stores developer 2


            Console.WriteLine("\nEnter The Third Employee's Details:"); // Collects data of third employee
            Console.Write("Name: ");
            name = Console.ReadLine();                                  //collects name
            for (int i = 0; i < name.Length; i++)                       // checks for numbers and outputs error messige if name contains numbers
            {
                if (name[i] >= 'a' && name[i] <= 'z' || name[i] == ' ')
                {
                    check = true;
                }
                else
                {
                    check = false;
                }
            }
            if (check == false)
            {
                Console.WriteLine("Names do not contain numbers please try again");
                Console.WriteLine("");
                name = Console.ReadLine();
            }// checks for numbers and outputs error messige if name contains numbers
            Console.Write("Address: ");
            address = Console.ReadLine();//collects dev 3 address
            Console.Write("Employee Type: ");
            employeeType = Console.ReadLine();//collects dev 3 1099 or w2
            employeeType = validateEmployeeType(employeeType);
            Console.Write("Gross Monthly Pay: ");
            try// collects pay data and verifys its a number
            {
                pay = double.Parse(Console.ReadLine());
            }
            catch
            {
                Console.WriteLine("Gross Monthly Pay must be a number. Please try again!");
                pay = double.Parse(Console.ReadLine());
            }// collects pay data and verifys its a number
            SoftwareDeveloper emp3 = new SoftwareDeveloper(name, address, employeeType, pay);//stores developer 3

            Console.WriteLine("");                                  // Writes the data of all three employees
            emp1.displayEmployee();                                 // employee 1
            emp2.displayEmployee();                                 // employee 2
            emp3.displayEmployee();                                 // employee 3

            Console.WriteLine(" ");                                 // provides space between collected data and displayed data
            Console.WriteLine(" ");                                 // provides space between collected data and displayed data
            Console.WriteLine("Press enter to close this program"); //
            Console.ReadLine();                                     // Requires user to press enter to close console
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string name, address, employeeType;
            double pay;

            Console.WriteLine("Weclome");
            Console.WriteLine("Enter The first Employee's Details:");// Collects data of first employee
            Console.Write("Name: ");
            bool check = false;

            name = Console.ReadLine();            // collects name
            for (int i = 0; i < name.Length; i++) // checks for numbers and outputs error messige if name contains numbers
            {
                if (name[i] >= 'a' && name[i] <= 'z' || name[i] == ' ')
                {
                    check = true;
                }
                else
                {
                    check = false;
                }
            }
            if (check == false)
            {
                Console.WriteLine("Names do not contain numbers please try again");
                Console.WriteLine("");
                name = Console.ReadLine();
            }// checks for numbers and outputs error messige if name contains numbers
            Console.Write("Address: ");
            address = Console.ReadLine();//collects dev 1 Address
            Console.Write("Employee Type: ");
            employeeType = Console.ReadLine();
            employeeType = validateEmployeeType(employeeType); //collects dev 1 1099 or w2
            Console.Write("Gross Monthly Pay: ");
            try                                                // collects pay data and verifys its a number
            {
                pay = double.Parse(Console.ReadLine());
            }
            catch
            {
                Console.WriteLine("Gross Monthly Pay must be a number. Please try again!");
                pay = double.Parse(Console.ReadLine());
            }// collects pay data and verifys its a number
            SoftwareDeveloper emp1 = new SoftwareDeveloper(name, address, employeeType, pay);//stores developer 1


            using (StreamWriter writer = new StreamWriter("E:\\Users\\jason\\source\\repos\\Week4redo.csv", true))
            {
                // Use string interpolation syntax to make code clearer.
                writer.WriteLine($" { name}{","}  {address}{","} {employeeType}{","} {pay} .");
            }


            Console.WriteLine("\nEnter The Second Employee's Details:"); //Collects data of second employee
            Console.Write("Name: ");
            name = Console.ReadLine();                                   //collects name
            for (int i = 0; i < name.Length; i++)                        // checks for numbers and outputs error messige if name contains numbers
            {
                if (name[i] >= 'a' && name[i] <= 'z' || name[i] == ' ')
                {
                    check = true;
                }
                else
                {
                    check = false;
                }
            }
            if (check == false)
            {
                Console.WriteLine("Names do not contain numbers please try again");
                Console.WriteLine("");
                name = Console.ReadLine();
            }// checks for numbers and outputs error messige if name contains numbers
            Console.Write("Address: ");
            address = Console.ReadLine();//collects dev 2 address
            Console.Write("Employee Type: ");
            employeeType = Console.ReadLine();//collects dev 2 1099 or w2
            employeeType = validateEmployeeType(employeeType);
            Console.Write("Gross Monthly Pay: ");
            try// collects pay data and verifys its a number
            {
                pay = double.Parse(Console.ReadLine());
            }
            catch
            {
                Console.WriteLine("Gross Monthly Pay must be a number. Please try again!");
                pay = double.Parse(Console.ReadLine());
            }// collects pay data and verifys its a number
            SoftwareDeveloper emp2 = new SoftwareDeveloper(name, address, employeeType, pay);//stores developer 2


            using (StreamWriter writer = new StreamWriter("E:\\Users\\jason\\source\\repos\\Week4redo.csv", true))
            {
                // Use string interpolation syntax to make code clearer.
                writer.WriteLine($" { name}{","}  {address}{","} {employeeType}{","} {pay}.");
            }


            Console.WriteLine("\nEnter The Third Employee's Details:"); // Collects data of third employee
            Console.Write("Name: ");
            name = Console.ReadLine();                                  //collects name
            for (int i = 0; i < name.Length; i++)                       // checks for numbers and outputs error messige if name contains numbers
            {
                if (name[i] >= 'a' && name[i] <= 'z' || name[i] == ' ')
                {
                    check = true;
                }
                else
                {
                    check = false;
                }
            }
            if (check == false)
            {
                Console.WriteLine("Names do not contain numbers please try again");
                Console.WriteLine("");
                name = Console.ReadLine();
            }// checks for numbers and outputs error messige if name contains numbers
            Console.Write("Address: ");
            address = Console.ReadLine();//collects dev 3 address
            Console.Write("Employee Type: ");
            employeeType = Console.ReadLine();//collects dev 3 1099 or w2
            employeeType = validateEmployeeType(employeeType);
            Console.Write("Gross Monthly Pay: ");
            try// collects pay data and verifys its a number
            {
                pay = double.Parse(Console.ReadLine());
            }
            catch
            {
                Console.WriteLine("Gross Monthly Pay must be a number. Please try again!");
                pay = double.Parse(Console.ReadLine());
            }// collects pay data and verifys its a number
            SoftwareDeveloper emp3 = new SoftwareDeveloper(name, address, employeeType, pay);//stores developer 3

            using (StreamWriter writer = new StreamWriter("E:\\Users\\jason\\source\\repos\\Week4redo.csv", true))
            {
                // Use string interpolation syntax to make code clearer.
                writer.WriteLine($" { name} {","} {address} {","} {employeeType} {","} {pay}{","} .");
            }

            string text = System.IO.File.ReadAllText("E:\\Users\\jason\\source\\repos\\Week4redo.csv");

            System.Console.WriteLine("Contents of WriteText.csv");
            System.Console.WriteLine("Name,  Address, Employee type,  Gross pay");
            System.Console.WriteLine("");
            System.Console.WriteLine("{0}", text);


            string[] lines = System.IO.File.ReadAllLines("E:\\Users\\jason\\source\\repos\\Week4redo.csv");



            Console.WriteLine(" ");                                 // provides space between collected data and displayed data
            Console.WriteLine(" ");                                 // provides space between collected data and displayed data
            Console.WriteLine("Press enter to close this program"); //
            Console.ReadLine();                                     // Requires user to press enter to close console
        }