示例#1
0
        //returns a Time Sheet Entry when called
        private static List <TimeSheetEntry> LoadTimeSheets()
        {
            List <TimeSheetEntry> output = new List <TimeSheetEntry>();
            string enterMoreTimeSheets   = "";

            //"while" runs 0 or more times
            //while (enterMoreTimeSheets == true)
            //"do" loop executes 1 or more times
            do
            {
                Console.Write("Enter what you did and for Acme or ABC?: ");
                string workDone = Console.ReadLine();

                Console.Write("How many hours did you do it for: ");
                //t = int.Parse(Console.ReadLine());
                string rawTimeWorked = Console.ReadLine();
                double timeWorked    = checkHoursValid(rawTimeWorked);

                TimeSheetEntry timeSheet = new TimeSheetEntry(); //this is a new instance, not a ref to the old one
                timeSheet.WorkedHours = timeWorked;
                timeSheet.WorkDone    = workDone.ToLower();
                output.Add(timeSheet);

                Console.Write("Do you want to enter more time:");
                //cont = bool.Parse(Console.ReadLine());
                enterMoreTimeSheets = Console.ReadLine();
            } while (checkMoreTimeValid(enterMoreTimeSheets) == true);


            return(output);
        }
示例#2
0
        static void Main(string[] args)
        {
            string w;
            int    i, t, ttl, tll;
            List <TimeSheetEntry> ents = new List <TimeSheetEntry>();
            TimeSheetEntry        ent  = new TimeSheetEntry();

            /*
             * Console.Write("Enter what you did: ");
             * w = Console.ReadLine();
             * Console.Write("How long did you do it for: ");
             * t = int.Parse(Console.ReadLine());
             * ent.HoursWorked = t;
             * ent.WorkDone = w;
             * ents.Add(ent);
             * Console.Write("Do you want to enter more time:");
             */

            // error: string cannot be converted to boolean
            //first capture the string and evaluate it to be sure if the app has to continue or not.
            // solution: declare boolean and then evaluate string to give value.
            // error2.0: evaluate code inside loop to avoid code repetition.
            bool cont = true;

            // bool cont = bool.Parse(Console.ReadLine());
            ttl = 0;
            //we create a new variable to count hours for the other company
            tll = 0;

            do
            {
                Console.Write("Enter what you did: ");
                w = Console.ReadLine();
                Console.Write("How long did you do it for: ");
                t = int.Parse(Console.ReadLine());
                ent.HoursWorked = t;
                // not necesarily a bug, I change it to upper to be able to work the maths later.
                ent.WorkDone = w.ToUpper();
                ents.Add(ent);

                for (i = 0; i < ents.Count; i++)
                {
                    if (ents[i].WorkDone.Contains("ACME"))
                    {
                        ttl += i;
                    }
                }
                for (i = 0; i < ents.Count; i++)
                {
                    if (ents[i].WorkDone.Contains("ABC"))
                    {
                        tll += i;
                    }
                }

                Console.Write("Do you want to enter more time:");

                //cont = bool.Parse(Console.ReadLine());
                w = Console.ReadLine();
                if (w == "yes")
                {
                    cont = true;
                }
                if (w == "no")
                {
                    cont = false;
                }
            } while (cont == true);



            Console.WriteLine("Simulating Sending email to Acme");
            Console.WriteLine("Your bill is $" + ttl * 150 + " for the hours worked.");



            Console.WriteLine("Simulating Sending email to ABC");
            Console.WriteLine("Your bill is $" + tll * 125 + " for the hours worked.");

            for (i = 0; i < ents.Count; i++)
            {
                ttl += ents[i].HoursWorked;
            }

            if (ttl > 40)
            {
                Console.WriteLine("You will get paid $" + ttl * 15 + " for your work.");
            }

            else
            {
                Console.WriteLine("You will get paid $" + ttl * 10 + " for your time.");
            }
            Console.WriteLine();
            Console.Write("Press any key to exit application...");
            Console.ReadKey();
        }
