Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C-Sharp University needs you to create a form that accepts a lunch order from the student and then calculates the order subtotal and total. The

C-Sharp University needs you to create a form that accepts a lunch order from the student and then calculates the order subtotal and total.

image text in transcribed

The application should provide for these main courses and add-ons:

image text in transcribed

1. Start Visual Studio.

2. Click the Create Project hyperlink or use the File-New Project menu option.

3. In the New Project dialog box type a name for the projectname the project Lab10-SectionTime-YourLastName-YourFirstName

4. Change the forms File Name property from Form1.vb to a new name Lab10.cs

5. Change the title of the form as shown above.

6. Add labels, text boxes, and buttons to the default form and set the properties of the form and its controls so they appear as shown above. When the user presses the Esc key, the Click event of the Exit button should fire. When the user presses the Enter key, the Click event for the Place Order button should fire.

7. Add three radio buttons to the Main Course group box, and set their properties so they appear as shown above. The Hamburger option should be selected by default.

8. Add a group box for the add-on items. Then, add three check boxes to this group box as shown above. None of the check boxes should be selected by default.

9. Code a method name ClearTotals that clears the three text boxes and a method named ClearAddOns that removes the check marks from the three check boxes.

10. Code an event handler (this will reference the three radio button checked changed event listed on the form) that changes the text thats displayed for the Add-ons group box and the three check boxes when the user selects a different main course.

image text in transcribed

Create a MainCourse CheckedChanged event that references all three radio buttons Use If Else If statements to test each radio to see if it is checked and if so the text property of each add on item will change. Example below:

image text in transcribed

Clear the Add on check boxes by calling the ClearAddOns() method and Clear the totals by calling the ClearTotals() method.

Test the application to be sure this works correctly.

11. Code the Place Order event handler that calculates and displays the subtotal, tax, and order total when the user clicks the Place Order button. Test the application to be sure this works correctly.

Use a series of If statement to test to see if each add on item check box is checked and if so accumulate the total

Use a series of If Else If statements to test to see if each Main course radio button is check and if so charge the price of the main course + (add on item amount times the price of $.75, $.50, or $.25). This is the subtotal amount.

The tax is 7.75% of the subtotal.

And the order total is the subtotal plus the tax.

12. Code an event handler called ChangeAddOns that clears the order totals when the user checks or unchecks an add-on. You will have 3 checked changed references created for the each checkbox add ons. Call the ClearTotals method you have already created. Then, test the application one more time.

Here is the code I have so far:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;

namespace Lab10_200_Cooper_Clayton { public partial class Lab10 : Form {

public Lab10() { InitializeComponent(); }

private void rdoHamburger_CheckedChanged(object sender, EventArgs e) { ClearAddOns();

gbxAddOnItems.Text = "Add-on Items ($0.75/each)"; chkAddOn1.Text = "Lettuce, tomatoes, and onions"; chkAddOn2.Text = "Ketchup, mustard, and mayo"; chkAddOn3.Text = "French Fries";

}

private void rdoPizza_CheckedChanged(object sender, EventArgs e) { ClearAddOns();

gbxAddOnItems.Text = "Add-on Items ($0.50/each)"; chkAddOn1.Text = "Pepperoni"; chkAddOn2.Text = "Sausage"; chkAddOn3.Text = "Onions";

}

private void rdoSalad_CheckedChanged(object sender, EventArgs e) { ClearAddOns();

gbxAddOnItems.Text = "Add-on Items ($0.25/each)"; chkAddOn1.Text = "Croutons"; chkAddOn2.Text = "Bacon Bits"; chkAddOn3.Text = "Bread Sticks"; }

private void ClearAddOns() { chkAddOn1.Checked = false; chkAddOn2.Checked = false; chkAddOn3.Checked = false; }

private void btnPlaceOrder_Click(object sender, EventArgs e) { if (rdoHamburger.Checked == true) { double AddOn = 0.75; double MainCourse = 6.95;

double Subtotal = MainCourse + AddOn; double Tax = 7.75 / 100; double OrderTotal = ((Subtotal * Tax) + Subtotal);

txtSubtotal.Text = Convert.ToString(Subtotal); txtTax.Text = Convert.ToString(Tax); txtOrderTotal.Text = Convert.ToString(OrderTotal); }

else if (rdoPizza.Checked == true) { double AddOn = 0.50; double MainCourse = 5.95;

double Subtotal = MainCourse + AddOn; double Tax = 7.75 / 100; double OrderTotal = ((Subtotal * Tax) + Subtotal);

txtSubtotal.Text = Convert.ToString(Subtotal); txtTax.Text = Convert.ToString(Tax); txtOrderTotal.Text = Convert.ToString(OrderTotal); }

else if (rdoSalad.Checked == true) { double AddOn = 0.25; double MainCourse = 4.95;

double Subtotal = MainCourse + AddOn; double Tax = 7.75 / 100; double OrderTotal = ((Subtotal * Tax) + Subtotal);

txtSubtotal.Text = Convert.ToString(Subtotal); txtTax.Text = Convert.ToString(Tax); txtOrderTotal.Text = Convert.ToString(OrderTotal); }

}

private void btnExit_Click(object sender, EventArgs e) { this.Close(); }

} }

