Write a Visual Basic Application that is user friendly and easy to use. You are going to be creating a soda machine. Your soda machine will have 3 different kinds of soda, one has to be diet coke, and the others are of your choice. The cost of the soda, 1.25 must be displayed. There has to be a place for a person to “Enter money”. The user can enter dollar bills, quarters, dimes and nickels. The user must have enough money to purchase soda, if not a message will show. Change will be given in the smallest number of coins. There must be a button to get all the money back and not buy a soda. If that is the case, the user will get his money back in all nickels.
The design of the form must be easy to understand and use.
Note: Each time the application begins, we only 5 sodas of each kind. In one run of the program, if we sell out of one kind, that slot is empty and should be shown as empty. You must keep track of what you sell. User can only buy one soda at a time.
Visual Basic Soda Machine
Page 1 of 19 Replies - 570 Views - Last Post: 28 September 2012 - 01:21 PM
Replies To: Visual Basic Soda Machine
#2
Re: Visual Basic Soda Machine
Posted 24 September 2012 - 08:45 PM
Kurdistan1, on 25 September 2012 - 08:04 AM, said:
Write a Visual Basic Application that is user friendly and easy to use. You are going to be creating a soda machine. Your soda machine will have 3 different kinds of soda, one has to be diet coke, and the others are of your choice. The cost of the soda, 1.25 must be displayed. There has to be a place for a person to “Enter money”. The user can enter dollar bills, quarters, dimes and nickels. The user must have enough money to purchase soda, if not a message will show. Change will be given in the smallest number of coins. There must be a button to get all the money back and not buy a soda. If that is the case, the user will get his money back in all nickels.
The design of the form must be easy to understand and use.
Note: Each time the application begins, we only 5 sodas of each kind. In one run of the program, if we sell out of one kind, that slot is empty and should be shown as empty. You must keep track of what you sell. User can only buy one soda at a time.
The design of the form must be easy to understand and use.
Note: Each time the application begins, we only 5 sodas of each kind. In one run of the program, if we sell out of one kind, that slot is empty and should be shown as empty. You must keep track of what you sell. User can only buy one soda at a time.
Well, posting the question here just won't help you. There must be some kind of effort from your part as well. What I suggest is write the code for the program and ask specific questions regarding errors or roadblocks that you face. Please do not think that people will write programs for you blindly. They expect that you put in at least 80 % effort and they will certainly help you with the remaining 20 %.
regards,
Raghav
#3
Re: Visual Basic Soda Machine
Posted 25 September 2012 - 12:56 PM
thanks you for let me know that. is just i am have hard time with this one.
#4
Re: Visual Basic Soda Machine
Posted 25 September 2012 - 02:58 PM
I always sketch out a design of how the form is going to look like first. From there on you'll know what is available to store/display your values. Like 6 textboxes or labels to display your soda name and their price. Just think about it a bit more.
#5
Re: Visual Basic Soda Machine
Posted 26 September 2012 - 09:08 AM
this is what i have know
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCalc.Click
Dim PennyValue As Single
Dim NickelValue As Single
Dim DimeValue As Single
Dim QuarterValue As Single
Dim DollarsValue As Single
Dim TotalAmount As Single
PennyValue = Val(txtPennies.Text) * 0.01
NickelValue = Val(txtNickels.Text) * 0.05
DimeValue = Val(txtDimes.Text) * 0.1
QuarterValue = Val(txtQuarters.Text) * 0.25
DollarsValue = Val(txtDollars.Text) * 100
TotalAmount = PennyValue + NickelValue + DimeValue + QuarterValue
lblTotal.Text = Format(TotalAmount, "Currency")
End Sub
Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click
txtPennies.Text = ""
txtNickels.Text = ""
txtDimes.Text = ""
txtQuarters.Text = ""
txtDollars.Text = ""
lblTotal.Text = ""
txtPennies.Focus()
End Sub
Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
Me.Close()
End Sub
Private Sub txtPennies_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPennies.GotFocus
txtPennies.SelectAll()
End Sub
Private Sub txtPennies_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPennies.KeyPress
e.Handled = Not (Char.IsDigit(e.KeyChar) Or Asc(e.KeyChar) < 32)
End Sub
Private Sub txtPennies_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPennies.TextChanged
With txtPennies
If Len(.Text) = .MaxLength Then
txtNickels.Focus()
End If
End With
End Sub
Private Sub txtNickels_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtNickels.GotFocus
txtNickels.SelectAll()
End Sub
Private Sub txtNickels_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNickels.KeyPress
e.Handled = Not (Char.IsDigit(e.KeyChar) Or Asc(e.KeyChar) < 32)
End Sub
Private Sub txtNickels_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNickels.TextChanged
With txtNickels
If Len(.Text) = .MaxLength Then
txtDimes.Focus()
End If
End With
End Sub
Private Sub txtDimes_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDimes.GotFocus
txtDimes.SelectAll()
End Sub
Private Sub txtDimes_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDimes.KeyPress
e.Handled = Not (Char.IsDigit(e.KeyChar) Or Asc(e.KeyChar) < 32)
End Sub
Private Sub txtDimes_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDimes.TextChanged
With txtDimes
If Len(.Text) = .MaxLength Then
txtQuarters.Focus()
End If
End With
End Sub
Private Sub txtQuarters_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtQuarters.GotFocus
txtQuarters.SelectAll()
End Sub
Private Sub txtQuarters_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtQuarters.KeyPress
e.Handled = Not (Char.IsDigit(e.KeyChar) Or Asc(e.KeyChar) < 32)
End Sub
Private Sub txtQuarters_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtQuarters.TextChanged
With txtQuarters
If Len(.Text) = .MaxLength Then
cmdCalc.Focus()
End If
End With
End Sub
Private Sub txtDollars_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDollars.TextChanged
txtDollars.SelectAll()
End Sub
End Class
This post has been edited by modi123_1: 26 September 2012 - 09:12 AM
Reason for edit:: highlight the lines THEN click the code tags
#6
Re: Visual Basic Soda Machine
Posted 26 September 2012 - 11:52 AM
You need to plan out how your logic needs to work on paper first, then write the code.
If you design your algorithm before you code, the code almost can write itself.
Couple things I'd suggest you change.
First, give your controls meaningful names, Button2_Click means nothing to the the next guy that has to look at your code, even if you are the next guy.
try, btnCalculate_Total or something.
Second, you declare a single variable, why not assign its value in the declaration.
then you can do the calculations with variables
You'll probably need variables for the total number of pennies inserted
don't use the Val() method, use the tryparse method instead, val can return bad values if the users doesn't put in a number.
Then you probably will need a loop of some sort with a counter to keep track of how many sodas you have left.
What are you doing in your textChanged subs?
Your KeyPress events can be done in a single sub,
If you design your algorithm before you code, the code almost can write itself.
Couple things I'd suggest you change.
First, give your controls meaningful names, Button2_Click means nothing to the the next guy that has to look at your code, even if you are the next guy.
try, btnCalculate_Total or something.
Second, you declare a single variable, why not assign its value in the declaration.
then you can do the calculations with variables
Const PennyValue as Single = .01 'Value doesn't change Const NickelValue as Single = .05 'so make it constant and so on.
You'll probably need variables for the total number of pennies inserted
dim totalPennies as single dim totalPennies as double etc..
don't use the Val() method, use the tryparse method instead, val can return bad values if the users doesn't put in a number.
totalPennies = Single.TryParse(txtPennies.Text, totalPennies) totalNickels = Single.TryParse(txtNickels.Text, totalNickels) etc.
Then you probably will need a loop of some sort with a counter to keep track of how many sodas you have left.
What are you doing in your textChanged subs?
Your KeyPress events can be done in a single sub,
Private Sub CancelKeys(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNickels.KeyPress, txtPennies.KeyPress, txtDimes.KeyPress, 'etc etc
e.Handled = Not (Char.IsDigit(e.KeyChar) Or Asc(e.KeyChar) < 32)
End Sub
This post has been edited by torind_2000: 26 September 2012 - 11:54 AM
#7
Re: Visual Basic Soda Machine
Posted 26 September 2012 - 12:01 PM
torind_2000, on 26 September 2012 - 02:52 PM, said:
totalPennies = Single.TryParse(txtPennies.Text, totalPennies) totalNickels = Single.TryParse(txtNickels.Text, totalNickels) etc.
Actually you're probably better off with
If Not Single.TryParse(txtPennies.Text, totalPennies) Then 'Display an error as the value could not be parsed End if
Because upon success, totalPennies will hold the parsed value.
The method above could still return an unwanted value
With option strict off, it will return 0 if unsuccessful
with Option Strict On, you receive implicit conversions from Boolean to Single are not allowed.
#8
Re: Visual Basic Soda Machine
Posted 26 September 2012 - 12:12 PM
thanks Charlie, I'm adding that to my "Better way to do stuff" file
#9
Re: Visual Basic Soda Machine
Posted 28 September 2012 - 12:18 PM
Kurdistan1, on 24 September 2012 - 07:34 PM, said:
Write a Visual Basic Application that is user friendly and easy to use. You are going to be creating a soda machine. Your soda machine will have 3 different kinds of soda, one has to be diet coke, and the others are of your choice. The cost of the soda, 1.25 must be displayed. There has to be a place for a person to “Enter money”. The user can enter dollar bills, quarters, dimes and nickels. The user must have enough money to purchase soda, if not a message will show. Change will be given in the smallest number of coins. There must be a button to get all the money back and not buy a soda. If that is the case, the user will get his money back in all nickels.
The design of the form must be easy to understand and use.
Note: Each time the application begins, we only 5 sodas of each kind. In one run of the program, if we sell out of one kind, that slot is empty and should be shown as empty. You must keep track of what you sell. User can only buy one soda at a time.
The design of the form must be easy to understand and use.
Note: Each time the application begins, we only 5 sodas of each kind. In one run of the program, if we sell out of one kind, that slot is empty and should be shown as empty. You must keep track of what you sell. User can only buy one soda at a time.
Do you currently take CST 216? I have an lab (If Statements) with an identical question due this week.
#10
Re: Visual Basic Soda Machine
Posted 28 September 2012 - 01:21 PM
A useful approach is to separate the Logic from the GUI.
Guessing Game Tutorial
You build an core that just handles to logic and state transitions, via methods.
Convey changes externally via Events.
So do you can build differ GUIs on top of it, by listening to the events.
Guessing Game Tutorial
You build an core that just handles to logic and state transitions, via methods.
Convey changes externally via Events.
sodaMachine.InsertCoin(coin As Coin) sodaMachine.PushButton(button As SodaMachineButton) sodaMachine.CurrentState() As sodaMachineState
So do you can build differ GUIs on top of it, by listening to the events.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote







|