示例#3
0
        static void Main(string[] args)
        {
            string w;
            int    i, t, ttl;
            bool   cont = false;
            List <TimeSheetEntry> ents = new List <TimeSheetEntry>(); // lista tiempo

            Console.Write("Enter what you did: ");
            w = Console.ReadLine();                    // W contains what did
            Console.Write("How long did you do it for: ");
            t = int.Parse(Console.ReadLine());         // t contains hours
            TimeSheetEntry ent = new TimeSheetEntry(); // funcion de tiempo ? buscar gogole

            ent.HoursWorked = t;
            ent.WorkDone    = w;
            ents.Add(ent);
            Console.Write("Do you want to enter more time:");

            //1. First error yes or no y not a bolean option // solution make a if for yes option, because other option are farse
            // Solution make a string condition with yes or no I know its better with boolen but i have to MVP
            string x = Console.ReadLine();

            if (x.Equals("yes"))
            {
                do
                {
                    Console.Write("Enter what you did: ");
                    w = Console.ReadLine();
                    Console.Write("How long did you do it for: ");
                    t = int.Parse(Console.ReadLine());
                    ent.HoursWorked = t;
                    ent.WorkDone    = w;
                    ents.Add(ent);
                    Console.Write("Do you want to enter more time:");
                    x = Console.ReadLine();
                    if (x.Equals("no"))
                    {
                        cont = false;
                    }
                    else
                    {
                        cont = true;
                    }
                    //cont = bool.Parse(Console.ReadLine());
                } while (cont == true);
            }
            //Boolean cont = Boolean.TryParse(x, out bool result);
            ttl = 0;
            // 2. Acme is in lower case
            // 3. Don't contain ACME activitys

            //5. the first postion of acctivitis don't detect ACME or ABC
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("ACME"))
                {
                    ttl += i;
                }
            }
            Console.WriteLine("Simulating Sending email to Acme");
            Console.WriteLine("Your bill is $" + ttl * 150 + " for the hours worked.");

            // 4. don't erase ttl soo abc ttl are always more
            // Solution declare ttl again to 0
            ttl = 0;
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("ABC"))
                {
                    ttl += i;
                }
            }

            Console.WriteLine("Simulating Sending email to ABC");
            Console.WriteLine("Your bill is $" + ttl * 125 + " for the hours worked.");
            for (i = 0; i < ents.Count; i++)
            {
                ttl += ents[i].HoursWorked;
            }
            if (ttl > 40)
            {
                Console.WriteLine("You will get paid $" + ttl * 15 + " for your work.");
            }
            else
            {
                Console.WriteLine("You will get paid $" + ttl * 10 + " for your time.");
            }
            Console.WriteLine();
            Console.Write("Press any key to exit application...");
            Console.ReadKey();
        }
示例#4
0
        static void Main(string[] args)
        {
            string w;
            int    i, t, ttl;
            bool   cont;
            List <TimeSheetEntry> ents = new List <TimeSheetEntry>();
            TimeSheetEntry        ent  = new TimeSheetEntry();

            /* You have the do-while so you can avoid this first loop and just initiate the variables thare are gonna be use
             *
             * Console.Write("Enter what you did: ");
             * w = Console.ReadLine();
             * Console.Write("How long did you do it for: ");
             * t = int.Parse(Console.ReadLine());
             * TimeSheetEntry ent = new TimeSheetEntry();
             * ent.HoursWorked = t;
             * ent.WorkDone = w;
             * ents.Add(ent);
             * Console.Write("Do you want to enter more time:");
             * bool cont = bool.Parse(Console.ReadLine());
             */
            do
            {
                Console.Write("Enter what you did: ");
                w = Console.ReadLine();
                Console.Write("How long did you do it for: ");
                t               = int.Parse(Console.ReadLine());
                ent             = new TimeSheetEntry(); // YOU HAVE TO SET END TO A NEW OBJECT OR ELSE IT IS JUST ADDING THE SAME OBJECT TO THE LIST AND ITS CHANGING ITS VALUE EVERY TIME
                ent.HoursWorked = t;
                ent.WorkDone    = w;
                ents.Add(ent);
                Console.Write("Do you want to enter more time:");

                // COMPARING IF YOU HAVE WRITE "YES" IF YOU HAVE DONE IT ITS TRUE IF NOT ITS FALSE
                cont = Console.ReadLine().ToUpper() == "YES";
            } while (cont == true);
            ttl = 0;
            for (i = 0; i < ents.Count; i++)
            {
                //if (ents[i].WorkDone.Contains("Acme"))
                // ADDING THIS LINE SO IT ALWAYS CHECK IF ACME ITS WRITEN WITHOUT BEING KEY SENSITIVE
                if (ents[i].WorkDone.ToUpper().Contains("ACME"))
                {
                    //ttl += i;
                    //ADDING hoursworked TO THE i VARIABLE CAUSE WHEN ITS THE FIRST ITERATION ITS VALUE IS 0 SO IF THE CONDITION
                    // IS TRUE YOU ARE DOING ttl =+ 0;
                    ttl += ents[i].HoursWorked;
                }
            }
            Console.WriteLine("Simulating Sending email to Acme");
            Console.WriteLine("Your bill is $" + ttl * 150 + " for the hours worked.");
            ttl = 0; //SETING tll TO 0 TO DONT CONFLICT WITH THE HOURS WORKED ON THE ABC LOOP
            for (i = 0; i < ents.Count; i++)
            {
                //if (ents[i].WorkDone.Contains("ABC"))
                // ADDING THIS LINE SO IT ALWAYS CHECK IF ABC ITS WRITEN WITHOUT BEING KEY SENSITIVE
                if (ents[i].WorkDone.ToUpper().Contains("ABC"))
                {
                    //ttl += i;
                    //ADDING hoursworked TO THE i VARIABLE CAUSE WHEN ITS THE FIRST ITERATION ITS VALUE IS 0 SO IF THE CONDITION
                    // IS TRUE YOU ARE DOING ttl =+ 0;
                    // ANOTHER SOLUTION COULD BE TO SET THE FOR LIKE THIS: (i = 1; i = ents.Count; i++)
                    ttl += ents[i].HoursWorked;
                }
            }
            Console.WriteLine("Simulating Sending email to ABC");
            Console.WriteLine("Your bill is $" + ttl * 125 + " for the hours worked.");

            ttl = 0; //SETING tll TO 0 TO DONT CONFLICT WITH THE LOOP
            for (i = 0; i < ents.Count; i++)
            {
                ttl += ents[i].HoursWorked;
            }
            if (ttl > 40)
            {
                Console.WriteLine("You will get paid $" + ttl * 15 + " for your work.");
            }
            else
            {
                Console.WriteLine("You will get paid $" + ttl * 10 + " for your time.");
            }
            Console.WriteLine();
            Console.Write("Press any key to exit application...");
            Console.ReadKey();
        }
