コード例 #1
0
    static void Main()
    {
        RushJob[] jobs = new RushJob[5];
        int       x, y;
        double    grandTotal = 0;
        bool      goodNum;

        for (x = 0; x < jobs.Length; ++x)
        {
            jobs[x] = new RushJob();
            Write("Enter job number ");
            jobs[x].JobNumber = Convert.ToInt32(ReadLine());
            goodNum           = true;
            for (y = 0; y < x; ++y)
            {
                if (jobs[x].Equals(jobs[y]))
                {
                    goodNum = false;
                }
            }
            while (!goodNum)
            {
                Write("Sorry, the job number " +
                      jobs[x].JobNumber + " is a duplicate. " +
                      "\nPlease reenter ");
                jobs[x].JobNumber = Convert.ToInt32(ReadLine());
                goodNum           = true;
                for (y = 0; y < x; ++y)
                {
                    if (jobs[x].Equals(jobs[y]))
                    {
                        goodNum = false;
                    }
                }
            }
            Write("Enter customer name ");
            jobs[x].Customer = ReadLine();
            Write("Enter description ");
            jobs[x].Description = ReadLine();
            Write("Enter estimated hours ");
            jobs[x].Hours = Convert.ToDouble(ReadLine());
        }
        WriteLine("\nSummary:\n");
        Array.Sort(jobs);
        for (x = 0; x < jobs.Length; ++x)
        {
            WriteLine(jobs[x].ToString());
            grandTotal += jobs[x].Price;
        }
        WriteLine("\nTotal for all jobs is " + grandTotal.ToString("C"));
    }
コード例 #2
0
ファイル: Program.cs プロジェクト: pumasloth/ITC366-20FA
        /// <summary>
        /// The do exe 3.
        /// </summary>
        private static void DoExe3()
        {
            Console.WriteLine("Exercise 3");

            RushJob[] rushJobs = new RushJob[5];
            for (int i = 0; i < rushJobs.Length; i++)
            {
                Console.Write("Enter job number >> ");
                if (int.TryParse(Console.ReadLine(), out int jobNumber))
                {
                    if (rushJobs.Any(j => j?.Id == jobNumber))
                    {
                        // Duplicate job number entered. Keep them in the loop.
                        Console.WriteLine($"Sorry, the job number {jobNumber} is a duplicate.");
                        i--;
                        continue;
                    }

                    Console.Write("Enter customer name >> ");
                    var customerName = Console.ReadLine();
                    Console.Write("Enter job description >> ");
                    var jobDescription = Console.ReadLine();
                    Console.Write("Enter estimated hours for job >> ");
                    int.TryParse(Console.ReadLine(), out int hours);
                    rushJobs[i] = new RushJob(jobNumber, customerName, jobDescription, hours);
                }
                else
                {
                    // Invalid data entered. Keep them in the loop.
                    i--;
                }
            }

            Console.WriteLine("\nSummary\n");

            double totalPrice = 0;

            foreach (var rushJob in rushJobs)
            {
                Console.WriteLine(rushJob.ToString());
                totalPrice += (rushJob.Hours * rushJob.Price) + RushJob.PREMIUM;
            }

            Console.WriteLine();
            Console.WriteLine($"Total for all jobs is {totalPrice:C}");

            // Pause until the user hits enter.
            Console.ReadKey();
        }
コード例 #3
0
    int IComparable.CompareTo(Object o)
    {
        int     returnVal;
        RushJob temp = (RushJob)o;

        if (this.JobNumber > temp.JobNumber)
        {
            returnVal = 1;
        }
        else
        if (this.JobNumber < temp.JobNumber)
        {
            returnVal = -1;
        }
        else
        {
            returnVal = 0;
        }
        return(returnVal);
    }
コード例 #4
0
        public static void Generate(RushJob[] arr2)
        {
            for (int i = 0; i < arr2.Length; i++)
            {
                arr2[i] = new RushJob();
                Console.Write("Enter Job Number: ");
                arr2[i].JobNumber = Convert.ToInt32(Console.ReadLine());
                if (i > 0)
                {
                    while (arr2[i].Equals(arr2[i - 1]) || arr2[i].Equals(arr2[0]))
                    {
                        arr2[i].JobNumber = Convert.ToInt32(Console.ReadLine());
                    }

                    if (i >= 2)
                    {
                        while (arr2[i].Equals(arr2[i - 2]) || arr2[i].Equals(arr2[i - 1]))
                        {
                            arr2[i].JobNumber = Convert.ToInt32(Console.ReadLine());
                        }
                    }

                    if (i >= 3)
                    {
                        while (arr2[i].Equals(arr2[i - 3]) || arr2[i].Equals(arr2[i - 2]) || arr2[i].Equals(arr2[i - 1]))
                        {
                            arr2[i].JobNumber = Convert.ToInt32(Console.ReadLine());
                        }
                    }

                    if (i >= 4)
                    {
                        while (arr2[i].Equals(arr2[i - 4]) || arr2[i].Equals(arr2[i - 3]) || arr2[i].Equals(arr2[i - 2]) || arr2[i].Equals(arr2[i - 1]))
                        {
                            arr2[i].JobNumber = Convert.ToInt32(Console.ReadLine());
                        }
                    }

                    if (i >= 5)
                    {
                        while (arr2[i].Equals(arr2[i - 5]) || arr2[i].Equals(arr2[i - 4]) || arr2[i].Equals(arr2[i - 3]) || arr2[i].Equals(arr2[i - 2]) || arr2[i].Equals(arr2[i - 1]))
                        {
                            arr2[i].JobNumber = Convert.ToInt32(Console.ReadLine());
                        }
                    }
                }
                Console.Write("Enter customer name: ");
                arr2[i].CustomerName = Console.ReadLine();
                Console.Write("Enter estimated hours: ");
                arr2[i].EstimatedHours = Convert.ToInt32(Console.ReadLine());
                Console.Write("Enter job description: ");
                arr2[i].JobDescription = Console.ReadLine();
                Console.Write("\n");

                arr2[i].PremiumPrice = 150 + (45 * arr2[i].EstimatedHours);
                prem = arr2[i].PremiumPrice;



                total += prem;
            }

            for (int c = 0; c < arr2.Length; c++)
            {
                Console.Write("\n" + arr2[c].ToString());
                Console.ReadLine();
            }

            Console.Write("\n Total price for all jobs: $" + total);
            Console.ReadLine();
        }
コード例 #5
0
        static void Main(String[] args)
        {
            RushJob[] rj = new RushJob[5];

            Generate(rj);
        }
コード例 #6
0
        static void Main(string[] args)
        {
            RushJob[] r = new RushJob[5];

            Generate(r);
        }