Académique Documents
Professionnel Documents
Culture Documents
The Practicals
2
OOP Lab
The form will have controls allowing the user to input a Student
ID, last name, and test average.
When the user clicks a button, your code will assign the input
values to Student class properties.
The form will also have a label to redisplay the Student object.
Lab
1-1: Creating a Student Class
1-2: Adding a parameterised constructor
OOP Lab
OOP Lab
3/6/2016
Lab 1-1
Step 1:
Step 2:
Next, add a class named Student to the project.
Right-click on the Project name, select Add, and select Class.
In the Add New Item dialog window, select Code, select
Class, and enter the class name as Student.vb.
Step 3:
Open the Student.vb file and replace its contents with the
class definition in the next slide:
OOP Lab
OOP Lab
Step 4:
Open the startup form in design mode and add the labels and the
named controls as shown below
OOP Lab
OOP Lab
3/6/2016
10
Next, you will write code in the startup form that copies the
users inputs to Student properties.
Step 5:
Step 6:
Create the Click handler on the next slide for the Save button.
You can omit the parameters from the btnSave_Click procedure because
they are optional
End Class
Copies values from the TextBox controls into the properties of the objStudent
object.
OOP Lab
OOP Lab
11
12
Step 7:
OOP Lab
Step 8:
Save the project, and run the application with the
following test:
Input
Expected output
OOP Lab
3/6/2016
Lab 1-2
13
14
2.
3.
Step 1:
In
Three parameters:
1.
ID number,
last name,
test average
Step 2:
Change
OOP Lab
15
Step 3:
OOP Lab
16
Public
Sub
New(ByVal
pIdNumber
As
String,
Optional ByVal pLastName As String = "", Optional
ByVal pTestAverage As Double = 0.0)
'the
second
and
third
parameters
are
optional
IdNumber = pIdNumber
LastName = pLastName
TestAverage = pTestAverage
End Sub
OOP Lab
Step 4:
OOP Lab
3/6/2016
17
Step 5:
Input
Expected output
Enter 200032, Odhis, 92.3 in the You should see the same ID
3 textboxes and click the Save number, name and average that
button.
you entered.
Then click the View button.
txtLastName.Text, testAverage)
calls the Student constructor, assigning values to the three class
variables.
lblStudent.Text = "(student information saved)"
Else
lblStudent.Text = "Test average is not a valid number"
End If
OOP Lab
End Sub
OOP Lab
Lab 1-3
20
19
Lab
OOP Lab
OOP Lab
3/6/2016
Requirements
22
1.
2.
3.
4.
5.
OOP Lab
Depositing Funds
Withdrawing Funds
23
24
OOP Lab
OOP Lab
3/6/2016
Requirements Specification
26
25
Lab
OOP Lab
OOP Lab
Lab 1-5
Testing Plan
27
28
OOP Lab
OOP Lab