1. Lab #CIS CIS170A-A3
  1. Lab 3 of 7: Decisions
  1. Lab Overview – Scenario / Summary:

TCOs:

4. Given a set of program specifications for a simple business problem requiring one or more decisions, code and test a program that meets the specifications and employs best programming practices.

6. Given a program with syntax and logic errors, employ the debugger and other diagnostic tools to remove or correct the errors.

This lab will familiarize students with If/Else/EndIf statements and possible Select Cast statements by calculating the amount of money a drive-in movie theater makes in a single night.

  1. Deliverables:

Step 6 / Deliverable / Points
6 / Project Files / 45

The Dropbox deliverables include the following.

  1. Include a zipped file with all the files from your Visual Basic project (see directions in Doc Sharing on how to collect and zip files).
  2. Upload each part of the lab into its corresponding weekly Dropbox.
  1. Lab Steps:

Step 1: Create a New Project
Create a new Windows Forms project in VB.NET. Name your project CIS170A_Lab03.
Step 2:Program Description
In this program you will create a Windows Form application that will calculate and display the money made by a drive-in movie theater each night.The movie theater has two types of nights.A “Regular” night is where each person in a guest car has to buy a ticket, and each ticket costs $10.A “Car” night is a special promotion where there is one price per car of $15, no matter how many guests are in the car.
In addition to the cost of entry (either Regular or Car), the theater sells popcorn andcandy but the price of the items depends on the type of night. On a Regular night popcorn costs $1.50 per box and on a special Car night popcorn costs $2.00 per box.On a Regular night candy cost $2.25 per candy box, while on a special Car night candy cost $3.00 per box.
On any night, the maximum number of cars allowed in is 500 and the maximum number of individual tickets is 3,000; the theater can produce 4,500 bags of popcorn each night and has 4,000 candy items.
Once the total revenue is calculated, the program will display a summary message with the type of night, the total number of cars, the total ticket sales, the total popcorn sales, the total candy sales, and the total sales amount.
Consider using the following pseudocode as a guide in developing the main processing algorithm of the program:
  1. Initialize program and create variables
  2. Accept and validate NumberOfCars
  3. Accept and validate TypeOfNight[Not needed if radio buttons are used for TypeOfNight.]
  4. If TypeOfNight = Regular:
a)Accept and validate Tickets
  1. Accept and validate Popcorn
  2. Accept and validate Candy
  3. If TypeOfNight = Regular[or if corresponding Radio Button was clicked]:
a)Compute TotalPopcorn = Popcorn*1.5
b)Compute TotalCandy = Candy* 2.25
c)Compute Total = Tickets*10 + TotalPopcorn + TotalCandy
  1. If strTypeOfNight = Car[or if corresponding Radio Button was clicked]:
a)Compute TotalPopcorn = Popcorn*2
b)Compute TotalCandy = Candy*3
c)Compute Total = NumberOfcars*15 + TotalPopcorn + TotalCandy
  1. Display the final message (TypeOfNight; NumberOfCars; TotalPopcorn; TotalCandy; and Total.)
In all cases where validation fails, the program should stop and return control to the user so they can figure out how to resolve the validation error (that is, exit the event handler immediately but continue within the program.)
Notice that this logic is a bit simple-minded and goes "straight through", without coming back to the beginning. This is due to not yet having learned how to use the loop statements that will allow us to go back our logic to ask again for a value that was entered in error. (We cover that next week.)
Step 3:Suggested Form Design
You are free to experiment with form design and object colors as you see fit, even though as to colors we strongly recommend using the default colors for the form and all objects – this allows each user to see your form in their chosen Windows color palette.
A possible form design is as follows:

Once the total sales are calculated, the program will display a summary message in a ListBox object with the following content:
  • type of night;
  • total number of cars;
  • total ticket revenue;
  • total popcorn revenue;
  • total candy revenue; and
  • total revenue amount.

Step 4: Implement the Event Handlers
Consider using the following suggested TOE chart as guide in designing your program’s event handlers. As also noted in the pseudocode description above, the final calculation should NOT be completed unless all the input fields are validated as correct.
Task / Object / Event
  1. Accept and validate NumberOfCars
  2. Accept and validate TypeOfNight [Not needed if radio buttons are used for TypeOfNight.]
  3. If TypeOfNight = Regular [or test for the radio button’s Checked prop.]:
a)Accept and validate Tickets
  1. Accept and validate Popcorn
  2. Accept and validate Candy
  3. If TypeOfNight = Regular:
a)Compute TotalPopcorn = Popcorn*1.5
b)Compute TotalCandy = Candy* 2.25
c)Compute Total = Tickets*10 + TotalPopcorn + TotalCandy
  1. If strTypeOfNight = Car:
a)Compute TotalPopcorn = Popcorn*2
b)Compute TotalCandy = Candy*3
c)Compute Total = NumberOfcars*15 + TotalPopcorn + TotalCandy
  1. Display the final message (TypeOfNight; NumberOfCars; TotalPopcorn; TotalCandy; and Total.)
/ btnCompute / Click
Clear all textboxes and listbox [Hint: use method Items.Clear()] / btnClear / Click
Close form. / btnExit / Click
[Hint: To comply with the desire to avoid computing the totals if we have some problem in validation, consider using the Exit Sub statement in suitable locations within your code.]
Programming notes:
  1. To check if a textbox is empty, use the String.IsNullOrEmpty method, such as:
IfString.IsNullOrEmpty(txtName.Text) = TrueThen
  1. To check if a radio button named “radRegular” was selected by the user, test for the radio button’s Checked property to be equal to True, as follows:
IfMe.radRegular.Checked = TrueThen
  1. To validate a numeric input (in the example below, intSeasons, an Integer value), consider the following suggested code:
IfInteger.TryParse(Me.txtSeasons.Text, intSeasons) = FalseThen
MessageBox.Show("Seasons must be numeric", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.txtSeasons.SelectAll()
Me.txtSeasons.Focus()
Exit Sub
Else
If intSeasons < 1 Or intSeasons > 20 Then
MessageBox.Show("Seasons must be between 1 and 20", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.txtSeasons.SelectAll()
Me.txtSeasons.Focus()
Exit Sub
EndIf
EndIf
Please remember to set Option Strict On and also to supply profuse internal documentation in your program.
Problem-Solving Questions (“IDEAL” problem-solving methodology):
  1. Identify the problematic situation.
  2. With respect to user requirements, can a “Regular” night and a “Car” night happen at the same time? What data is needed for a “Regular” night and for a “Car” night? Can popcorn and candy be sold for both types of night or not? Is there a price for cars as well as for occupants of the cars? Is candy and popcorn priced the same always?
  3. What are the (explicit or implicit) validation rules for each data element?
  4. Define the problem and goals.
  5. How can the problem be described in words?
  6. What is the exact meaning of the following specification in the Lab’s description: “In all cases where validation fails, the program should terminate and return control to the user (i.e., exit the event handler immediately.)”
  7. What specific tests can we execute on the finished program to ascertain correct functioning? Please include detailed test scripts (i.e., what data to enter; what object to activate; and what results are expected -- test by test.)
  8. Explore and evaluate possible solution strategies.
  9. What form design alternatives exist to allow the user to specify the type of night? What advantages / disadvantages do you see for those options?
  10. What form objects could be used to encase the textboxes as shown in the “suggested form design” in the Lab’s description? What features do those “container” objects allow? Beyond aesthetics, what could they be used for?
  11. Should the Tickets data item be allowed to be entered if the TypeOfNight is: (a) Regular; (b) Car?
  12. Should the display be produced bit by bit as the input data elements are validated; or, on the other hand, after all input data elements have been validated as correct? Why?
  13. What form objects could be used to display the “Revenue”? How would such an object be handled within the program?
  14. Anticipate the outcomes. Choose, justify, and implement a solution.
  15. How should the solution to the problem be coded in Visual Studio?
  16. Look back at learning and evaluate the solution.
  17. Can you summarize in a few sentences what you learned in this Lab? Be extensive in your analysis.
NOTE: These questions are meant to help you identify the problem presented in the Lab and resolve it. You should not submit written replies to the questions as part of your Lab.
Step 6:Deliverables
  1. Zip up the top-level folder with your program (the complete set of project files) into a single file (please check Doc Sharing for details.)
  2. Rename that .zip file as CIS170A_Lab03_LastName_FirstInitial.zip, or similar.
  3. Place deliverables in the Dropbox.

END OF LAB

Page 1 of 5

Lab Activity CIS CIS170A-A2