コード例 #1
0
 /// Constrcutor To Create RideRepository instance.
 /// </summary>
 /// <summary>
 ///
 public InvoiceGenerator(RideType rideType)
 {
     this.rideType       = rideType;
     this.rideRepository = new RideRepository();
     try
     {
         //If Ride type is Premium Then Rates Set For Premium else For Normal.
         if (rideType.Equals(RideType.PREMIUM))
         {
             this.MINIMUM_COST_PER_KM = 15;
             this.COST_PER_TIME       = 2;
             this.MINIMUM_FARE        = 20;
         }
         else if (rideType.Equals(RideType.NORMAL))
         {
             this.MINIMUM_COST_PER_KM = 10;
             this.COST_PER_TIME       = 1;
             this.MINIMUM_FARE        = 5;
         }
     }
     catch (CabInvoiceException)
     {
         throw new CabInvoiceException(CabInvoiceException.ExceptionType.INVALID_RIDE_TYPE, "Invalid Ride Type");
     }
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InvoiceGenerator"/> class.
 /// </summary>
 /// <param name="rideType">Type of the ride.</param>
 /// <exception cref="CabInvoiceException">Invalid ride type</exception>
 public InvoiceGenerator(RideType rideType)
 {
     this.rideType       = rideType;
     this.rideRepository = new RideRepository();
     // Based on the ride type respective values for the ride will get selected
     if (rideType.Equals(null))
     {
         throw new CabInvoiceException(CabInvoiceException.ExceptionType.NULL_RIDES, "Null ride type");
     }
     else if (rideType.Equals(RideType.PREMIUM))
     {
         this.MINIMUM_COST_PER_KM = 15;
         this.COST_PER_TIME       = 2;
         this.MINIMUM_FARE        = 20;
     }
     else if (rideType.Equals(RideType.NORMAL))
     {
         this.MINIMUM_COST_PER_KM = 10;
         this.COST_PER_TIME       = 1;
         this.MINIMUM_FARE        = 5;
     }
     else
     {
         throw new CabInvoiceException(CabInvoiceException.ExceptionType.INVALID_RIDE_TYPE, "Invalid ride type");
     }
 }
コード例 #3
0
        public InvoiceGenerator(RideType rideType)
        {
            this.rideType       = rideType;
            this.rideRepository = rideRepository;

            try
            {
                if (rideType.Equals(RideType.PREMIUM))
                {
                    this.MINIMUM_COST_PER_KM = 15;
                    this.COST_PER_TIME       = 2;
                    this.MINIMUM_FARE        = 20;
                }
                if (rideType.Equals(RideType.NORMAL))
                {
                    this.MINIMUM_COST_PER_KM = 10;
                    this.COST_PER_TIME       = 1;
                    this.MINIMUM_FARE        = 5;
                }
            }
            catch (CabInvoiceException)
            {
                throw new CabInvoiceException(CabInvoiceException.ExceptionType.INVALID_RIDE_TYPE, "Invalid Ride Type");
            }
        }
コード例 #4
0
 /// <summary>
 /// Method to calculate total fare for a single ride
 /// </summary>
 /// <param name="time">total time travelled</param>
 /// <param name="distance">total distance travelled</param>
 /// <param name="type">Type of Ride(Premier/Normal)</param>
 /// <returns>Total Fare for single ride</returns>
 public double SingleTripFareCalculation(int time, double distance, RideType type)
 {
     try
     {
         if (distance == 0)
         {
             throw new InvoiceException(InvoiceException.ExceptionType.INVALID_DISTANCE, "Distance cannot be null");
         }
         else if (time == 0)
         {
             throw new InvoiceException(InvoiceException.ExceptionType.INVALID_DISTANCE, "Time cannot be null");
         }
         else
         {
             if (type.Equals(RideType.PREMIER))
             {
                 totalAmt = distance * COST_PER_KM * 1.5 + time * COST_PER_MIN * 2;
                 MIN_FARE = 20;
             }
             else
             {
                 totalAmt = distance * COST_PER_KM + time * COST_PER_MIN;
             }
             return(Math.Max(MIN_FARE, totalAmt));
         }
     }
     catch (InvoiceException e)
     {
         throw new InvoiceException(InvoiceException.ExceptionType.INVALID_RIDE_TYPE, "Ride type not valid");
     }
 }
コード例 #5
0
        ///Parameterized  constructor
        public InvoiceGenerator(RideType rideType)
        {
            this.rideType = rideType;

            this.MINIMUM_COST_PER_KM = 10;
            this.COST_PER_KM         = 1;
            this.MINIMUM_FARE        = 5;
        }
コード例 #6
0
        /// <summary>
        /// Calculates the fare.
        /// </summary>
        /// <param name="rides">The rides.</param>
        /// <param name="rideType">Type of the ride.</param>
        /// <returns></returns>
        ///
        public InvoiceSummary CalculateFare(List <Ride> rides, RideType rideType)
        {
            double totalFare = 0;

            foreach (Ride ride in rides)
            {
                double fareAmount = CalculateFare(rideType, ride.distance, ride.time);
                totalFare = totalFare + fareAmount;
            }
            return(new InvoiceSummary(rides.Count, totalFare, totalFare / rides.Count));
        }
コード例 #7
0
        /// <summary>
        /// Gets the invoice summary.
        /// </summary>
        /// <param name="userID">The user identifier.</param>
        /// <param name="rideType">Type of the ride.</param>
        /// <returns></returns>
        /// <exception cref="CabInvoiceGenerator.CabInvoiceException">Provided user ID is empty</exception>
        public InvoiceSummary GetInvoiceSummary(string userID, RideType rideType)
        {
            if (!rideRepo.ContainsKey(userID))
            {
                throw new CabInvoiceException(CabInvoiceException.ExceptionType.INVAILD_USERID, "Provided user ID is empty");
            }

            Invoicegenerator invoicegenerator = new Invoicegenerator();
            InvoiceSummary   invoiceSummary   = invoicegenerator.CalculateFare(rideRepo[userID], rideType);

            return(invoiceSummary);
        }
コード例 #8
0
 /// <summary>
 /// Method to calculate total fare of all the rides
 /// </summary>
 /// <param name="rideList">List of ride details</param>
 /// <param name="type">Type of Ride(Premier/Normal)</param>
 /// <returns>Total fare</returns>
 public double MultipleTripFareCalculationList(string userID, RideType type)
 {
     try
     {
         if (type.Equals(RideType.PREMIER))
         {
             RideRepository rideRepo = new RideRepository();
             if (rideRepo.rideRepoDict.ContainsKey(userID))
             {
                 List <RideDetails> rideList = rideRepo.GetRideDetailsofUser(userID);
                 if (rideList.Count != 0)
                 {
                     foreach (var rides in rideList)
                     {
                         totalAmt += rides.distance * COST_PER_KM * 1.5 + rides.time * COST_PER_MIN * 2;
                         MIN_FARE  = 20;
                     }
                 }
                 return(Math.Max(MIN_FARE, totalAmt));
             }
             else
             {
                 throw new InvoiceException(InvoiceException.ExceptionType.INVALID_USER_ID, "UserID not found");
             }
         }
         else
         {
             RideRepository rideRepo = new RideRepository();
             if (rideRepo.rideRepoDict.ContainsKey(userID))
             {
                 List <RideDetails> rideList = rideRepo.GetRideDetailsofUser(userID);
                 if (rideList.Count != 0)
                 {
                     foreach (var rides in rideList)
                     {
                         totalAmt += rides.distance * COST_PER_KM + rides.time * COST_PER_MIN;
                     }
                 }
                 return(Math.Max(MIN_FARE, totalAmt));
             }
             else
             {
                 throw new InvoiceException(InvoiceException.ExceptionType.INVALID_USER_ID, "UserID not found");
             }
         }
     }
     catch (InvoiceException e)
     {
         throw new InvoiceException(InvoiceException.ExceptionType.INVALID_RIDE_TYPE, "Ride type not valid");
     }
 }
コード例 #9
0
        /// <summary>
        /// Calculates the fare.
        /// </summary>
        /// <param name="rideType">Type of the ride.</param>
        /// <param name="distance">The distance.</param>
        /// <param name="time">The time.</param>
        /// <returns></returns>
        /// <exception cref="CabInvoiceException">Invalid Ride Type</exception>

        public double CalculateFare(RideType rideType, double distance, int time)
        {
            switch (rideType)
            {
            case RideType.NORMAL_RIDE:
                return(Math.Max(distance * fare.NORMAL_COST_PER_KILOMETER + time * fare.NORMAL_COST_PER_MINUTE, fare.NORMAL_MINIMUM_FARE));

            case RideType.PREMIUM_RIDE:
                return(Math.Max(distance * fare.PREMIUM_COST_PER_KILOMETER + time * fare.PREMIUM_COST_PER_MINUTE, fare.PREMIUM_MINIMUM_FARE));

            default:
                throw new CabInvoiceException(CabInvoiceException.ExceptionType.INVAILD_RIDE_TYPE, "Invalid Ride Type");
            }
        }
コード例 #10
0
        /// <summary>
        /// method to calculate fare for a provided ride details
        /// </summary>
        /// <param name="distance"> distance travelled in ride </param>
        /// <param name="time"> time duration of ride </param>
        /// <param name="type"> type of ride , normal if not provided </param>
        /// <returns> calculated fare </returns>
        public double CalculateFare(double distance, int time, string type = "normal")
        {
            // creating instance of RideType
            RideType rideType = new RideType(type);

            // calculating total fare for ride
            double totalFare = (distance * rideType.MinimumCostPerKilometer) + (time * rideType.CostPerTime);

            // checking if totalFare is less than MinimumFare
            if (totalFare < rideType.MinimumFare)
            {
                return(rideType.MinimumFare);
            }

            return(totalFare);
        } //// end : public double CalculateFare(double distance, int time, string type = "normal")
コード例 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InvoiceGenerator"/> class.
        /// </summary>
        /// <param name="rideType">Type of the ride.</param>
        public InvoiceGenerator(RideType rideType)
        {
            switch (rideType)
            {
            case RideType.NORMAL:
                this.COST_PER_KM  = 10;
                this.COST_PER_MIN = 1;
                this.MIN_FARE     = 5;
                break;

            case RideType.PREMIUM:
                this.COST_PER_KM  = 15;
                this.COST_PER_MIN = 2;
                this.MIN_FARE     = 20;
                break;
            }
        }
コード例 #12
0
        public InvoiceGenerator(RideType rideType)
        {
            this.rideType       = rideType;
            this.rideRepository = new RideRepository();

            if (rideType.Equals(RideType.PREMIUM))
            {
                this.MINIMUM_COST_PER_KM = 15;
                this.COST_PER_TIME       = 2;
                this.MINIMUM_FARE        = 20;
            }
            else if (rideType.Equals(RideType.NORMAL))
            {
                this.MINIMUM_COST_PER_KM = 10;
                this.COST_PER_TIME       = 1;
                this.MINIMUM_FARE        = 10;
            }
        }
コード例 #13
0
        /// <summary>
        /// Method to calculate Total Fare for Multiple Rides
        /// </summary>
        /// <param name="time">Array of distance travelled per ride</param>
        /// <param name="distance">Array of time taken per ride</param>
        /// <param name="type">Type of Ride(Premier/Normal)</param>
        /// <returns>Sum total Fare of all the rides</returns>
        public double MultipleTripFareCalculation(int[] time, double[] distance, RideType type)
        {
            try
            {
                if (distance.Length == 0)
                {
                    throw new InvoiceException(InvoiceException.ExceptionType.INVALID_DISTANCE, "Distance cannot be null");
                }
                else if (time.Length == 0)
                {
                    throw new InvoiceException(InvoiceException.ExceptionType.INVALID_DISTANCE, "Time cannot be null");
                }

                else
                {
                    if (type.Equals(RideType.PREMIER))
                    {
                        NO_OF_RIDES = distance.Length;

                        for (int i = 0; i < distance.Length; i++)
                        {
                            totalAmt += distance[i] * COST_PER_KM * 1.5 + time[i] * COST_PER_MIN * 2;
                            MIN_FARE  = 20;
                        }
                    }
                    else
                    {
                        NO_OF_RIDES = distance.Length;

                        for (int i = 0; i < distance.Length; i++)
                        {
                            totalAmt += distance[i] * COST_PER_KM + time[i] * COST_PER_MIN;
                        }
                    }
                    return(Math.Max(MIN_FARE, totalAmt));
                }
            }
            catch (InvoiceException e)
            {
                throw new InvoiceException(InvoiceException.ExceptionType.INVALID_RIDE_TYPE, "Ride type not valid");
            }
        }
コード例 #14
0
 public InvoiceGenerator(RideType rideType)
 {
     this.rideType = rideType;
     try {
         if (rideType.Equals(RideType.NORMAL))
         {
             MIN_PER_KM_COST = 10;
             COST_PER_TIME   = 1;
             MIN_FARE        = 5;
         }
         if (rideType.Equals(RideType.PREMIUM))
         {
             MIN_PER_KM_COST = 15;
             COST_PER_TIME   = 2;
             MIN_FARE        = 20;
         }
     }
     catch (CabInvoiceCustomException) {
         throw new CabInvoiceCustomException("Invalid ride", CabInvoiceCustomException.Exception.INVALID_RIDE_TYPE);
     }
 }
コード例 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InvoiceGenerator"/> class.
 /// </summary>
 /// <param name="ridetype">The ridetype.</param>
 public InvoiceGenerator(RideType ridetype)
 {
     this.rideType  = ridetype;
     rideRepository = new RideRepository();
     if (ridetype.Equals(RideType.NORMAL))
     {
         /// Initialization of constants for NORMAL rideType
         COST_PER_KM     = 10;
         COST_PER_MINUTE = 1;
         MINIMUM_FARE    = 5;
     }
     /// UC 5 Refactor
     else if (ridetype.Equals(RideType.PREMIUM))
     {
         /// Initialization of constants for PREMIUM rideType
         COST_PER_KM     = 15;
         COST_PER_MINUTE = 2;
         MINIMUM_FARE    = 20;
     }
     else
     {
         throw new CabInvoiceCustomException(CabInvoiceCustomException.ExceptionType.INVALID_RIDE_TYPE, "Invalid Ride Type");
     }
 }
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Ride"/> class.
 /// </summary>
 /// <param name="distance">The distance.</param>
 /// <param name="time">The time.</param>
 public Ride(RideType rideType, double distance, int time)
 {
     this.distance = distance;
     this.time     = time;
     this.rideType = rideType;
 }
コード例 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Rides"/> class.
 /// Constuctor for model rides.
 /// </summary>
 /// <param name="rideType">ride type.</param>
 /// <param name="distance">Travel distance.</param>
 /// <param name="time">Travel time.</param>
 public Rides(RideType rideType, double distance, double time)
 {
     this.distance      = distance;
     this.time          = time;
     this.RideTypeValue = rideType;
 }