Results 1 to 6 of 6

Thread: Restaurant Application with menu items

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Posts
    2

    Restaurant Application with menu items

    In visual basic how do I do the following?

    A restaurant wants an application that calculates a table's bill. The application should display all the menu items ( shown below) in four ComboBoxes. Each ComboBox should contain a category of food offered by the restaurant (Beverage, Appetizer, Main Course and Dessert). The user can choose from one of these ComboBoxes to add an item to a table's bill. As each item is selected in the ComboBoxes, add the price of that item to the bill. The user can click the Clear Button to restore the Subtotal:, Tax:, and Total: fields to $0.00

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Restaurant Application with menu items

    how far have you got?

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Restaurant Application with menu items

    assuming you're using vb2008+, you could use databinding + LINQ:

    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Dim loaded As Boolean = False
    4.  
    5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.         Dim ds As New DataSet
    7.         ds.Tables.Add("Beverage")
    8.         ds.Tables("Beverage").Columns.Add("item")
    9.         ds.Tables("Beverage").Columns.Add("price", GetType(Decimal))
    10.  
    11.         For x As Integer = 1 To 5
    12.             Dim dr As DataRow = ds.Tables("Beverage").NewRow
    13.             dr.ItemArray = New Object() {"drink" & x.ToString, x}
    14.             ds.Tables("Beverage").Rows.Add(dr)
    15.         Next
    16.  
    17.         Label1.Text = "Beverage"
    18.         ComboBox1.DataSource = ds.Tables("Beverage")
    19.         ComboBox1.DisplayMember = "item"
    20.         ComboBox1.ValueMember = "price"
    21.  
    22.         ds.Tables.Add("Appetizer")
    23.         ds.Tables("Appetizer").Columns.Add("item")
    24.         ds.Tables("Appetizer").Columns.Add("price", GetType(Decimal))
    25.  
    26.         For x As Integer = 1 To 5
    27.             Dim dr As DataRow = ds.Tables("Appetizer").NewRow
    28.             dr.ItemArray = New Object() {"starter" & x.ToString, x}
    29.             ds.Tables("Appetizer").Rows.Add(dr)
    30.         Next
    31.  
    32.         Label2.Text = "Appetizer"
    33.         ComboBox2.DataSource = ds.Tables("Appetizer")
    34.         ComboBox2.DisplayMember = "item"
    35.         ComboBox2.ValueMember = "price"
    36.  
    37.         ds.Tables.Add("Main_Course")
    38.         ds.Tables("Main_Course").Columns.Add("item")
    39.         ds.Tables("Main_Course").Columns.Add("price", GetType(Decimal))
    40.  
    41.         For x As Integer = 1 To 5
    42.             Dim dr As DataRow = ds.Tables("Main_Course").NewRow
    43.             dr.ItemArray = New Object() {"meal" & x.ToString, x}
    44.             ds.Tables("Main_Course").Rows.Add(dr)
    45.         Next
    46.  
    47.         Label3.Text = "Main_Course"
    48.         ComboBox3.DataSource = ds.Tables("Main_Course")
    49.         ComboBox3.DisplayMember = "item"
    50.         ComboBox3.ValueMember = "price"
    51.  
    52.         ds.Tables.Add("Dessert")
    53.         ds.Tables("Dessert").Columns.Add("item")
    54.         ds.Tables("Dessert").Columns.Add("price", GetType(Decimal))
    55.  
    56.         For x As Integer = 1 To 5
    57.             Dim dr As DataRow = ds.Tables("Dessert").NewRow
    58.             dr.ItemArray = New Object() {"dessert" & x.ToString, x}
    59.             ds.Tables("Dessert").Rows.Add(dr)
    60.         Next
    61.  
    62.         Label4.Text = "Dessert"
    63.         ComboBox4.DataSource = ds.Tables("Dessert")
    64.         ComboBox4.DisplayMember = "item"
    65.         ComboBox4.ValueMember = "price"
    66.  
    67.         loaded = True
    68.         ComboBox1.SelectedIndex += 1
    69.         ComboBox1.SelectedIndex = 0
    70.  
    71.     End Sub
    72.  
    73.     Private Sub ComboBoxes_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    74.     Handles ComboBox1.SelectedIndexChanged, ComboBox2.SelectedIndexChanged, ComboBox3.SelectedIndexChanged, ComboBox4.SelectedIndexChanged
    75.  
    76.         If Not loaded Then Return
    77.  
    78.         Dim total = (From cb In Me.Controls.OfType(Of ComboBox)() _
    79.                      Let value = CDec(DirectCast(cb, ComboBox).SelectedValue) _
    80.                      Select value).Sum
    81.         Label5.Text = "total = " & total.ToString("c2")
    82.     End Sub
    83. End Class
    Attached Images Attached Images  

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Restaurant Application with menu items

    Can someone please do my homework for me too?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Restaurant Application with menu items

    Quote Originally Posted by jmcilhinney View Post
    Can someone please do my homework for me too?
    ok. post your question. but i charge...

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Restaurant Application with menu items

    Quote Originally Posted by .paul. View Post
    ok. post your question. but i charge...
    At least I'll get good marks in my class without having to think for myself.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width