コード例 #1
0
        }//setName

        /** Changes the fee of the service
         *  @param aFee the new fee
         *  @throws IllegalArgumentException if aFee is negative or
         *             greater than MAX_FEE
         */
        public void setFee(double aFee)
        {
            if (aFee < 0 || aFee >= MAX_FEE)
            {
                throw new System.ArgumentException
                          ("The fee must be between $0 and " + MAX_FEE.ToString("C2"));
            }
            fee = aFee;
        }//setFee
コード例 #2
0
        static void Main(string[] args)
        {
            /*pseudocode
             * Program : CarParkCalc3
             * HOURLY_RATE=2.50
             * MAX_FREE=20.00
             * int[]hoursArray
             * parkFee = HOURLY_RATE * hoursArray
             * IF parkTime > MAX_FEE THEN
             *      OUTPUT MAX_FEE
             * ELSE
             *      OUTPUT parkFee
             * ENDIF
             */


            const decimal HOURLY_RATE = 2.50m;
            const decimal MAX_FEE     = 20m;
            decimal       parkFee     = 0;

            int[]   hoursArray = { 8, 24, 9, 7, 6, 12, 10, 11, 23, 1, 2, 9, 8, 8, 9, 7, 9, 15, 6, 1, 7, 6, 12, 10, 11, 23, 1, 2, 9, 8 };
            decimal total      = 0;
            double  average    = 0;

            Console.WriteLine("Hours  Park fee");
            for (int index = 0; index < hoursArray.Length; index++)
            {
                {
                    parkFee = HOURLY_RATE * hoursArray[index];
                    total  += parkFee;
                    if (parkFee > MAX_FEE)
                    {
                        Console.WriteLine("{0,6}   {1,9} ", hoursArray[index], MAX_FEE.ToString("N"));
                    }
                    else
                    {
                        Console.WriteLine("{0,6}   {1,9} ", hoursArray[index], parkFee.ToString("N"));
                    }
                }
            }



            average = (double)total / hoursArray.Length;
            Console.WriteLine("Total = " + total);
            Console.WriteLine("Average = " + average.ToString("N2"));
            Console.ReadKey();
        }