示例#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>
 public InvoiceGenerator()
 {
     this.rideRepository      = new RideRepository();
     this.MINIMUM_COST_PER_KM = 10;
     this.COST_PER_TIME       = 1;
     this.MINIMUM_FARE        = 5;
 }
        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");
            }
        }
 /// <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");
     }
 }
 /// <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");
     }
 }
示例#6
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;
            }
        }
        public double GetUserInvoice(string userId)
        {
            double distance;
            int    time;
            double totalFare = 0;
            Dictionary <string, Ride> rideRepos = RideRepository.GetRideList();

            foreach (var element in rideRepos)
            {
                if (userId == element.Key)
                {
                    distance  = element.Value.distance;
                    time      = element.Value.time;
                    totalFare = this.CalculateFare(distance, time);
                }
            }
            return(totalFare);
        }
        /// <summary>
        /// Creates rideList and add it to the ride Repository per User
        /// </summary>
        /// <param name="userID">userID if the user</param>
        public void CreateRideRepository(string userID)
        {
            List <RideDetails> rideList = new List <RideDetails>();

            Console.WriteLine("Enter the number of rides");
            NO_OF_RIDES = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < NO_OF_RIDES; i++)
            {
                Console.WriteLine("Enter the time and distance separated by space for ride " + (i + 1));
                int         time     = Convert.ToInt32(Console.ReadLine());
                double      distance = Convert.ToInt32(Console.ReadLine());
                RideDetails newRide  = new RideDetails(time, distance);
                rideList.Add(newRide);
            }

            RideRepository rideReop = new RideRepository();

            rideReop.AddUser(userID, rideList);
        }
 /// <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");
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CabInvoice"/> class.
 /// </summary>
 public CabInvoice()
 {
     this.rideRepository = new RideRepository();
 }
 /// <summary>
 /// UC 4 Initializes a new instance of the <see cref="InvoiceService"/> class.
 /// </summary>
 public InvoiceService()
 {
     repository = new RideRepository();
 }