void CalculatePrice(NormalTicket ticket) { int tariefeenheden = Tariefeenheden.getTariefeenheden(ticket.From, ticket.To); float p; p = 0.16f * tariefeenheden + 0.82f; // is uit appendix B van Lab 2 if (ticket.Class == 1) { p = p * 1.7f; } if (ticket.International) { p = p + 2f; } if (!ticket.Single) { p = p * 2f; } p *= amount; if (tariefeenheden == 0) { p = 0f; } price = p; }
public static float Calculate(string departure, string destination, UIClass type, UIDiscount discount, bool singleFare) { float ret = 0; int tariefeenheden = Tariefeenheden.getTariefeenheden(departure, destination); switch (type) { case UIClass.FirstClass: ret = FirstClassCalculator.Calculate(tariefeenheden, discount); break; case UIClass.SecondClass: ret = SecondClassCalculator.Calculate(tariefeenheden, discount); break; } if (singleFare) { return(ret); } else { return(ret * 2); } }
private void handlePayment(UIInfo info) { // Get number of tariefeenheden int tariefeenheden = Tariefeenheden.getTariefeenheden(info.From, info.To) // Get price float price = PricingTable.getPrice(tariefeenheden, getColumn(info)); if (info.Way == UIWay.Return) { price *= 2; } //Initialize payment paymethod(price, info.Payment); }
public static float getPrice(Ticket info) { // Get number of tariefeenheden int tariefeenheden = Tariefeenheden.getTariefeenheden(info.From, info.To); // Compute the column in the table based on choices int tableColumn; // First based on class switch (info.Class) { case Class.FirstClass: tableColumn = 3; break; default: tableColumn = 0; break; } // Then, on the discount switch (info.Discount) { case Discount.TwentyDiscount: tableColumn += 1; break; case Discount.FortyDiscount: tableColumn += 2; break; } // Get price float price = PricingTable.getPrice(tariefeenheden, tableColumn); if (info.Way == Way.Return) { price *= 2; } // Add 50 cent if paying with credit card if (info.Payment == Payment.CreditCard) { price += 0.50f; } return(price); }
public float getPrice(UIInfo info) { int tableColumn = getColumn(info); int tariefeenheden = Tariefeenheden.getTariefeenheden(info.From, info.To); float price = PricingTable.getPrice(tariefeenheden, tableColumn); if (info.Way == UIWay.Return) { price *= 2; } // Add 50 cent if paying with credit card if (info.Payment == UIPayment.CreditCard) { price += 0.50f; } return(price); }
public static float calcPrice(Ticket ticket, UIDiscount discount, UIPayment payment) { float price = 0; int tariefeenheden = Tariefeenheden.getTariefeenheden(ticket.from, ticket.to); int tableColumn; // First based on class switch (ticket.cls) { case UIClass.FirstClass: tableColumn = 3; break; default: tableColumn = 0; break; } // Then, on the discount switch (discount) { case UIDiscount.TwentyDiscount: tableColumn += 1; break; case UIDiscount.FortyDiscount: tableColumn += 2; break; } // Get price price = PricingTable.getPrice(tariefeenheden, tableColumn); if (ticket.way == UIWay.Return) { price *= 2; } // Add 50 cent if paying with credit card if (payment == UIPayment.CreditCard) { price += 0.50f; } return(price); }
public float GetCost() { // Get number of tariefeenheden int tariefeenheden = Tariefeenheden.getTariefeenheden(from, to); // Compute the column in the table based on choices int tableColumn; // First based on class tableColumn = seatClass.GetColumn(); // Then, on the discount tableColumn = discount.AddDiscount(tableColumn); // Get price float price = PricingTable.getPrice(tariefeenheden, tableColumn); if (way == UIWay.Return) { price *= 2; } return(price); }
private void handlePayment(UIInfo info) { // ************************************* // This is the code you need to refactor // ************************************* // Get number of tariefeenheden int tariefeenheden = Tariefeenheden.getTariefeenheden(info.From, info.To); // Compute the column in the table based on choices int tableColumn = getColumn(info); // Get price float price = PricingTable.getPrice(tariefeenheden, tableColumn); if (info.Way == UIWay.Return) { price *= 2; } makePayment(info.Payment, price); }
public GetPrice(UIClass klasse, UIDiscount discount, String destination, String origin, UIWay way) { // Get number of tariefeenheden int tariefeenheden = Tariefeenheden.getTariefeenheden(origin, destination); // Compute the column in the table based on choices int tableColumn; // First based on class switch (klasse) { case UIClass.FirstClass: tableColumn = 3; break; default: tableColumn = 0; break; } // Then, on the discount switch (discount) { case UIDiscount.TwentyDiscount: tableColumn += 1; break; case UIDiscount.FortyDiscount: tableColumn += 2; break; } // Get price price = PricingTable.getPrice(tariefeenheden, tableColumn); if (way == UIWay.Return) { price *= 2; } }
private void handlePayment(UIInfo info) { // ************************************* // This is the code you need to refactor // ************************************* // Get number of tariefeenheden int tariefeenheden = Tariefeenheden.getTariefeenheden(info.From, info.To); // Compute the column in the table based on choices int tableColumn; // First based on class switch (info.Class) { case UIClass.FirstClass: tableColumn = 3; break; default: tableColumn = 0; break; } // Then, on the discount switch (info.Discount) { case UIDiscount.TwentyDiscount: tableColumn += 1; break; case UIDiscount.FortyDiscount: tableColumn += 2; break; } // Get price float price = PricingTable.getPrice(tariefeenheden, tableColumn); if (info.Way == UIWay.Return) { price *= 2; } // Add 50 cent if paying with credit card if (info.Payment == UIPayment.CreditCard) { price += 0.50f; } // Pay switch (info.Payment) { case UIPayment.CreditCard: CreditCard c = new CreditCard(); c.Connect(); int ccid = c.BeginTransaction(price); c.EndTransaction(ccid); break; case UIPayment.DebitCard: DebitCard d = new DebitCard(); d.Connect(); int dcid = d.BeginTransaction(price); d.EndTransaction(dcid); break; case UIPayment.Cash: IKEAMyntAtare2000 coin = new IKEAMyntAtare2000(); coin.starta(); coin.betala((int)Math.Round(price * 100)); coin.stoppa(); break; } }
private void initializeControls() { // Set label this.Text = "MSO Lab Exercise III"; // this.FormBorderStyle = FormBorderStyle.FixedSingle; this.Width = 500; this.Height = 210; // Set layout var grid = new TableLayoutPanel(); grid.Dock = DockStyle.Fill; grid.Padding = new Padding(5); this.Controls.Add(grid); grid.RowCount = 4; grid.RowStyles.Add(new RowStyle(SizeType.Absolute, 20)); grid.RowStyles.Add(new RowStyle(SizeType.Percent, 100)); grid.RowStyles.Add(new RowStyle(SizeType.Absolute, 20)); grid.RowStyles.Add(new RowStyle(SizeType.Absolute, 40)); grid.ColumnCount = 6; for (int i = 0; i < 6; i++) { ColumnStyle c = new ColumnStyle(SizeType.Percent, 16.66666f); grid.ColumnStyles.Add(c); } // Create From and To var fromLabel = new Label(); fromLabel.Text = "From:"; fromLabel.TextAlign = ContentAlignment.MiddleRight; grid.Controls.Add(fromLabel, 0, 0); fromLabel.Dock = DockStyle.Fill; fromBox = new ComboBox(); fromBox.DropDownStyle = ComboBoxStyle.DropDownList; fromBox.Items.AddRange(Tariefeenheden.getStations()); fromBox.SelectedIndex = 0; grid.Controls.Add(fromBox, 1, 0); grid.SetColumnSpan(fromBox, 2); fromBox.Dock = DockStyle.Fill; var toLabel = new Label(); toLabel.Text = "To:"; toLabel.TextAlign = ContentAlignment.MiddleRight; grid.Controls.Add(toLabel, 3, 0); toLabel.Dock = DockStyle.Fill; toBox = new ComboBox(); toBox.DropDownStyle = ComboBoxStyle.DropDownList; toBox.Items.AddRange(Tariefeenheden.getStations()); toBox.SelectedIndex = 0; grid.Controls.Add(toBox, 4, 0); grid.SetColumnSpan(toBox, 2); toBox.Dock = DockStyle.Fill; // Create groups GroupBox classGroup = new GroupBox(); classGroup.Text = "Class"; classGroup.Dock = DockStyle.Fill; grid.Controls.Add(classGroup, 0, 1); grid.SetColumnSpan(classGroup, 2); var classGrid = new TableLayoutPanel(); classGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); classGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); classGrid.Dock = DockStyle.Fill; classGroup.Controls.Add(classGrid); GroupBox wayGroup = new GroupBox(); wayGroup.Text = "Amount"; wayGroup.Dock = DockStyle.Fill; grid.Controls.Add(wayGroup, 2, 1); grid.SetColumnSpan(wayGroup, 2); var wayGrid = new TableLayoutPanel(); wayGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); wayGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); wayGrid.Dock = DockStyle.Fill; wayGroup.Controls.Add(wayGrid); GroupBox discountGroup = new GroupBox(); discountGroup.Text = "Discount"; discountGroup.Dock = DockStyle.Fill; grid.Controls.Add(discountGroup, 4, 1); grid.SetColumnSpan(discountGroup, 2); var discountGrid = new TableLayoutPanel(); discountGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33333f)); discountGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33333f)); discountGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33333f)); discountGrid.Dock = DockStyle.Fill; discountGroup.Controls.Add(discountGrid); // Create radio buttons firstClass = new RadioButton(); firstClass.Text = "1st class"; firstClass.Checked = true; classGrid.Controls.Add(firstClass); secondClass = new RadioButton(); secondClass.Text = "2nd class"; classGrid.Controls.Add(secondClass); oneWay = new RadioButton(); oneWay.Text = "One-way"; oneWay.Checked = true; wayGrid.Controls.Add(oneWay); returnWay = new RadioButton(); returnWay.Text = "Return"; wayGrid.Controls.Add(returnWay); noDiscount = new RadioButton(); noDiscount.Text = "No discount"; noDiscount.Checked = true; discountGrid.Controls.Add(noDiscount); twentyDiscount = new RadioButton(); twentyDiscount.Text = "20% discount"; discountGrid.Controls.Add(twentyDiscount); fortyDiscount = new RadioButton(); fortyDiscount.Text = "40% discount"; discountGrid.Controls.Add(fortyDiscount); // Payment option Label paymentLabel = new Label(); paymentLabel.Text = "Payment by:"; paymentLabel.Dock = DockStyle.Fill; paymentLabel.TextAlign = ContentAlignment.MiddleRight; grid.Controls.Add(paymentLabel, 0, 2); payment = new ComboBox(); payment.DropDownStyle = ComboBoxStyle.DropDownList; payment.Items.AddRange(new String[] { "Credit card", "Debit card", "Cash" }); payment.SelectedIndex = 0; payment.Dock = DockStyle.Fill; grid.Controls.Add(payment, 1, 2); grid.SetColumnSpan(payment, 5); // Pay button pay = new Button(); pay.Text = "Pay"; pay.Dock = DockStyle.Fill; grid.Controls.Add(pay, 0, 3); grid.SetColumnSpan(pay, 6); // Set up event pay.Click += (object sender, EventArgs e) => handlePayment(getUIInfo()); }
public int getTariefeenheden(UIInfo info) { int tariefeenheden = Tariefeenheden.getTariefeenheden(info.From, info.To); return(tariefeenheden); }
public UI() { initializeControls(); Tariefeenheden.Tabel(); }
public int getDistance() { tarief_eenheden = Tariefeenheden.getTariefeenheden(dep_station, arr_station); return(tarief_eenheden); }
private void initializeControls() { // Set label Text = "MSO Lab Exercise III"; // this.FormBorderStyle = FormBorderStyle.FixedSingle; Width = 700; Height = 310; // Set layout var grid = new TableLayoutPanel(); grid.Dock = DockStyle.Fill; grid.Padding = new Padding(5); Controls.Add(grid); grid.RowCount = 4; grid.RowStyles.Add(new RowStyle(SizeType.Absolute, 20)); grid.RowStyles.Add(new RowStyle(SizeType.Percent, 100)); grid.RowStyles.Add(new RowStyle(SizeType.Absolute, 20)); grid.RowStyles.Add(new RowStyle(SizeType.Absolute, 40)); grid.ColumnCount = 6; for (int i = 0; i < 6; i++) { ColumnStyle c = new ColumnStyle(SizeType.Percent, 22.0f); //ColumnStyle c = new ColumnStyle(SizeType.AutoSize); grid.ColumnStyles.Add(c); } // Create From and To var fromLabel = new Label(); fromLabel.Text = "From:"; fromLabel.TextAlign = ContentAlignment.MiddleRight; grid.Controls.Add(fromLabel, 0, 0); fromLabel.Dock = DockStyle.Fill; fromBox = new ComboBox(); fromBox.DropDownStyle = ComboBoxStyle.DropDownList; fromBox.Items.AddRange(Tariefeenheden.getStations()); fromBox.SelectedIndex = 0; grid.Controls.Add(fromBox, 1, 0); grid.SetColumnSpan(fromBox, 2); fromBox.Dock = DockStyle.Fill; var toLabel = new Label(); toLabel.Text = "To:"; toLabel.TextAlign = ContentAlignment.MiddleRight; grid.Controls.Add(toLabel, 3, 0); toLabel.Dock = DockStyle.Fill; toBox = new ComboBox(); toBox.DropDownStyle = ComboBoxStyle.DropDownList; toBox.Items.AddRange(Tariefeenheden.getStations()); toBox.SelectedIndex = 0; grid.Controls.Add(toBox, 4, 0); grid.SetColumnSpan(toBox, 2); toBox.Dock = DockStyle.Fill; // Create groups GroupBox classGroup = new GroupBox(); classGroup.Text = "Class"; classGroup.Dock = DockStyle.Fill; grid.Controls.Add(classGroup, 0, 1); grid.SetColumnSpan(classGroup, 1); var classGrid = new TableLayoutPanel(); classGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); classGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); classGrid.Dock = DockStyle.Fill; classGroup.Controls.Add(classGrid); GroupBox wayGroup = new GroupBox(); wayGroup.Text = "Amount"; wayGroup.Dock = DockStyle.Fill; grid.Controls.Add(wayGroup, 1, 1); grid.SetColumnSpan(wayGroup, 1); var wayGrid = new TableLayoutPanel(); wayGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); wayGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); wayGrid.Dock = DockStyle.Fill; wayGroup.Controls.Add(wayGrid); //new GroupBox IntGroup = new GroupBox(); IntGroup.Text = "International"; IntGroup.Dock = DockStyle.Fill; grid.Controls.Add(IntGroup, 2, 1); grid.SetColumnSpan(IntGroup, 1); var IntGrid = new TableLayoutPanel(); IntGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50.0f)); IntGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50.0f)); IntGrid.Dock = DockStyle.Fill; IntGroup.Controls.Add(IntGrid); GroupBox DayGroup = new GroupBox(); DayGroup.Text = "Choose Day"; DayGroup.Dock = DockStyle.Fill; grid.Controls.Add(DayGroup, 4, 1); grid.SetColumnSpan(DayGroup, 1); var DayGrid = new TableLayoutPanel(); DayGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50.0f)); DayGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50.0f)); DayGrid.Dock = DockStyle.Fill; DayGroup.Controls.Add(DayGrid); //verplaatst GroupBox discountGroup = new GroupBox(); discountGroup.Text = "# of tickets"; discountGroup.Dock = DockStyle.Fill; grid.Controls.Add(discountGroup, 5, 1); grid.SetColumnSpan(discountGroup, 1); var discountGrid = new TableLayoutPanel(); discountGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33333f)); discountGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33333f)); discountGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33333f)); discountGrid.Dock = DockStyle.Fill; discountGroup.Controls.Add(discountGrid); // Create radio buttons firstClass = new RadioButton(); firstClass.Text = "1st class"; classGrid.Controls.Add(firstClass); secondClass = new RadioButton(); secondClass.Text = "2nd class"; secondClass.Checked = true; classGrid.Controls.Add(secondClass); oneWay = new RadioButton(); oneWay.Text = "One-way"; oneWay.Checked = true; wayGrid.Controls.Add(oneWay); returnWay = new RadioButton(); returnWay.Text = "Return"; wayGrid.Controls.Add(returnWay); //discount Ticket1 = new RadioButton(); Ticket1.Text = "1"; Ticket1.Checked = true; discountGrid.Controls.Add(Ticket1); Ticket2 = new RadioButton(); Ticket2.Text = "2"; discountGrid.Controls.Add(Ticket2); Ticket3 = new RadioButton(); Ticket3.Text = "3"; discountGrid.Controls.Add(Ticket3); //new International = new RadioButton(); International.Text = "International"; IntGrid.Controls.Add(International); Local = new RadioButton(); Local.Text = "Local"; Local.Checked = true; IntGrid.Controls.Add(Local); //new Today = new RadioButton(); Today.Text = "Today"; Today.Checked = true; DayGrid.Controls.Add(Today); Otherday = new RadioButton(); Otherday.Text = "Other Day"; DayGrid.Controls.Add(Otherday); // Pay button pay = new Button(); pay.Text = "Pay"; pay.Dock = DockStyle.Fill; grid.Controls.Add(pay, 0, 3); grid.SetColumnSpan(pay, 6); // Set up event pay.Click += (object sender, EventArgs e) => handlePayment(MakeTicket()); }