Lab 4 of 7: An OrderCalculator Class (40 points)
Submit your assignment to the Dropbox located on the silver tab at the top of this page.
(See Syllabus “Due Dates for Assignments & Exams” for due dates.)
L A B O V E R V I E W
Scenario and Summary
For this lab, you’ll create the Visual Basic implementation of an OrderCalculator class. This class has OrderAmount and SalesTaxPercent properties. The class also has a GetTotalAfterDiscount method. The method determines if the order is greater than $100. If it is, the method applies a discount of 10% to the order amount. If the order is less than or equal to $100, the program applies no discount. Then, the method applies sales tax and returns the result.
Also, you will create a user interface for the OrderCalculator. The user interface will accept an OrderAmount and a SalesTaxPercent through textboxes. The user interface will have a button that declares and instantiates an OrderCalculator object, sets its properties, calls its GetTotalAfterDiscount method, and displays the result.
Here is the class diagram for the OrderCalculator.
OrderCalculator +numeric OrderAmount +numeric SalesTaxPercent GetTotalAfterDiscount( )
Here is the pseudocode for the GetTotalAfterDiscount( ) method.
Numeric GetTotalAfterDiscount( ) Declare Variables Numeric Discount Numeric TotalAfterDiscount If OrderAmount > 100 Discount = 0.10 Else Discount = 0 TotalAfterDiscount = (OrderAmount – OrderAmount * Discount) * (1 + SalesTaxPercent) Return(TotalAfter Discount)
The button-click event pseudocode for the user interface looks like this.
Start Declare Variables OrderCalculator objOrderCalculator Numeric TotalAfterDiscount
Get OrderAmount, SalesTaxPercent TotalAfterDiscount = objOrderCalculator.GetTotalAfterDiscount() Display TotalAfterDiscount Stop
Upon completing this lab, you will be able to do the following.
1. Create a class and a method within the class to perform a calculation.
2. Use a selection structure (an If or Else statement) to alter a calculation based on the value of a variable.
3. Create a form with labels, textboxes, and a button as a user interface to test your calculation class.
Lab4YourFirstLastName.docx (Word document)
Screen shot of Windows form Screen shot of class code Screen shot of button_click event code
Create the form and rename it.
Add the class OrderCalculator.
Add the public properties and the method.
Design the form and set the properties.
Code the button-click event.
Debug and run the program with the test data.
L A B S T E P S
STEP 1: Log Into Citrix
Log into the Citrix server and launch Visual Studio 2010.
STEP 2: Start a New VB Windows Project
Start a new Visual Basic Windows Project, and name it Lab4YourName.
To do this, pull down the File menu in Visual Studio, select New, and then select Project. For Project Type, make sure Windows is selected under Visual Basic, and for the template, make sure the Windows Forms Application is selected. Enter Lab4YourName in the Name box and click OK.
STEP 3: Rename Form1
Go to the Solution Explorer and rename Form1 as frmLab4YourFirstLastName.vb. To do this, right click on Form1.vb in the Solution Explorer and select Rename.
Enter frmLab4YourFirstLastName.vb and press Enter.
If the following dialog appears, click Yes.
STEP 4: Add a New Class
Pull down the Project menu, select Add Class, and add a new class called OrderCalculator to your solution.
Your environment should look like this.
STEP 5: Add the Public Properties and the Method
Add the public properties and the method to the class. Put your name at the top of the class as well as a brief description in the comments. When finished, it should look like this.
STEP 6: Design the Form
Click the Lab4YourFirstYourLastName.vb [Design] tab at the top of the editing window to switch to the design view, and design the form so that it looks like this.
To design this form, drag three labels, two textboxes, and a button from the Common Controls area of the Toolbox onto the form and position them as shown.
TIP: If the Toolbox is not visible, pull down the View menu and select Toolbox to display it. TIP: If the Toolbox is collapsed against the left side of the window, click it to expand it. Then, click the pushpin symbol at the top right of the Toolbox (the Auto Hide icon) to pin it in place. TIP: If the Common Controls section of the Toolbox is collapsed, click the + symbol on the left to expand it.
Set the properties of each control in the Properties window, as follows.
Sales Tax Percent
Calculate Order Total
lblOutput (was Label3)
The Answer Will Display Here
You may need to expand the size of the button control by clicking on it and then dragging the sizing handles around the edges so that all of the text is displayed.
STEP 7: Add a Button-Click Event
While the form is still in design view, double click on the button to bring up its button1_click event. Put the following code in it, including comments at the top that indicate the Lab number and your name.
By the way, the following line
has an underscore after the “&” to signify that the instruction continues onto the next line. This is called a line continuation character, which alerts Visual Basic to keep looking on the following line for more characters in that line.
STEP 8: Start Debugging
Go to the debug toolbar and press the Start Debugging button (sometimes called the Run button).
STEP 9: Run the Program
Run the program and provide values in the textboxes. Verify that your output is correct and formatted as currency. Debug it as necessary. Your output should look like this after you enter values and click the button.
STEP 10: Create the Lab File for Submission
Create a new Word file called Lab4YourFirstLastName.docx and paste screenshots of your Windows form, your class code, and your button-click event code in it. Save the Word document, and submit it to the Week 4 iLab Dropbox.
Here is compete solution for BIS311 Lab 4
If you have more questions, please contact me via email firstname.lastname@example.org
I will help you any time