示例#5
0
        static void Main(string[] args)
        {
            string w;
            int    i, t, ttl;
            List <TimeSheetEntry> ents = new List <TimeSheetEntry>();

            Console.Write("Enter what you did: ");
            w = Console.ReadLine();
            Console.Write("How long did you do it for: ");
            t = int.Parse(Console.ReadLine());
            TimeSheetEntry ent = new TimeSheetEntry();

            ent.HoursWorked = t;
            ent.WorkDone    = w;
            ents.Add(ent);
            Console.Write("Do you want to enter more time:");
            bool cont = bool.Parse(Console.ReadLine());

            do
            {
                Console.Write("Enter what you did: ");
                w = Console.ReadLine();
                Console.Write("How long did you do it for: ");
                t = int.Parse(Console.ReadLine());
                ent.HoursWorked = t;
                ent.WorkDone    = w;
                ents.Add(ent);
                Console.Write("Do you want to enter more time:");
                cont = bool.Parse(Console.ReadLine());
            } while (cont == true);
            ttl = 0;
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("Acme"))
                {
                    ttl += i;
                }
            }
            Console.WriteLine("Simulating Sending email to Acme");
            Console.WriteLine("Your bill is $" + ttl * 150 + " for the hours worked.");
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("ABC"))
                {
                    ttl += i;
                }
            }
            Console.WriteLine("Simulating Sending email to ABC");
            Console.WriteLine("Your bill is $" + ttl * 125 + " for the hours worked.");
            for (i = 0; i < ents.Count; i++)
            {
                ttl += ents[i].HoursWorked;
            }
            if (ttl > 40)
            {
                Console.WriteLine("You will get paid $" + ttl * 15 + " for your work.");
            }
            else
            {
                Console.WriteLine("You will get paid $" + ttl * 10 + " for your time.");
            }
            Console.WriteLine();
            Console.Write("Press any key to exit application...");
            Console.ReadKey();
        }
示例#6
0
        static void Main(string[] args)
        {
            string w, rawTimeWorked;
            int    i;
            double ttl, t;
            List <TimeSheetEntry> ents = new List <TimeSheetEntry>();

            Console.Write("Enter what you did: ");
            w = Console.ReadLine();
            Console.Write("How long did you do it for: ");
            rawTimeWorked = Console.ReadLine();

            while (double.TryParse(rawTimeWorked, out t) == false)
            {
                Console.WriteLine();
                Console.WriteLine("Invalid number given");
                Console.Write("How long did you do it for: ");
                rawTimeWorked = Console.ReadLine();
            }

            TimeSheetEntry ent = new TimeSheetEntry();

            ent.HoursWorked = t;
            ent.WorkDone    = w;
            ents.Add(ent);
            Console.Write("Do you want to enter more time (yes/no): ");

            string answer = Console.ReadLine();
            bool   cont   = false;

            if (answer.ToLower() == "yes")
            {
                cont = true;
            }

            while (cont == true)
            {
                Console.Write("Enter what you did: ");
                w = Console.ReadLine();
                Console.Write("How long did you do it for: ");
                rawTimeWorked = Console.ReadLine();

                while (double.TryParse(rawTimeWorked, out t) == false)
                {
                    Console.WriteLine();
                    Console.WriteLine("Invalid number given");
                    Console.Write("How long did you do it for: ");
                    rawTimeWorked = Console.ReadLine();
                }

                ent             = new TimeSheetEntry();
                ent.HoursWorked = t;
                ent.WorkDone    = w;
                ents.Add(ent);

                Console.Write("Do you want to enter more time (yes/no): ");
                answer = Console.ReadLine();
                cont   = false;

                if (answer.ToLower() == "yes")
                {
                    cont = true;
                }
            }
            ttl = 0;
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.ToLower().Contains("acme"))
                {
                    ttl += ents[i].HoursWorked;
                }
            }
            Console.WriteLine("Simulating Sending email to Acme");
            Console.WriteLine("Your bill is $" + ttl * 150 + " for the hours worked.");

            ttl = 0;
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.ToLower().Contains("abc"))
                {
                    ttl += ents[i].HoursWorked;
                }
            }
            Console.WriteLine("Simulating Sending email to ABC");
            Console.WriteLine("Your bill is $" + ttl * 125 + " for the hours worked.");

            ttl = 0;
            for (i = 0; i < ents.Count; i++)
            {
                ttl += ents[i].HoursWorked;
            }
            if (ttl > 40)
            {
                Console.WriteLine("You will get paid $" + (((ttl - 40) * 15) + (40 * 10)) + " for your work.");
            }
            else
            {
                Console.WriteLine("You will get paid $" + ttl * 10 + " for your time.");
            }
            Console.WriteLine();
            Console.Write("Press any key to exit application...");
            Console.ReadKey();
        }
