Object-Oriented
Programming
Fundamentals
OVERVIEW
YOUR PROJECT
In the graded project for Lesson 2, you implemented the login
process for a Windows Forms application in Visual Studio.
In this project, you’ll add exception handling to the login
process. You’ll also create a class to represent a grocery item
and a custom collection class to represent a grocery basket.
The output of this project will be used in the next graded
project.
INSTRUCTIONS
1. In Visual Studio, load the Grocery App project that you
completed in Lesson 2. If this isn’t available, then you’ll
need to ask your instructor for the finished Lesson 2
project.
2. Add a new class to the project named Login Exception.vb
(Figure 34).
Make the Login Exception class a custom exception by
deriving from the Exception class. See Assignment 3 for
an example.
3. In the Login procedure of the Main module, replace the
two lines that read Message Box.Show(“Incorrect password.”)
with the following code:
Throw New Login Exception
4. Save your work and debug the application. What happens
now when you type in an incorrect password for a
valid username?
5. Stop debugging the application. You’ll now add exception
handling code.
6. Add a Try…Catch statement for the following line in the
btnLogin_Click event handler procedure:
Main.Login(txtUsername.Text, txtPassword.Text)
Add the following line to the Catch block:
Message Box.Show(“Incorrect password.”)
FIGURE 34—Enter Login Exception.vb and click Enter.
7. Save your work and debug the application. It should
perform the same action as before.
8. Add a new public class to the project named
Grocery Item. See Assignment 1 for help.
9. The class should contain the following public properties:
¦ Scan Number. Represents the unique serial code for
the item on the shelf. This property should be read only.
¦ Brand Name. The name as described on the item’s
packaging
¦ Description. A short description of the item
¦ Price. The amount of money it costs to buy the item.
Make sure that only positive values can be assigned
to this property.
¦ Aisle. This should indicate one of the following
aisles: Bakery, Canned Good, Drinks, Deli,
Dry Goods, Frozen Food, and Produce. See
Assignment 2 on how to create enumerations.
10. The class should contain the following public
constructors:
¦ A constructor that accepts and sets only the
Scan Number property. Remember, if a property is
read-only, then you’ll need to set the variable, not
use the property name.
¦ A constructor that accepts and sets the
Scan Number, Brand Name, and Price properties.
11. Add a new public class to the project named
Grocery Basket. See Assignment 2 for help.
a. Derive from the generic Dictionary class.
b. Ensure that only String values are used as keys.
c. Ensure that only Grocery Item objects are stored as
values.
12. Test your work. You can add code to the btnLogin_Click
event handler procedure to instantiate the GroceryItem
class and add multiple objects to the Grocery Basket
class. Make sure you either remove or comment out this
code after testing.
To submit your project, you must provide the following five
files:
¦ Main.vb
¦ LoginForm.vb
¦ LoginException.vb
¦ GroceryItem.vb
¦ GroceryBasket.vb
Penn Foster 03709400 -100% score – support available – iqrajavaid
Please feel free to send me a message in case of any query
iqra javaid
Use the order calculator below and get started! Contact our live support team for any assistance or inquiry.
[order_calculator]
