Penn Foster Graded Project 03784100 Object-Oriented Programming Fundamentals
You now have the requisite OOP knowledge to expand the logic in the GroceryApp project. This project will assess your ability to create and use classes, collections, enumerations, and runtime exceptions. Make sure that you follow all directions completely and verify your results before submitting the project. Remember to include all required components in your solution.
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 that login process. You’ll also create a class to represent a grocery item and a custom collection class to represent a grocery basket.
Note: The output of this project will be used in the graded project for Lesson 4.
1. In Visual Studio, load the GroceryApp project that you completed in Lesson 2.
2. Add a new class named LoginException to the project.
3. Make the LoginException class a custom exception by deriving from the Exception class. See the last assignment in Lesson 3 for an example.
4. In the Login procedure of the Main module, replace the two lines that read MessageBox.Show(“Incorrect password.”) with the following code:
Throw New LoginException
5. Save your work and debug the application. What happens now when you type in an incorrect password for a valid username?
6. Stop debugging the application. You’ll now add exception handling code.
7. Add a Try…Catch statement for the following line in the btnLogin_Click event handler procedure:
8. Add the following line to the Catch block:
MessageBox.Show(“Incorrect password. “)
9. Save your work and debug the application. It should perform the same action as before.
10. Add a new public class to the project named GroceryItem.
11. The GroceryItem class should contain the following public properties:
a. ScanNumber – Represents the unique serial code for the item on the shelf. This property should be read-only.
b. BrandName – The name as described on the item’s packaging
c. Description – A short description of the item
d. Price – The amount of money it costs to buy the item. Make sure that only positive values can be assigned to this property.
e. Aisle – This should indicate one of the following aisles: Bakery, CannedGoods, Drinks, Deli, DryGoods, FrozenFoods, and Produce.
Note: See the second assignment in Lesson 3 for how to create an enumeration.
12. The GroceryItem class should contain the following public constructors:
a. A constructor that accepts and sets only the ScanNumber property. Remember: If a property is read-only, then you’ll need to set the variable, not use the property name.
b. A constructor that accepts and sets the ScanNumber, BrandName and Price properties.
13. Add a new public class named GroceryBasket to the project.
n Derive from the generic List class.
n Ensure that only GroceryItem objects are stored as items.
14. Add the following variable declaration to the Main module:
Friend basket As New GroceryBasket
15. Test your work.
Note: You can add code to the btnLogin_Click event handler procedure to instantiate the GroceryItem class and add multiple objects to the GroceryBasket variable. Make sure you either remove or comment out this code after testing.
To submit your project, you must provide the following five files:
To find these files, you should go to directory where you saved the GroceryApp project. To open the project directory, right-click on GroceryApp in the Solution Explorer panel and choose the Open Folder in File Explorer option in the context menu.
Copy the Main.vb, LoginForm.vb, LoginException.vb, GroceryItem.vb and GroceryBasket.vb files to your desktop or any other temporary location.
Remember to follow directions and good OOP principles as described in Lesson 3.
Your project will be graded using the following rubric:
The LoginException class is defined correctly 20 points
The Login button correctly uses a Try…Catch statement 20 points
The GroceryItem class is defined correctly 20 points
The GroceryBasket class is defined correctly 20 points
All source code files are included 20 points
TOTAL 100 points