Example #1
0
        public static BusArrival EarliestWithAtLeast10Passengers(BusArrival[] arr)
        {
            if (arr == null)
            {
                throw new Exception("invalid parameter");
            }

            BusArrival result = null;

            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] == null)
                {
                    continue;
                }
                if (arr[i].passengers >= 10)
                {
                    if (result == null)
                    {
                        result = arr[i];
                    }
                    else if (arr[i].Before(result))
                    {
                        result = arr[i];
                    }
                }
            }
            return(result);
        }
Example #2
0
 public bool isFuller(BusArrival other)
 {
     if (other == null)
     {
         return(true);
     }
     return(this.passengers > other.passengers);
 }
Example #3
0
        public string PrintEarliestWithAtLeast10Passengers(BusArrival[] busArr)
        {
            BusArrival bus = EarliestWithAtLeast10Passengers(busArr);

            return("\n time arrival      | " + AddZero(bus.timeArrival.GetHour()) + " : " + AddZero(bus.timeArrival.GetMinute()) + " : " + AddZero(bus.timeArrival.GetSecond()) +
                   "\n line number       | " + bus.LineNumber +
                   "\n passengers number | " + bus.Passengers);
        }
Example #4
0
 public bool Before(BusArrival other)
 {
     if (other == null)
     {
         throw new Exception("cannot compare to null");
     }
     return(TimeArrival.Before(other.timeArrival));
 }
Example #5
0
 public bool Equals(BusArrival other)
 {
     if (other == null)
     {
         return(false);
     }
     if (this == other)
     {
         return(true);
     }
     return(lineNumber == other.lineNumber &&
            passengers == other.passengers &&
            timeArrival.Equals(other.timeArrival));
 }
Example #6
0
        public string Fuller(BusArrival other)
        {
            int result = comparePassengers(passengers, other.passengers);

            if (passengers < other.passengers)
            {
                return("  Sender bus is more fuller than This \n " +
                       "\nsender.passengers     : " + other.passengers +
                       "\nthis.passengers       : " + passengers +
                       "\nresult                : " + result);
            }

            else
            {
                return("  This bus is more fuller than Sender \n " +
                       "\nsender.passengersNumber : " + other.passengers +
                       "\nthis.passengersNumber   : " + passengers +
                       "\nresult                  : " + result);
            }
        }
Example #7
0
 public void Add(BusArrival busArrival)
 {
     timeSpan = (busArrival.TimeArrival.GetHour() * 60 * 60) + (busArrival.TimeArrival.GetMinute() * 60) + busArrival.TimeArrival.GetSecond();
     busArrivals[timeSpan] = busArrival;
 }
Example #8
0
        public override View GetRealChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
        {
            View row = convertView;

            if (row == null)
            {
                row = Context.LayoutInflater.Inflate(Resource.Layout.BusArrivalListItem, null);
            }

            BusArrival busArrival = DataList[groupPosition].busArrivals[childPosition];

            // TODO: handle for no bus services
            row.FindViewById <TextView>(Resource.Id.BusArrivalItemServiceNo).Text = busArrival.serviceNo;

            //string busArrivalTimings = "";

            TextView busArrivalTimingTextView = row.FindViewById <TextView>(Resource.Id.BusArrivalItemTiming);

            busArrivalTimingTextView.Text = "";

            SpannableString span;

            // has bus timings?
            if (busArrival.estimatedArrivals[0] >= 0)
            {
                for (int i = 0; i < busArrival.estimatedArrivals.Length; i++)
                {
                    if (busArrival.estimatedArrivals[i] >= 0)
                    {
                        int fontSize = 2;
                        if (i != 0)
                        {
                            fontSize = 1;

                            // create span for comma
                            span = new SpannableString(", ");
                            span.SetSpan(new ForegroundColorSpan(Color.Gray), 0, span.Length(), SpanTypes.ExclusiveExclusive);
                            busArrivalTimingTextView.Append(span);
                        }

                        // create span for bus arrival
                        span = new SpannableString(((int)busArrival.estimatedArrivals[i]).ToString());
                        span.SetSpan(new ForegroundColorSpan(Color.ParseColor(AppConstants.LOAD_COLORS[busArrival.load[i]])), 0, span.Length(), SpanTypes.ExclusiveExclusive);
                        span.SetSpan(new RelativeSizeSpan(fontSize), 0, span.Length(), SpanTypes.ExclusiveExclusive);

                        busArrivalTimingTextView.Append(span);
                    }
                }
            }
            else
            {
                span = new SpannableString("no timing available");
                span.SetSpan(new ForegroundColorSpan(Color.Gray), 0, span.Length(), SpanTypes.ExclusiveExclusive);
                busArrivalTimingTextView.Append(span);
            }

            //System.Diagnostics.Debug.WriteLine(busArrivalTimings);
            //row.FindViewById<TextView>(Resource.Id.BusArrivalItemTiming).TextFormatted = Html.FromHtml(busArrivalTimings);
            row.FindViewById <TextView>(Resource.Id.BusArrivalItemDestination).Text = busArrival.terminatingDescription;

            return(row);
        }
Example #9
0
 // copy constructor
 public BusArrival(BusArrival other)
 {
     lineNumber  = other.lineNumber;
     passengers  = other.passengers;
     timeArrival = new Time(other.timeArrival);
 }