Create an app to calculate the cost of a night of bowling including snacks. Chec
ID: 3737682 • Letter: C
Question
Create an app to calculate the cost of a night of bowling including snacks. Check that the user enters a numeric value and if not, display an error message. The fees are as follow:
1) Cost per game is $5.00 2) Cost for shoe rental is a flat fee of $2.50 3) Cost for chips is $1.00 4) Cost for soda is $1.00 5) Cost for pizza is $2.00
if a bowler has a coupon, there is a $2.00 discount on the total cost.
Make sure to code a Clear and Close function. Make sure your app includes all the specifications on page one (listed with the point value for each item)
Bowling Total cost is sx.XX Create an app to calculate the cost of a night of bowling including snacks. Check that the user enters a numeric value and if not, display an error message. The fees are as follows .Cost per game is $5.00 . Cost for shoe rental is a flat fee of $2.50 .Cost for chips is $1.00 . Cost for soda is $1.00 . Cost for pizza is $2.50 If a bowler has a coupon, there is a $2.00 discount on the total cost. Make sure to code a Clear and Close function. Make sure your app includes all the specifications on page one (listed with the point value for each item).Explanation / Answer
Form1.cs file in VB:
Imports System
Imports System.Drawing
Imports System.IO
Imports System.Net
Imports System.Windows.Forms
Namespace WindowsFormsApplication2
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim value As Integer
If Integer.TryParse(textBox1.Text, value) Then
Dim games As Double = Convert.ToInt16(textBox1.Text)
games =(games * 5) + 2.5
If radioButton1.Checked = True Then
games = games - 2
End If
If checkBox1.Checked = True Then
games = games + 1
End If
If checkBox2.Checked = True Then
games = games + 1
End If
If checkBox3.Checked = True Then
games = games + 2
End If
textBox2.Text = Convert.ToString(games)
Else
MessageBox.Show("enter numeric values")
End If
End Sub
Private Sub label1_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Private Sub label5_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Private Sub textBox2_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
End Sub
End Class
End Namespace
Designer.cs in Vb:
Namespace WindowsFormsApplication2
Partial Class Form1
Private components As System.ComponentModel.IContainer = Nothing
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso (components IsNot Nothing) Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
Private Sub InitializeComponent()
Me.textBox1 = New System.Windows.Forms.TextBox()
Me.button1 = New System.Windows.Forms.Button()
Me.label1 = New System.Windows.Forms.Label()
Me.label2 = New System.Windows.Forms.Label()
Me.label3 = New System.Windows.Forms.Label()
Me.checkBox1 = New System.Windows.Forms.CheckBox()
Me.checkBox2 = New System.Windows.Forms.CheckBox()
Me.checkBox3 = New System.Windows.Forms.CheckBox()
Me.label4 = New System.Windows.Forms.Label()
Me.radioButton1 = New System.Windows.Forms.RadioButton()
Me.radioButton2 = New System.Windows.Forms.RadioButton()
Me.label5 = New System.Windows.Forms.Label()
Me.textBox2 = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
Me.textBox1.Location = New System.Drawing.Point(207, 49)
Me.textBox1.Name = "textBox1"
Me.textBox1.Size = New System.Drawing.Size(84, 26)
Me.textBox1.TabIndex = 3
Me.button1.Location = New System.Drawing.Point(303, 529)
Me.button1.Name = "button1"
Me.button1.Size = New System.Drawing.Size(75, 42)
Me.button1.TabIndex = 4
Me.button1.Text = "Calculate"
Me.button1.UseVisualStyleBackColor = True
Me.button1.Click += New System.EventHandler(Me.button1_Click)
Me.label1.AutoSize = True
Me.label1.Location = New System.Drawing.Point(24, 49)
Me.label1.Name = "label1"
Me.label1.Size = New System.Drawing.Size(135, 20)
Me.label1.TabIndex = 5
Me.label1.Text = "Number of games"
Me.label1.Click += New System.EventHandler(Me.label1_Click)
Me.label2.AutoSize = True
Me.label2.Location = New System.Drawing.Point(45, 144)
Me.label2.Name = "label2"
Me.label2.Size = New System.Drawing.Size(202, 20)
Me.label2.TabIndex = 6
Me.label2.Text = "Cost of shoe rental is $2.50"
Me.label3.AutoSize = True
Me.label3.Location = New System.Drawing.Point(33, 224)
Me.label3.Name = "label3"
Me.label3.Size = New System.Drawing.Size(68, 20)
Me.label3.TabIndex = 7
Me.label3.Text = "snacks?"
Me.checkBox1.AutoSize = True
Me.checkBox1.Location = New System.Drawing.Point(47, 279)
Me.checkBox1.Name = "checkBox1"
Me.checkBox1.Size = New System.Drawing.Size(72, 24)
Me.checkBox1.TabIndex = 8
Me.checkBox1.Text = "chips"
Me.checkBox1.UseVisualStyleBackColor = True
Me.checkBox2.AutoSize = True
Me.checkBox2.Location = New System.Drawing.Point(54, 326)
Me.checkBox2.Name = "checkBox2"
Me.checkBox2.Size = New System.Drawing.Size(70, 24)
Me.checkBox2.TabIndex = 9
Me.checkBox2.Text = "soda"
Me.checkBox2.UseVisualStyleBackColor = True
Me.checkBox3.AutoSize = True
Me.checkBox3.Location = New System.Drawing.Point(61, 374)
Me.checkBox3.Name = "checkBox3"
Me.checkBox3.Size = New System.Drawing.Size(72, 24)
Me.checkBox3.TabIndex = 10
Me.checkBox3.Text = "pizza"
Me.checkBox3.UseVisualStyleBackColor = True
Me.label4.AutoSize = True
Me.label4.Location = New System.Drawing.Point(518, 213)
Me.label4.Name = "label4"
Me.label4.Size = New System.Drawing.Size(83, 20)
Me.label4.TabIndex = 11
Me.label4.Text = "coupons ?"
Me.radioButton1.AutoSize = True
Me.radioButton1.Location = New System.Drawing.Point(560, 263)
Me.radioButton1.Name = "radioButton1"
Me.radioButton1.Size = New System.Drawing.Size(58, 24)
Me.radioButton1.TabIndex = 12
Me.radioButton1.TabStop = True
Me.radioButton1.Text = "yes"
Me.radioButton1.UseVisualStyleBackColor = True
Me.radioButton2.AutoSize = True
Me.radioButton2.Location = New System.Drawing.Point(560, 325)
Me.radioButton2.Name = "radioButton2"
Me.radioButton2.Size = New System.Drawing.Size(57, 24)
Me.radioButton2.TabIndex = 13
Me.radioButton2.TabStop = True
Me.radioButton2.Text = "NO"
Me.radioButton2.UseVisualStyleBackColor = True
Me.label5.AutoSize = True
Me.label5.Location = New System.Drawing.Point(284, 449)
Me.label5.Name = "label5"
Me.label5.Size = New System.Drawing.Size(93, 20)
Me.label5.TabIndex = 14
Me.label5.Text = "Total cost is"
Me.label5.Click += New System.EventHandler(Me.label5_Click)
Me.textBox2.Location = New System.Drawing.Point(398, 442)
Me.textBox2.Name = "textBox2"
Me.textBox2.Size = New System.Drawing.Size(100, 26)
Me.textBox2.TabIndex = 15
Me.textBox2.TextChanged += New System.EventHandler(Me.textBox2_TextChanged)
Me.AutoScaleDimensions = New System.Drawing.SizeF(9F, 20F)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(860, 605)
Me.Controls.Add(Me.textBox2)
Me.Controls.Add(Me.label5)
Me.Controls.Add(Me.radioButton2)
Me.Controls.Add(Me.radioButton1)
Me.Controls.Add(Me.label4)
Me.Controls.Add(Me.checkBox3)
Me.Controls.Add(Me.checkBox2)
Me.Controls.Add(Me.checkBox1)
Me.Controls.Add(Me.label3)
Me.Controls.Add(Me.label2)
Me.Controls.Add(Me.label1)
Me.Controls.Add(Me.button1)
Me.Controls.Add(Me.textBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Private textBox1 As System.Windows.Forms.TextBox
Private button1 As System.Windows.Forms.Button
Private label1 As System.Windows.Forms.Label
Private label2 As System.Windows.Forms.Label
Private label3 As System.Windows.Forms.Label
Private checkBox1 As System.Windows.Forms.CheckBox
Private checkBox2 As System.Windows.Forms.CheckBox
Private checkBox3 As System.Windows.Forms.CheckBox
Private label4 As System.Windows.Forms.Label
Private radioButton1 As System.Windows.Forms.RadioButton
Private radioButton2 As System.Windows.Forms.RadioButton
Private label5 As System.Windows.Forms.Label
Private textBox2 As System.Windows.Forms.TextBox
End Class
End Namespace
Form1.cs in c#
using System;
using System.Drawing;
using System.IO;
using System.Net;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int value;
if (int.TryParse(textBox1.Text, out value))
{
double games = Convert.ToInt16(textBox1.Text);
games = (games * 5) + 2.50;
if (radioButton1.Checked == true)
{
games = games - 2;
}
if (checkBox1.Checked == true)
{
games = games + 1;
}
if (checkBox2.Checked == true)
{
games = games + 1;
}
if (checkBox3.Checked == true)
{
games = games + 2;
}
textBox2.Text = Convert.ToString(games);
}
else
{
MessageBox.Show("enter numeric values");
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label5_Click(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
}
}
Designer.cs in c#:
namespace WindowsFormsApplication2
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.checkBox3 = new System.Windows.Forms.CheckBox();
this.label4 = new System.Windows.Forms.Label();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.label5 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(207, 49);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(84, 26);
this.textBox1.TabIndex = 3;
//
// button1
//
this.button1.Location = new System.Drawing.Point(303, 529);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 42);
this.button1.TabIndex = 4;
this.button1.Text = "Calculate";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(24, 49);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(135, 20);
this.label1.TabIndex = 5;
this.label1.Text = "Number of games";
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(45, 144);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(202, 20);
this.label2.TabIndex = 6;
this.label2.Text = "Cost of shoe rental is $2.50";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(33, 224);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(68, 20);
this.label3.TabIndex = 7;
this.label3.Text = "snacks?";
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(47, 279);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(72, 24);
this.checkBox1.TabIndex = 8;
this.checkBox1.Text = "chips";
this.checkBox1.UseVisualStyleBackColor = true;
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Location = new System.Drawing.Point(54, 326);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(70, 24);
this.checkBox2.TabIndex = 9;
this.checkBox2.Text = "soda";
this.checkBox2.UseVisualStyleBackColor = true;
//
// checkBox3
//
this.checkBox3.AutoSize = true;
this.checkBox3.Location = new System.Drawing.Point(61, 374);
this.checkBox3.Name = "checkBox3";
this.checkBox3.Size = new System.Drawing.Size(72, 24);
this.checkBox3.TabIndex = 10;
this.checkBox3.Text = "pizza";
this.checkBox3.UseVisualStyleBackColor = true;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(518, 213);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(83, 20);
this.label4.TabIndex = 11;
this.label4.Text = "coupons ?";
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Location = new System.Drawing.Point(560, 263);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(58, 24);
this.radioButton1.TabIndex = 12;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "yes";
this.radioButton1.UseVisualStyleBackColor = true;
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.Location = new System.Drawing.Point(560, 325);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(57, 24);
this.radioButton2.TabIndex = 13;
this.radioButton2.TabStop = true;
this.radioButton2.Text = "NO";
this.radioButton2.UseVisualStyleBackColor = true;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(284, 449);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(93, 20);
this.label5.TabIndex = 14;
this.label5.Text = "Total cost is";
this.label5.Click += new System.EventHandler(this.label5_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(398, 442);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 26);
this.textBox2.TabIndex = 15;
this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(860, 605);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.label5);
this.Controls.Add(this.radioButton2);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.label4);
this.Controls.Add(this.checkBox3);
this.Controls.Add(this.checkBox2);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBox2;
}
}
I have done the solution using windows forms application.
1) It will Get the number of games initially
2) Add the shoe rental
3) check for snacks and coupns
4) calculates the total cost as requested.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.