Exemplo n.º 1
0
 public void buildClock(TimeReader t)
 {
     if (t.Seconds % 2 == 0)               // Row 1 --> Seconds indicator has to glow on even seconds
     {
         this.Rows [0].LampRow [0].Colour = this.SecondsIndicator;
     }
     for (int i = 0; i < t.Hours / 5; i++)               // Row 2 --> Hours X 5 indicator
     {
         this.Rows [1].LampRow [i].Colour = this.HoursIndicator;
     }
     for (int i = 0; i < t.Hours % 5; i++)               // Row 3 --> Hours X 1  indicator
     {
         this.Rows [2].LampRow [i].Colour = this.HoursIndicator;
     }
     for (int i = 0; i < t.Minutes / 5; i++)               // Row 4 --> Minutes X 5 indicator
     {
         this.Rows [3].LampRow [i].Colour = this.MinutesIndicator;
         if (((i + 1) * 5) % 15 == 0)
         {
             this.Rows [3].LampRow [i].Colour = this.QuarterIndicator;
         }
     }
     for (int i = 0; i < t.Minutes % 5; i++)               // Row 5 --> Minutes X 1 indicator
     {
         this.Rows [4].LampRow [i].Colour = this.MinutesIndicator;
     }
 }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            String offIndicator = "O";

//			Customizations start
            Console.WriteLine("Press Enter to continue with default colors.");
            Console.WriteLine("Enter the color for off indicator. Default is O");
            string enteredOffInd = Console.ReadLine();

            if (!(enteredOffInd == null || enteredOffInd == String.Empty))
            {
                offIndicator = enteredOffInd;
            }
            Console.WriteLine("Enter the color for seconds indicator. Default is Y");
            string enteredSecInd = Console.ReadLine();

            Console.WriteLine("Enter the color for hours indicator. Default is R");
            string enteredHrInd = Console.ReadLine();

            Console.WriteLine("Enter the color for quarter hour indicator. Default is R");
            string enteredQtrInd = Console.ReadLine();

            Console.WriteLine("Enter the color for minutes indicator Default is Y");
            string enteredMinInd = Console.ReadLine();
//			Customizations end

            BerlinClock <String> bc = new BerlinClock <String> (offIndicator);

            //check whether to apply custom colors or run with default colors
            if (!(enteredSecInd == null || enteredSecInd == String.Empty))
            {
                bc.SecondsIndicator = enteredSecInd;
            }
            if (!(enteredHrInd == null || enteredHrInd == String.Empty))
            {
                bc.HoursIndicator = enteredHrInd;
            }
            if (!(enteredQtrInd == null || enteredQtrInd == String.Empty))
            {
                bc.QuarterIndicator = enteredQtrInd;
            }
            if (!(enteredMinInd == null || enteredMinInd == String.Empty))
            {
                bc.MinutesIndicator = enteredMinInd;
            }

            //instantiate TimeReader to read user's time input
            TimeReader tr     = new TimeReader();
            Boolean    isRead = false;          //flag variable indicated read status

            while (isRead == false)             // run until user enters time in correct format
            {
                try {
                    Console.WriteLine("Enter time e.g. 04/18/2017 12:00:00 PM, 11 am, 11:45 am, 5 pm, 11:59 PM");
                    String   enteredTime = Console.ReadLine();
                    DateTime timeValue   = Convert.ToDateTime(enteredTime);
                    Console.WriteLine("Interpreted time in HH:mm:ss format is {0}", timeValue.ToString("HH:mm:ss"));
                    String dateTimeString = timeValue.ToString("HH:mm:ss");
                    tr.readTime(dateTimeString);       //call to readTime function
                    isRead = true;                     //break out of while loop
                } catch (FormatException e) {
                    Console.WriteLine(e.Message);
                    Console.WriteLine("An error has occured parsing the time. Please check your input and try again");
                    Console.WriteLine();
                    isRead = false;
                }
            }
            bc.buildClock(tr);              //call buildClock function to build the BerlinClock
            Console.Write("Output: ");
            Console.WriteLine(bc);          // Display the output in a single line as required
        }