Here is the designer code:

namespace Lab10_200_Cooper_Clayton { partial class Lab10 { ///

/// Required designer variable. /// private System.ComponentModel.IContainer components = null;

///

/// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }

#region Windows Form Designer generated code

///

/// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.gbxMainCourse = new System.Windows.Forms.GroupBox(); this.rdoSalad = new System.Windows.Forms.RadioButton(); this.rdoPizza = new System.Windows.Forms.RadioButton(); this.rdoHamburger = new System.Windows.Forms.RadioButton(); this.gbxAddOnItems = new System.Windows.Forms.GroupBox(); this.chkAddOn3 = new System.Windows.Forms.CheckBox(); this.chkAddOn2 = new System.Windows.Forms.CheckBox(); this.chkAddOn1 = new System.Windows.Forms.CheckBox(); this.gbxOrderTotals = new System.Windows.Forms.GroupBox(); this.lblOrderTotal = new System.Windows.Forms.Label(); this.lblTax = new System.Windows.Forms.Label(); this.lblSubtotal = new System.Windows.Forms.Label(); this.txtOrderTotal = new System.Windows.Forms.TextBox(); this.txtTax = new System.Windows.Forms.TextBox(); this.txtSubtotal = new System.Windows.Forms.TextBox(); this.btnPlaceOrder = new System.Windows.Forms.Button(); this.btnExit = new System.Windows.Forms.Button(); this.gbxMainCourse.SuspendLayout(); this.gbxAddOnItems.SuspendLayout(); this.gbxOrderTotals.SuspendLayout(); this.SuspendLayout(); // // gbxMainCourse // this.gbxMainCourse.Controls.Add(this.rdoSalad); this.gbxMainCourse.Controls.Add(this.rdoPizza); this.gbxMainCourse.Controls.Add(this.rdoHamburger); this.gbxMainCourse.Location = new System.Drawing.Point(12, 12); this.gbxMainCourse.Name = "gbxMainCourse"; this.gbxMainCourse.Size = new System.Drawing.Size(170, 166); this.gbxMainCourse.TabIndex = 0; this.gbxMainCourse.TabStop = false; this.gbxMainCourse.Text = "Main Course"; // // rdoSalad // this.rdoSalad.AutoSize = true; this.rdoSalad.Location = new System.Drawing.Point(7, 121); this.rdoSalad.Name = "rdoSalad"; this.rdoSalad.Size = new System.Drawing.Size(114, 21); this.rdoSalad.TabIndex = 2; this.rdoSalad.TabStop = true; this.rdoSalad.Text = "Salad - $4.95"; this.rdoSalad.UseVisualStyleBackColor = true; this.rdoSalad.CheckedChanged += new System.EventHandler(this.rdoSalad_CheckedChanged); // // rdoPizza // this.rdoPizza.AutoSize = true; this.rdoPizza.Location = new System.Drawing.Point(7, 77); this.rdoPizza.Name = "rdoPizza"; this.rdoPizza.Size = new System.Drawing.Size(112, 21); this.rdoPizza.TabIndex = 1; this.rdoPizza.TabStop = true; this.rdoPizza.Text = "Pizza - $5.95"; this.rdoPizza.UseVisualStyleBackColor = true; this.rdoPizza.CheckedChanged += new System.EventHandler(this.rdoPizza_CheckedChanged); // // rdoHamburger // this.rdoHamburger.AutoSize = true; this.rdoHamburger.Location = new System.Drawing.Point(7, 33); this.rdoHamburger.Name = "rdoHamburger"; this.rdoHamburger.Size = new System.Drawing.Size(149, 21); this.rdoHamburger.TabIndex = 0; this.rdoHamburger.TabStop = true; this.rdoHamburger.Text = "Hamburger - $6.95"; this.rdoHamburger.UseVisualStyleBackColor = true; this.rdoHamburger.CheckedChanged += new System.EventHandler(this.rdoHamburger_CheckedChanged); // // gbxAddOnItems // this.gbxAddOnItems.Controls.Add(this.chkAddOn3); this.gbxAddOnItems.Controls.Add(this.chkAddOn2); this.gbxAddOnItems.Controls.Add(this.chkAddOn1); this.gbxAddOnItems.Location = new System.Drawing.Point(188, 12); this.gbxAddOnItems.Name = "gbxAddOnItems"; this.gbxAddOnItems.Size = new System.Drawing.Size(245, 166); this.gbxAddOnItems.TabIndex = 1; this.gbxAddOnItems.TabStop = false; this.gbxAddOnItems.Text = "Add-on Items ($.75/each)"; // // chkAddOn3 // this.chkAddOn3.AutoSize = true; this.chkAddOn3.Location = new System.Drawing.Point(6, 121); this.chkAddOn3.Name = "chkAddOn3"; this.chkAddOn3.Size = new System.Drawing.Size(109, 21); this.chkAddOn3.TabIndex = 2; this.chkAddOn3.Text = "French Fries"; this.chkAddOn3.UseVisualStyleBackColor = true; // // chkAddOn2 // this.chkAddOn2.AutoSize = true; this.chkAddOn2.Location = new System.Drawing.Point(6, 77); this.chkAddOn2.Name = "chkAddOn2"; this.chkAddOn2.Size = new System.Drawing.Size(211, 21); this.chkAddOn2.TabIndex = 1; this.chkAddOn2.Text = "Ketchup, mustard, and mayo"; this.chkAddOn2.UseVisualStyleBackColor = true; // // chkAddOn1 // this.chkAddOn1.AutoSize = true; this.chkAddOn1.Location = new System.Drawing.Point(6, 34); this.chkAddOn1.Name = "chkAddOn1"; this.chkAddOn1.Size = new System.Drawing.Size(206, 21); this.chkAddOn1.TabIndex = 0; this.chkAddOn1.Text = "Lettuce, tomato, and onions"; this.chkAddOn1.UseVisualStyleBackColor = true; // // gbxOrderTotals // this.gbxOrderTotals.Controls.Add(this.lblOrderTotal); this.gbxOrderTotals.Controls.Add(this.lblTax); this.gbxOrderTotals.Controls.Add(this.lblSubtotal); this.gbxOrderTotals.Controls.Add(this.txtOrderTotal); this.gbxOrderTotals.Controls.Add(this.txtTax); this.gbxOrderTotals.Controls.Add(this.txtSubtotal); this.gbxOrderTotals.Location = new System.Drawing.Point(12, 199); this.gbxOrderTotals.Name = "gbxOrderTotals"; this.gbxOrderTotals.Size = new System.Drawing.Size(248, 146); this.gbxOrderTotals.TabIndex = 2; this.gbxOrderTotals.TabStop = false; this.gbxOrderTotals.Text = "Order Total"; // // lblOrderTotal // this.lblOrderTotal.AutoSize = true; this.lblOrderTotal.Location = new System.Drawing.Point(51, 81); this.lblOrderTotal.Name = "lblOrderTotal"; this.lblOrderTotal.Size = new System.Drawing.Size(85, 17); this.lblOrderTotal.TabIndex = 5; this.lblOrderTotal.Text = "Order Total:"; // // lblTax // this.lblTax.AutoSize = true; this.lblTax.Location = new System.Drawing.Point(47, 52); this.lblTax.Name = "lblTax"; this.lblTax.Size = new System.Drawing.Size(89, 17); this.lblTax.TabIndex = 4; this.lblTax.Text = "Tax (7.75%):"; // // lblSubtotal // this.lblSubtotal.AutoSize = true; this.lblSubtotal.Location = new System.Drawing.Point(72, 24); this.lblSubtotal.Name = "lblSubtotal"; this.lblSubtotal.Size = new System.Drawing.Size(64, 17); this.lblSubtotal.TabIndex = 3; this.lblSubtotal.Text = "Subtotal:"; // // txtOrderTotal // this.txtOrderTotal.Location = new System.Drawing.Point(142, 78); this.txtOrderTotal.Name = "txtOrderTotal"; this.txtOrderTotal.ReadOnly = true; this.txtOrderTotal.Size = new System.Drawing.Size(100, 22); this.txtOrderTotal.TabIndex = 2; // // txtTax // this.txtTax.Location = new System.Drawing.Point(142, 49); this.txtTax.Name = "txtTax"; this.txtTax.ReadOnly = true; this.txtTax.Size = new System.Drawing.Size(100, 22); this.txtTax.TabIndex = 1; // // txtSubtotal // this.txtSubtotal.Location = new System.Drawing.Point(142, 21); this.txtSubtotal.Name = "txtSubtotal"; this.txtSubtotal.ReadOnly = true; this.txtSubtotal.Size = new System.Drawing.Size(100, 22); this.txtSubtotal.TabIndex = 0; // // btnPlaceOrder // this.btnPlaceOrder.Location = new System.Drawing.Point(290, 223); this.btnPlaceOrder.Name = "btnPlaceOrder"; this.btnPlaceOrder.Size = new System.Drawing.Size(110, 23); this.btnPlaceOrder.TabIndex = 3; this.btnPlaceOrder.Text = "Place &Order"; this.btnPlaceOrder.UseVisualStyleBackColor = true; // // btnExit // this.btnExit.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.btnExit.Location = new System.Drawing.Point(290, 252); this.btnExit.Name = "btnExit"; this.btnExit.Size = new System.Drawing.Size(110, 23); this.btnExit.TabIndex = 4; this.btnExit.Text = "E&xit"; this.btnExit.UseVisualStyleBackColor = true; this.btnExit.Click += new System.EventHandler(this.btnExit_Click); // // Lab10 // this.AcceptButton = this.btnPlaceOrder; this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.btnExit; this.ClientSize = new System.Drawing.Size(451, 369); this.Controls.Add(this.btnExit); this.Controls.Add(this.btnPlaceOrder); this.Controls.Add(this.gbxOrderTotals); this.Controls.Add(this.gbxAddOnItems); this.Controls.Add(this.gbxMainCourse); this.Name = "Lab10"; this.Text = "Lunch Order"; this.gbxMainCourse.ResumeLayout(false); this.gbxMainCourse.PerformLayout(); this.gbxAddOnItems.ResumeLayout(false); this.gbxAddOnItems.PerformLayout(); this.gbxOrderTotals.ResumeLayout(false); this.gbxOrderTotals.PerformLayout(); this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.GroupBox gbxMainCourse; private System.Windows.Forms.GroupBox gbxAddOnItems; private System.Windows.Forms.GroupBox gbxOrderTotals; private System.Windows.Forms.RadioButton rdoSalad; private System.Windows.Forms.RadioButton rdoPizza; private System.Windows.Forms.RadioButton rdoHamburger; private System.Windows.Forms.CheckBox chkAddOn3; private System.Windows.Forms.CheckBox chkAddOn2; private System.Windows.Forms.CheckBox chkAddOn1; private System.Windows.Forms.Label lblOrderTotal; private System.Windows.Forms.Label lblTax; private System.Windows.Forms.Label lblSubtotal; private System.Windows.Forms.TextBox txtOrderTotal; private System.Windows.Forms.TextBox txtTax; private System.Windows.Forms.TextBox txtSubtotal; private System.Windows.Forms.Button btnPlaceOrder; private System.Windows.Forms.Button btnExit; } }

Lunch Order Main course Add-on items (S.75/each) (0 Hamburger-S6.95 Pizza -$5.95 Salad -$4.95 Lettuce, tomato, and onions Ketchup, mustard, and mayo French fries Order tota Place Order Subtotal: Tax (7.75%): Order total: Egit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What magazine and ads did you choose to examine?

Answered: 1 week ago