/// <summary>
        /// Equalses the specified invoice summary.
        /// </summary>
        /// <param name="invoiceSummary">The invoice summary.</param>
        /// <returns></returns>
        public override bool Equals(Object invoiceSummary)
        {
            if (invoiceSummary == null)
            {
                return(false);
            }
            if (!(invoiceSummary is InvoiceSummary))
            {
                return(false);
            }
            InvoiceSummary invoice = (InvoiceSummary)invoiceSummary;

            return(this.totalFare == invoice.totalFare && this.noOfRides == invoice.noOfRides && this.averageFarePerRide == invoice.averageFarePerRide);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checking whether the specified is equal to this instance or not.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (!(obj is InvoiceSummary))
            {
                return(false);
            }
            InvoiceSummary inputObject = (InvoiceSummary)obj;

            return(this.numberOfRides == inputObject.numberOfRides && this.totalFare == inputObject.totalFare && this.averageFare == inputObject.averageFare);
        }
Ejemplo n.º 3
0
        /// Creating method to override the equals method
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (!(obj is InvoiceSummary))
            {
                return(false);
            }
            InvoiceSummary invoiceObject = (InvoiceSummary)obj;

            return(this.totalFare == invoiceObject.totalFare && this.length == invoiceObject.length && this.averageFare == invoiceObject.averageFare);
        }
Ejemplo n.º 4
0
        } //// end : public double CalculateFare(double distance, int time, string type = "normal")

        /// <summary>
        /// method to generate invoice summary
        /// </summary>
        /// <param name="userId"> user id </param>
        /// <returns> invoice summary </returns>
        public InvoiceSummary GetInvoiceSummary(string userId)
        {
            try
            {
                // checking if user id is null
                if (userId is null)
                {
                    throw new ArgumentNullException(nameof(userId));
                }

                // checking if user id exists in user account
                // if not : throw exception wrong user id
                if (UserAccount.Account.ContainsKey(userId))
                {
                    double         totalFare      = 0;
                    int            numberOfRides  = 0;
                    InvoiceSummary invoiceSummary = new InvoiceSummary();

                    // calculating total fare by traversing through all user rides for given user id
                    foreach (Ride ride in UserAccount.Account[userId])
                    {
                        totalFare += this.CalculateFare(ride.Distance, ride.Time, ride.RideType);
                        numberOfRides++;
                    }

                    // setting invoice summary details from the obtained result
                    invoiceSummary.TotalNumberOfRides = numberOfRides;
                    invoiceSummary.TotalFare          = totalFare;
                    invoiceSummary.CalculateAvergaeFare();
                    return(invoiceSummary);
                }
                else
                {
                    throw new InvalidInputException(InvalidInputException.InvoiceException.invalidUserId, "Wrong user Id");
                }
            }
            catch (ArgumentNullException exception)
            {
                throw new ArgumentNullException(exception.Message);
            }
            catch (InvalidInputException exception)
            {
                throw new InvalidInputException(InvalidInputException.InvoiceException.invalidUserId, exception.Message);
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        } //// end : public InvoiceSummary GetInvoiceSummary(string userId)
Ejemplo n.º 5
0
        public override bool Equals(object that)
        {
            if (this == that)
            {
                return(true);
            }
            if (this == null)
            {
                return(false);
            }
            InvoiceSummary obj = (InvoiceSummary)that;

            return(this.numberOfRide == obj.numberOfRide &&
                   this.totalFare == obj.totalFare &&
                   this.avgFarePerRide == obj.avgFarePerRide);
        }
        /// <CalculateCabFare>
        /// Method to calculated fare of multiple rides
        /// </CalculateCabFare>
        /// <param name="rides"></param>
        /// <returns></returns>
        public InvoiceSummary CalculateCabFare(Ride[] rides)
        {
            int    totalNumberOfRides = 0;
            double totalFare          = 0;

            foreach (Ride ride in rides)
            {
                totalFare          += this.CalculateCabFare(ride.rideType, ride.rideDistance, ride.rideTime);
                totalNumberOfRides += 1;
            }
            //// Object of InvoiceSummery and accessing data from class
            InvoiceSummary invoiceSummary = new InvoiceSummary();

            invoiceSummary.totalNumberOfRides = totalNumberOfRides;
            invoiceSummary.totalFare          = totalFare;
            invoiceSummary.CalulateAverageFare();
            return(invoiceSummary);
        }