示例#7
0
        static void Main(string[] args)
        {
            /*
             * I add one String value 'cont', for change the error bool!
             */

            string w, cont;
            int    i, t, ttl;
            List <TimeSheetEntry> ents = new List <TimeSheetEntry>();

            /*
             * I coment the next lines because we need this code fragment in a while for a loop.
             */

            /*
             *  Console.Write("Enter what you did: ");
             *  w = Console.ReadLine();
             *
             *  Console.Write("How long did you do it for: ");
             *  t = int.Parse(Console.ReadLine());
             *  TimeSheetEntry ent = new TimeSheetEntry();
             *  ent.HoursWorked = t;
             *  ent.WorkDone = w;
             *  ents.Add(ent);
             *
             *  Console.Write("Do you want to enter more time:");
             */

            do
            {
                Console.Write("Enter what you did: ");
                w = Console.ReadLine();

                Console.Write("How long did you do it for: ");
                t = int.Parse(Console.ReadLine());
                TimeSheetEntry ent = new TimeSheetEntry();
                ent.HoursWorked = t;
                ent.WorkDone    = w;
                ents.Add(ent);

                Console.Write("Do you want to enter more time:");

                /*
                 * Delete the last line: bool cont = bool.Parse(Console.ReadLine());
                 * and i replace for this:
                 */
                cont = Console.ReadLine();
            } while (cont == "yes");


            ttl = 0;
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("Acme"))
                {
                    ttl += i;
                }
            }
            Console.WriteLine("Simulating Sending email to Acme");
            Console.WriteLine("Your bill is $" + ttl * 150 + " for the hours worked.");
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("ABC"))
                {
                    ttl += i;
                }
            }
            Console.WriteLine("Simulating Sending email to ABC");
            Console.WriteLine("Your bill is $" + ttl * 125 + " for the hours worked.");
            for (i = 0; i < ents.Count; i++)
            {
                ttl += ents[i].HoursWorked;
            }
            if (ttl > 40)
            {
                Console.WriteLine("You will get paid $" + ttl * 13 + " for your work.");
            }
            else
            {
                Console.WriteLine("You will get paid $" + ttl * 10 + " for your time.");
            }
            Console.WriteLine();
            Console.Write("Press any key to exit application...");
            Console.ReadKey();
        }
示例#8
0
        static void Main(string[] args)
        {
            string w;
            int    i, t, ttl;
            List <TimeSheetEntry> ents = new List <TimeSheetEntry>();

            Console.Write("Enter what you did: ");
            w = Console.ReadLine();
            Console.Write("How long did you do it for: ");
            t = int.Parse(Console.ReadLine());
            TimeSheetEntry ent = new TimeSheetEntry();

            ent.HoursWorked = t;
            ent.WorkDone    = w;
            ents.Add(ent);
            Console.Write("Do you want to enter more time:");
            String cont = (Console.ReadLine()); //Boolean not accepted. We could have done that if the string is "yes", boolean cont is "true" and if it's "no", is false.

            if (cont == "yes")
            {
                do
                {
                    Console.Write("Enter what you did: ");
                    w = Console.ReadLine();
                    Console.Write("How long did you do it for: ");
                    t = int.Parse(Console.ReadLine());
                    ent.HoursWorked = t;
                    ent.WorkDone    = w;
                    ents.Add(ent);
                    Console.Write("Do you want to enter more time:");
                    cont = (Console.ReadLine());
                } while (cont == "yes");
            }
            ttl = 0;
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("ACME"))
                {
                    ttl++;      //We have to operate the ttl with itself, not with the variable "i"
                }
            }
            Console.WriteLine("Simulating Sending email to Acme");
            Console.WriteLine("Your bill is $" + ttl * (125 * t) + " for the hours worked."); //The right amount for ACME was 125, not 150
            for (i = 0; i < ents.Count; i++)                                                  // MY GUESS WAS TO PUT TTL TO 0 SO IT DOESN'T OPERATE WITH THE "OLD" TTL VARIABLE FROM ACME
            {
                if (ents[i].WorkDone.Contains("ABC"))
                {
                    ttl++;     //Same as before
                }
            }
            Console.WriteLine("Simulating Sending email to ABC");
            Console.WriteLine("Your bill is $" + ttl * 125 + " for the hours worked.");
            for (i = 0; i < ents.Count; i++)
            {
                ttl += ents[i].HoursWorked;
            }
            if (ttl > 40)
            {
                Console.WriteLine("You will get paid $" + ttl * 15 + " for your work.");
            }
            else
            {
                Console.WriteLine("You will get paid $" + ttl * 10 + " for your time.");
            }
            Console.WriteLine();
            Console.Write("Press any key to exit application...");
            Console.ReadKey();
        }
