private LiftPass SelectType() { string input; int value; int i = 1; do { if (i > 1) { Console.WriteLine("Invalid input!", Color.Pink); } Console.WriteLine("\nSelects type of pass: (1 ... 10)"); input = Console.ReadLine(); i++; } while (!int.TryParse(input, out value) || value < 1 || value > 10); LiftPass liftPass = liftPassController.GetByType(value); return(liftPass); }
/// <summary> /// This method calculates the price or every type of lift pass. /// </summary> /// <param name="liftPass">The lift pass chosen by the user.</param> /// <returns>Returns the price of the lift pass by the type of the lift pass.</returns> public double CalculatePrice(LiftPass liftPass) { double price = liftPass.Price; switch (liftPass.Type) { case "Kid": price *= KidsDiscount; break; case "Student": price *= StudentsAndRetieredDiscount; break; case "Retired": price *= StudentsAndRetieredDiscount; break; default: break; } return(price); }
private void Buy() { ListAllTypes(); LiftPass liftPass = SelectType(); string type; int i = 1; do { if (i > 1) { Console.WriteLine("Invalid input!", Color.Pink); } Console.WriteLine("\nAre you a (Adult / Kid / Student / Retired):"); type = Console.ReadLine(); i++; } while (type.ToLower() != "adult" && type.ToLower() != "kid" && type.ToLower() != "student" && type.ToLower() != "retired"); liftPass.Type = FirstCharToUpper(type); var price = liftPassController.CalculatePrice(liftPass); Console.WriteLine($"\nIt costs {price} lv. ", Color.LightGreen); boughtPasses.Add(liftPass); Console.WriteLine(); Console.WriteLine(new string('-', 52), Color.LightGoldenrodYellow); Console.WriteLine(new string(' ', 19) + "You have bought:", Color.LightGoldenrodYellow); Console.WriteLine(new string('-', 52), Color.LightGoldenrodYellow); foreach (var pass in boughtPasses) { Console.WriteLine(new string(' ', 18) + $"{pass.Description} for {pass.Type} "); Console.WriteLine(); } }