public void DisplayTrainFare()
        {
            //票价定价规定
            //按照市物价主管部门批复的轨道交通网络票价体系,即:轨道交通实行按里程计价的多级票价,0~6公里3元,6公里之后每10公里增加1元;票价计算采用最短路径法,即:当两个站点之间有超过1条换乘路径时,选取里程最短的一条路径作为两站间票价计算依据。

            Console.WriteLine("地铁票价计算");
            Console.WriteLine("-----------------------");
            Console.WriteLine("输入起始站名:");
            var fromStation = Console.ReadLine();

            Console.WriteLine("输入目的地站名:");
            var toStation = Console.ReadLine();

            StationFareRuleModel stations = new StationFareRuleModel();

            stations.FareRuleId       = 1;
            stations.StationDistance  = CountStationsDistance(fromStation, toStation);
            stations.IncrementalPrice = FareConstants.OnStationFare;

            FareCalculatorContext fareCalculatorContext = new FareCalculatorContext(new StationRuleFareCalculator());
            var totalFare = fareCalculatorContext.GetFareDetails(stations, FareConstants.BasicFare);

            Console.WriteLine("-----------------------");
            Console.WriteLine("从 {1} 至 {2},距离 {3}KM,车票价钱为:  {0}元", totalFare, fromStation, toStation, stations.StationDistance);
            Console.WriteLine("-----------------------");

            Console.WriteLine("是否是VIP (y/n):");
            var isSeniorCitize = Console.ReadKey();

            if (isSeniorCitize.Key == ConsoleKey.Y)
            {
                VIPFareRuleModel ageFareRuleModel = new VIPFareRuleModel();
                ageFareRuleModel.FareRuleId = 2;
                ageFareRuleModel.Discount   = FareConstants.VIPDiscount;

                fareCalculatorContext = new FareCalculatorContext(new VIPRuleFareCalculator());
                totalFare             = fareCalculatorContext.GetFareDetails(ageFareRuleModel, totalFare);
                Console.WriteLine("\n-----------------------");
                Console.WriteLine("享受会员折扣");
                Console.WriteLine("从 {1} 至 {2},享受{3}折的优惠,车票价钱为:  {0}元", totalFare, fromStation, toStation, FareConstants.VIPDiscount);
            }

            Console.WriteLine("\n是否还有其它费用 (y/n):");
            var isFestival = Console.ReadKey();

            if (isFestival.Key == ConsoleKey.Y)
            {
                var otherFareRuleModel = new OtherFareRuleModel();
                Console.WriteLine("\n输入费用名称:");
                otherFareRuleModel.FareRuleId    = 3;
                otherFareRuleModel.OtherFareName = Console.ReadLine();
                Console.WriteLine("\n输入费用(元):");
                otherFareRuleModel.AdditionalFare = float.Parse(Console.ReadLine());
                fareCalculatorContext             = new FareCalculatorContext(new OtherRuleFareCalculator());
                totalFare = fareCalculatorContext.GetFareDetails(otherFareRuleModel, totalFare);
                Console.WriteLine("-----------------------");
                Console.WriteLine("总票价");
                Console.WriteLine("从 {1} 至 {2},车票价钱为:  {0}元", totalFare, fromStation, toStation);
            }
        }
Beispiel #2
0
        public void DisplayTrainFare()
        {
            //Fare pricing rules
            //According to the rail transit network fare system approved by the municipal price department, that is:
            //rail transit implements multi-level fare based on mileage, 3 CHF for 0~6 kilometers, 1 CHF for every 10 kilometers after 6 kilometers;
            //fare calculation The shortest path method is adopted, that is, when there is more than one transfer path between two stations, the shortest path is selected as the basis for calculating the fare between the two stations.
            Console.WriteLine("Metro fare calculation");
            Console.WriteLine("-----------------------");
            Console.WriteLine("Enter the starting station name:");
            var fromStation = Console.ReadLine();

            Console.WriteLine("Enter destination station name:");
            var toStation = Console.ReadLine();

            StationFareRuleModel stations = new StationFareRuleModel();

            stations.FareRuleId       = 1;
            stations.StationDistance  = this.CountStationsDistance(fromStation, toStation);
            stations.IncrementalPrice = FareConstants.OnStationFare;

            FareCalculatorContext fareCalculatorContext = new FareCalculatorContext(new StationRuleFareCalculator());
            var totalFare = fareCalculatorContext.GetFareDetails(stations, FareConstants.BasicFare);

            Console.WriteLine("-----------------------");
            Console.WriteLine("from {1} to {2}, distance {3}KM, car fare is: {0} CHF", totalFare, fromStation, toStation, stations.StationDistance);
            Console.WriteLine("-----------------------");

            Console.WriteLine("Is it a VIP (y/n):");
            var isSeniorCitize = Console.ReadKey();

            if (isSeniorCitize.Key == ConsoleKey.Y)
            {
                VIPFareRuleModel ageFareRuleModel = new VIPFareRuleModel();
                ageFareRuleModel.FareRuleId = 2;
                ageFareRuleModel.Discount   = FareConstants.VIPDiscount;

                fareCalculatorContext = new FareCalculatorContext(new VIPRuleFareCalculator());
                totalFare             = fareCalculatorContext.GetFareDetails(ageFareRuleModel, totalFare);
                Console.WriteLine("\n-----------------------");
                Console.WriteLine("Enjoy Member Discount");
                Console.WriteLine("From {1} to {2}, enjoy a {3} discount, the car fare is: {0} CHF", totalFare, fromStation, toStation, FareConstants.VIPDiscount);
            }

            Console.WriteLine("\n is there any other fee (y/n):");
            var isFestival = Console.ReadKey();

            if (isFestival.Key == ConsoleKey.Y)
            {
                var otherFareRuleModel = new OtherFareRuleModel();
                Console.WriteLine("\nEnter the cost name:");
                otherFareRuleModel.FareRuleId    = 3;
                otherFareRuleModel.OtherFareName = Console.ReadLine();
                Console.WriteLine("\nInput fee (CHF):");
                otherFareRuleModel.AdditionalFare = float.Parse(Console.ReadLine());
                fareCalculatorContext             = new FareCalculatorContext(new OtherRuleFareCalculator());
                totalFare = fareCalculatorContext.GetFareDetails(otherFareRuleModel, totalFare);
                Console.WriteLine("-----------------------");
                Console.WriteLine("Total fare");
                Console.WriteLine("From {1} to {2}, car fare is: {0} CHF", totalFare, fromStation, toStation);
            }
        }