示例#9
0
        static void Main(string[] args)
        {
            string w;
            int    i, t = 0, ttl;
            List <TimeSheetEntry> ents = new List <TimeSheetEntry>();

            Console.Write("Enter what you did: ");
            w = Convert.ToString(Console.ReadLine());
            Console.Write("How long did you do it for: ");
            try//System.FormatException
            {
                t = int.Parse(Console.ReadLine());
            }
            catch (SystemException b)
            {
                Console.WriteLine("It must be an integer... Program exiting...");
                System.Threading.Thread.Sleep(3000);
                Environment.Exit(1);
            }

            TimeSheetEntry ent = new TimeSheetEntry();

            ent.HoursWorked = t;
            ent.WorkDone    = w;
            ents.Add(ent);
            Console.Write("Do you want to enter more time:");

            String yesno = Convert.ToString(Console.ReadLine()); // Converting yes and no
            bool   cont  = false;

            if (yesno == "yes")
            {
                cont = true;
            }
            else
            {
                if (yesno == "no")
                {
                    cont = false;
                }
                else
                {
                    Console.WriteLine("It must be yes or no... Program exiting...");
                    System.Threading.Thread.Sleep(3000);
                    Environment.Exit(1);
                }
            }



            while (cont == true) //
            {
                Console.Write("Enter what you did: ");
                w = Console.ReadLine();
                Console.Write("How long did you do it for: ");
                t = int.Parse(Console.ReadLine());
                ent.HoursWorked = t;
                ent.WorkDone    = w;
                ents.Add(ent);
                Console.Write("Do you want to enter more time:");
                yesno = Convert.ToString(Console.ReadLine()); // Converting yes and no
                cont  = false;

                if (yesno == "yes")
                {
                    cont = true;
                }
                else
                {
                    if (yesno == "no")
                    {
                        cont = false;
                    }
                    else
                    {
                        Console.WriteLine("It must be yes or no... Program exiting...");
                        System.Threading.Thread.Sleep(3000);
                        Environment.Exit(1);
                    }
                }
            }
            ttl = 0;


            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("ACME"))
                {
                    ttl += 1; // Changed i for 1
                }
            }
            Console.WriteLine("Simulating Sending email to Acme");
            Console.WriteLine("Your bill is $" + ttl * 150 + " for the hours worked.");
            int a = ttl * 150;

            ttl = 0;
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("ABC"))
                {
                    ttl = ttl + 1; // Changed i for 1
                }
            }
            int c = ttl * 125;

            Console.WriteLine("Simulating Sending email to ABC");
            Console.WriteLine("Your bill is $" + c + " for the hours worked.");

            ttl = 0;
            for (i = 0; i < ents.Count; i++)
            {
                ttl += ents[i].HoursWorked;
            }
            if (ttl > 40)
            {
                Console.WriteLine("You will get paid $" + ttl * 15 + a + c + " for your work."); // It fails to do the sum
            }
            else
            {
                Console.WriteLine("You will get paid $" + ttl * 10 + a + c + " for your time."); // It fails to do the sum
            }
            Console.WriteLine();
            Console.Write("Press any key to exit application...");
            Console.ReadKey();
        }
示例#10
0
        static void Main(string[] args)
        {
            string w;
            int    i, t, ttl;
            List <TimeSheetEntry> ents = new List <TimeSheetEntry>();

            Console.Write("Enter what you did: ");
            w = Console.ReadLine();
            Console.Write("How long did you do it for: ");
            t = int.Parse(Console.ReadLine());
            TimeSheetEntry ent = new TimeSheetEntry();

            ent.HoursWorked = t;
            ent.WorkDone    = w;
            ents.Add(ent);
            Console.Write("Do you want to enter more time:");
            //bool cont = bool.Parse(Console.ReadLine());   original
            //creamos un string para la lectura de la linea y si el usuario escribes yes cont sera true. Por defecto la iniciamos en false.
            bool   cont  = false;//= bool.Parse(Console.ReadLine());
            string texto = Console.ReadLine();

            if (texto == "yes")
            {
                cont = true;
            }
            else
            {
                cont = false;
            }

            // mientras cont sea true
            while (cont == true)
            //do
            {
                Console.Write("Enter what you did: ");
                w = Console.ReadLine();
                Console.Write("How long did you do it for: ");
                t = int.Parse(Console.ReadLine());
                ent.HoursWorked = t;
                ent.WorkDone    = w;
                ents.Add(ent);
                Console.Write("Do you want to enter more time:");
                //cont = bool.Parse(Console.ReadLine());
                // tambien lo cambiamos dentro del bucle podriamos crear un metodo para verificar si es verdadero o falso
                texto = Console.ReadLine();
                if (texto == "yes")
                {
                    cont = true;
                }
                else
                {
                    cont = false;
                }
            }

            //while (cont == true);
            // este while sobra. Tanto si añadimos como si no tenemos que calcular la factura.
            ttl = 0;
            for (i = 0; i < ents.Count; i++)
            {
                //if (ents[i].WorkDone.Contains("Acme"))
                // comprobamos si la empresa es ACME. Cambiamos el nombre a UPERCASE
                if (ents[i].WorkDone.Contains("ACME"))
                {
                    ttl += i;
                }
            }
            Console.WriteLine("Simulating Sending email to ACME"); //Acme
            Console.WriteLine("Your bill is $" + ttl * 150 + " for the hours worked.");
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("ABC"))
                {
                    ttl += i;
                }
            }
            Console.WriteLine("Simulating Sending email to ABC");
            Console.WriteLine("Your bill is $" + ttl * 125 + " for the hours worked.");
            for (i = 0; i < ents.Count; i++)
            {
                ttl += ents[i].HoursWorked;
            }
            if (ttl > 40)
            {
                Console.WriteLine("You will get paid $" + ttl * 15 + " for your work.");
                //falta esta linea para saber lo que ganamos por nuestro tiempo
                Console.WriteLine("You will get paid $" + ttl * 10 + " for your time.");
            }
            else
            {
                //falta esta linea para saber lo que ganamos por las horas
                Console.WriteLine("You will get paid $" + ttl * 15 + " for your work.");
                Console.WriteLine("You will get paid $" + ttl * 10 + " for your time.");
            }
            Console.WriteLine();
            Console.Write("Press any key to exit application...");
            Console.ReadKey();
        }
