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.
* You can also use 2CO option if you want to purchase through Credit Cards/Paypal but make sure you put the correct billing information otherwise you wont be able to receive any download link.
* Your paypal has to be pre-loaded in order to complete the purchase or otherwise please discuss it with us at email@example.com.
* As soon as the payment is received, download link of the solution will automatically be sent to the address used in selected payment method.
* Please check your junk mails as the download link email might go there and please be patient for the download link email. Sometimes, due to server congestion, you may receive download link with a delay.
* All the contents are compressed in one zip folder.
* In case if you get stuck at any point during the payment process, please immediately contact us at firstname.lastname@example.org and we will fix it with you.
* We try our best to reach back to you on immediate basis. However, please wait for atleast 8 hours for a response from our side. Afterall, we are humans.
* Comments/Feedbacks are truely welcomed and there might be some incentives for you for the next lab/quiz/assignment.
* In case of any query, please donot hesitate to contact us at email@example.com.
* MOST IMPORTANT Please use the tutorials as a guide and they need NOT to be used for any submission. Just take help from the material.
******************************************** Good Luck ***************************************************
Any personal information received will only be used to fill your order. We will not sell or redistribute your information to anyone.
We will try our best to resolve the issue and if still persists we can discuss for a refund in case its required.