public Payment(DateTime pd, int p, string pm, string pt, SeasonPass sp) { purchaseDate = pd; price = p; paymentMode = pm; //credit, visa purchaseType = pt; // type of trasaction - SeasonPass - Car, SeasonPass - Motorbike, SeasonPass - Lorry sp.AddPayment(this); }
public void Renew() { int price = 0; bool status = true; while (status) //if user did not confirm { Console.WriteLine("----Renew Season Parking Pass----"); Console.Write("Please enter no. of months you want to renew: "); string rpMonth = Console.ReadLine(); int rpm; bool r = Int32.TryParse(rpMonth, out rpm); if (!r) { Console.WriteLine(); Console.WriteLine("Please enter valid number"); return; } if (rpm < 0 || rpm > 15) { Console.WriteLine("Please enter a valid month between 1 -12"); return; } Console.WriteLine("Renewing season parking pass..."); Console.WriteLine("Extend season parking pass for another " + rpm + " month(s)"); string confirmation = Confirm(""); if (confirmation.ToLower() == "y") { Console.WriteLine("You decide to renew " + rpm + " month(s) of your season parking pass"); Console.WriteLine(); Console.WriteLine("Calculating season pass amount..."); if (vsp.VehicleType == "Car" || vsp.VehicleType == "Lorry") //if seasonpass is car type { price = 80; int amt = price * rpm; Console.WriteLine("Amount needed to pay: $" + amt); Console.WriteLine("Pass successfully extended for " + rpm + " month(s)"); //add payment record Payment p = new Payment(DateTime.Now, amt, "Credit", "Surface", vsp); p.makePayment(); vsp.AddPayment(p); } else if (vsp.VehicleType == "Motorbike") { //if seasonpass is motorbike type price = 15; int amt = price * rpm; Console.WriteLine("Amount needed to pay: $" + amt); Console.WriteLine("Pass successfully extended for " + rpm + " month(s)"); //add payment record Payment p = new Payment(DateTime.Now, amt, "Credit", "Surface", vsp); p.makePayment(); vsp.AddPayment(p); } //add number of months extended by user //vsp.EndDate.AddMonths(rpm); //vsp.RemainingMonth = vsp.RemainingMonth + rpm; //add input month to remaining month vsp.StartDate = DateTime.Now; vsp.EndDate = DateTime.Now.AddMonths(rpm); vsp.RemainingMonth = vsp.EndDate.Month - vsp.StartDate.Month; vsp.SetCurrentState(vsp.GetValidState()); //set season pass state to valid Console.WriteLine("The remianing month of your pass is {0} month(s)", vsp.RemainingMonth); Console.WriteLine("Your Season Pass New Expiry Date: {0}", vsp.EndDate); status = false; } } }