示例#11
0
        static void Main(string[] args)
        {
            string w;
            int    i, t, ttl;
            bool   cont;
            //Crea un ArrayList que contendrá los tiempos
            List <TimeSheetEntry> ents = new List <TimeSheetEntry>();

            //Solicita la información
            Console.Write("Enter what you did: ");
            //recoge un String
            w = Console.ReadLine();
            //Solicita información
            Console.Write("How long did you do it for: ");
            //Espera un entero.
            t = int.Parse(Console.ReadLine());

            //Prepara el objeto que va a introducir al arrayList
            TimeSheetEntry ent = new TimeSheetEntry();

            //Añade la hora
            ent.HoursWorked = t;
            //Añade el trabajo realizado.
            ent.WorkDone = w;
            //Lo añade al ArrayList
            ents.Add(ent);

            //Pregunta si dessea hacer algo mas.
            Console.Write("Do you want to enter more time:");

            /////////////////////////////////////////////////////////////////////
            ///Error al pasar un String a boolean para comprobar si desea continuar.

            //Le llega un string y espera un boolean
            // cont = bool.Equals(Console.ReadLine() );

            //*******************************************************************************************************//
            //Podemos realizar una función /Metodo para mejorar la funcionalidad y no repetir codigo.
            //Declaramos un string vacio
            string inputString = string.Empty;

            //le introducimos el valor de entrada
            inputString = (Console.ReadLine());
            //nos aseguramos de ponerlo en minucsulas con ToLower y comprobamos si es true.
            //Si lo es le ponemos a cont true en el caso contrario un false.
            if (inputString.ToLower() == "yes")
            {
                cont = true;
            }
            else
            {
                cont = false;
            }
            //*******************************************************************************************************//
            if (cont == true)
            {
                do
                {
                    Console.Write("Enter what you did: ");
                    w = Console.ReadLine();
                    Console.Write("How long did you do it for: ");
                    t = int.Parse(Console.ReadLine());
                    ent.HoursWorked = t;
                    ent.WorkDone    = w;
                    ents.Add(ent);
                    Console.Write("Do you want to enter more time:");
                    //Declaramos un string vacio
                    inputString = string.Empty;
                    //le introducimos el valor de entrada
                    inputString = (Console.ReadLine());
                    //nos aseguramos de ponerlo en minucsulas con ToLower y comprobamos si es true.
                    //Si lo es le ponemos a cont true en el caso contrario un false.
                    if (inputString.ToLower() == "yes")
                    {
                        cont = true;
                    }
                    else
                    {
                        cont = false;
                    }
                    //Repetirá el proceso hasta que se introduzca un no en el apartado de "more time:"
                } while (cont == true);
            }

            //Pone el ttl   tiempo trabajado a cero.
            ttl = 0;
            //Primero comprueba cuantos trabajos se han realizado con "Acme".
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("Acme"))
                {
                    //Prueba para ver si suma
                    //    ttl ++;
                    ttl += i;
                    //Comprobar si encuentra Acme
                    //Console.WriteLine("ACME encontrado");
                }
            }
            //Ahora muestra el mensaje
            Console.WriteLine("Simulating Sending email to Acme");
            //realiza el calculo de horas * 150
            int acmeWork = ttl * 150;

            Console.WriteLine("Your bill is $" + acmeWork + " for the hours worked.");
            Console.WriteLine("ACME encontrado" + acmeWork);

            //Pone el ttl   tiempo trabajado a cero.
            ttl = 0;
            //Se prepara para revisar cuantas veces se va a introducir ABC.
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("ABC"))
                {
                    ttl += i;
                }
            }
            //Imprime el mensaje
            Console.WriteLine("Simulating Sending email to ABC");
            //Realiza el cálculo a mostrar
            Console.WriteLine("Your bill is $" + ttl * 125 + " for the hours worked.");
            for (i = 0; i < ents.Count; i++)
            {
                ttl += ents[i].HoursWorked;
            }
            if (ttl > 40)
            {
                Console.WriteLine("You will get paid $" + ttl * 15 + " for your work.");
            }
            else
            {
                Console.WriteLine("You will get paid $" + ttl * 10 + " for your time.");
            }
            Console.WriteLine();
            Console.Write("Press any key to exit application...");
            Console.ReadKey();
        }
