コード例 #1
0
        public decimal Calculate(BabySittingSession babySittingSession)
        {
            decimal cost = 0;

            if (babySittingSession.validateTimes())
            {
                cost = this.calculateStartToBed(babySittingSession.bedTime, babySittingSession.startTime)
                       + this.calculateBedToMidnight(babySittingSession.bedTime, babySittingSession.endTime)
                       + this.calculateMidToEnd(babySittingSession.bedTime, babySittingSession.endTime);
            }
            else
            {
                throw new FormatException("Times are incorrect. Make sure start <= bed <= end. Correct and try again.");
            }

            return(cost);
        }
コード例 #2
0
        private static void loadBabySittingSession()
        {
            //Clear mp for further usage.
            Program.babySittingSession = null;

            if (File.Exists("BabySitSession.obj"))
            {
                //Open the file written above and read values from it.
                var stream     = File.Open("BabySitSession.obj", FileMode.Open);
                var bformatter = new BinaryFormatter();

                Console.WriteLine("Reading Baby Sitting Information");
                Program.babySittingSession = (BabySittingSession)bformatter.Deserialize(stream);
                stream.Close();

                Program.babySittingSession.print();
            }
            else
            {
                Program.babySittingSession = new BabySittingSession();
            }
        }