示例#12
0
        static void Main(string[] args)
        {
            string w;
            int    i;
            double ttl = 0;
            List <TimeSheetEntry> ents = new List <TimeSheetEntry>();

            Console.Write("Enter what you did: ");
            w = Console.ReadLine();
            TimeSheetEntry ent = new TimeSheetEntry();

            ent.HoursWorked = yesOrNo(); //we place in the hours worked the return from the method
            ent.WorkDone    = w;
            ents.Add(ent);
            Console.Write("Do you want to enter more time:");
            String conditional = Console.ReadLine(); // i changed the boolean and noy i check the string that we read from the console

            if (conditional.ToUpper() == "YES")      //i turn it into uppercase because it can me valid if you say "yes" or "YES"
            {                                        //also if you put things like "ye" or "yess" it should don't work and don't enter in the do/while so i think this way it works quite well.
                do
                {
                    Console.Write("Enter what you did: ");
                    w = Console.ReadLine();
                    ent.HoursWorked = yesOrNo(); //we place in the hours worked the return from the method
                    ent.WorkDone    = w;
                    ents.Add(ent);
                    Console.Write("Do you want to enter more time:");
                    conditional = Console.ReadLine();
                } while (conditional.ToUpper() == "YES");
            }
            ttl = 0;
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("Acme"))
                {
                    ttl += i;
                }
            }
            Console.WriteLine("Simulating Sending email to Acme");
            Console.WriteLine("Your bill is $" + ttl * 150 + " for the hours worked.");
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("ABC"))
                {
                    ttl += i;
                }
            }
            Console.WriteLine("Simulating Sending email to ABC");
            Console.WriteLine("Your bill is $" + ttl * 125 + " for the hours worked.");
            for (i = 0; i < ents.Count; i++)
            {
                ttl += ents[i].HoursWorked;
            }
            if (ttl > 40)
            {
                Console.WriteLine("You will get paid $" + ttl * 15 + " for your work.");
            }
            else
            {
                Console.WriteLine("You will get paid $" + ttl * 10 + " for your time.");
            }
            Console.WriteLine();
            Console.Write("Press any key to exit application...");
            Console.ReadKey();
        }
示例#13
0
        static void Main(string[] args)
        {
            // We don't need all this code, because we can execute it with the do while.

            //Console.Write("Enter what you did: ");
            //w = Console.ReadLine();
            //Console.Write("How long did you do it for: ");
            //t = int.Parse(Console.ReadLine());
            //ent.HoursWorked = t;
            //ent.WorkDone = w;
            //ents.Add(ent);
            //Console.Write("Do you want to enter more time:");
            // bool cont = bool.Parse(Console.ReadLine());

            string w;
            // New variable ttt for control the work done with abc.
            int i, t, ttl, ttt;
            List <TimeSheetEntry> ents = new List <TimeSheetEntry>();
            // We need the variable cont for enter in the do while.
            bool cont = true;

            do
            {
                // We have to use a new ent for every time that we execute the program.
                TimeSheetEntry ent = new TimeSheetEntry();
                Console.Write("Enter what you did: ");
                w = Console.ReadLine();
                Console.Write("How long did you do it for: ");
                //t = int.Parse(Console.ReadLine());
                // Use TryParse for variable t
                string input = Console.ReadLine();
                if (int.TryParse(input, out t))
                {
                    ent.HoursWorked = t;
                }
                ent.WorkDone = w;
                ents.Add(ent);
                Console.Write("Do you want to enter more time:");
                // cont = bool.Parse(Console.ReadLine());
                // cont only works with booleans so we have to parse our YES and NO, using true or false.
                if (Console.ReadLine().Equals("yes"))
                {
                    cont = true;
                }
                else
                {
                    cont = false;
                }
            } while (cont == true);

            ttl = 0;
            // Use another variable for the workdone with abc.
            ttt = 0;
            for (i = 0; i < ents.Count; i++)
            {
                if (ents[i].WorkDone.Contains("Acme"))
                {
                    ttl++;
                    Console.WriteLine(ttl);
                }
                if (ents[i].WorkDone.Contains("ABC"))
                {
                    ttt++;
                }
            }
            Console.WriteLine("Simulating Sending email to Acme");
            Console.WriteLine("Your bill is $" + ttl * 150 + " for the hours worked.");
            Console.WriteLine("Simulating Sending email to ABC");
            Console.WriteLine("Your bill is $" + ttt * 125 + " for the hours worked.");

            //We don't need repeat the code, we can use the same for loop.

            //Console.WriteLine("Simulating Sending email to Acme");
            //Console.WriteLine("Your bill is $" + ttl * 150 + " for the hours worked.");
            //for (i = 0; i < ents.Count; i++)
            //{
            //    if (ents[i].WorkDone.Contains("ABC"))
            //    {
            //        ttl += i;
            //    }
            //}
            //Console.WriteLine("Simulating Sending email to ABC");
            //Console.WriteLine("Your bill is $" + ttl * 125 + " for the hours worked.");

            // create a new variable for merge all the hours worked
            int totalHours = ttl + ttt;

            // if we use the variable totalHours we don't need this part of code.
            //for (i = 0; i < ents.Count; i++)
            //{
            //    totalHours += ents[i].HoursWorked;
            //}
            if (totalHours > 40)
            {
                Console.WriteLine("You will get paid $" + totalHours * 15 + " for your work.");
            }
            else
            {
                Console.WriteLine("You will get paid $" + totalHours * 10 + " for your time.");
            }
            Console.WriteLine();
            Console.Write("Press any key to exit application...");
            Console.ReadKey();
        }
示例#14
0
        //It didn't have the public
        public static void Main(string[] args)
        {
            string w;
            //assign a value for ttl variable
            int i, t, ttl = 0;
            //made a new variable for selecting if the user wants to add or no
            bool varia = true;
            List <TimeSheetEntry> ents = new List <TimeSheetEntry>();

            Console.Write("Enter what you did: ");
            w = Console.ReadLine();
            Console.Write("How long did you do it for: ");
            t = int.Parse(Console.ReadLine());
            TimeSheetEntry ent = new TimeSheetEntry();

            ent.HoursWorked = t;
            ent.WorkDone    = w;
            ents.Add(ent);
            Console.Write("Do you want to enter more time:");
            //added string to detect if is yes or no then convert to true or false, also added another variable to kepp trak of errors in the input in case of wrong output it asks again
            String cont = Console.ReadLine();

            cont = cont.ToLower();
            if (cont == "yes")
            {
                varia = true;
            }
            else if (cont == "no")
            {
                varia = false;
                //I have Put the exit comand here with all the calculus, so when you say no, will make the calculs
                for (i = 0; i < ents.Count; i++)
                {
                    if (ents[i].WorkDone.Contains("Acme"))
                    {
                        ttl += 1;
                    }
                }
                Console.WriteLine("Simulating Sending email to Acme");
                Console.WriteLine("Your bill is $" + ttl * (150 * t) + " for the hours worked.");
                //Re-initializing the ttl value each time we use it
                ttl = 0;
                for (i = 0; i < ents.Count; i++)
                {
                    if (ents[i].WorkDone.Contains("ABC"))
                    {
                        ttl += 1;
                    }
                }
                Console.WriteLine("Simulating Sending email to ABC");
                Console.WriteLine("Your bill is $" + ttl * (125 * t) + " for the hours worked.");
                for (i = 0; i < ents.Count; i++)
                {
                    ttl += ents[i].HoursWorked;
                }
                ttl = 0;
                if (ttl > 40)
                {
                    Console.WriteLine("You will get paid $" + ttl * 15 + " for your work.");
                }
                else
                {
                    Console.WriteLine("You will get paid $" + ttl * 10 + " for your time.");
                }
                Console.WriteLine();
                Console.Write("Press any key to exit application...");
                Console.ReadKey();
            }
            else
            {
                Console.Write("Invalid Statment");
            }
            while (varia == true)
            {
                //we do the same that up there
                Console.Write("Enter what you did: ");
                w = Console.ReadLine();
                Console.Write("How long did you do it for: ");
                t = int.Parse(Console.ReadLine());
                ent.HoursWorked = t;
                ent.WorkDone    = w;
                ents.Add(ent);
                Console.Write("Do you want to enter more time:");
                cont = Console.ReadLine();
                cont = cont.ToLower();
                if (cont == "yes")
                {
                    varia = true;
                }
                else if (cont == "no")
                {
                    varia = false;
                    for (i = 0; i < ents.Count; i++)
                    {
                        if (ents[i].WorkDone.Contains("Acme"))
                        {
                            ttl += 1;
                        }
                    }
                    Console.WriteLine("Simulating Sending email to Acme");
                    Console.WriteLine("Your bill is $" + ttl * (150 * t) + " for the hours worked.");
                    for (i = 0; i < ents.Count; i++)
                    {
                        if (ents[i].WorkDone.Contains("ABC"))
                        {
                            ttl += 1;
                        }
                    }
                    ttl = 0;
                    Console.WriteLine("Simulating Sending email to ABC");
                    Console.WriteLine("Your bill is $" + ttl * (125 * t) + " for the hours worked.");
                    for (i = 0; i < ents.Count; i++)
                    {
                        ttl += ents[i].HoursWorked;
                    }
                    ttl = 0;
                    if (ttl > 40)
                    {
                        Console.WriteLine("You will get paid $" + ttl * 15 + " for your work.");
                    }
                    else
                    {
                        Console.WriteLine("You will get paid $" + ttl * 10 + " for your time.");
                    }
                    Console.WriteLine();
                    Console.Write("Press any key to exit application...");
                    Console.ReadKey();
                }
                else
                {
                    Console.Write("Invalid Statment");
                }
            }
        }