CSC139 Chapter 11 Lab Assignments
Objectives
In this lab assignment students will learn:
– How to define LINQ statement
– How to use LINQ to query data from object array
Goals
In this lab assignment students will demonstrate the abilities to:
– Define LINQ statement
– Use LINQ to query data from object array
Grading rubric
Public Class GradeBook
Private nameValue As String
Private scoreValue As Integer
Public Sub New(ByVal n As String ByVal s As Integer)
nameValue = n
scoreValue = s
End Sub
Public Property Name() As String
Get
Return nameValue
End Get
Set(ByVal value As String)
nameValue = value
End Set
End Property
Public Property Score() As Integer
Get
Return scoreValue
End Get
Set(ByVal value As Integer)
scoreValue = value
End Set
End Property
Public Sub displayGradeBook()
Console.WriteLine(Name: & Name & vbTab & Score: & Score)
End Sub
End Class
Option Strict On
Module LINQGradeBookTester
Sub Main()
Dim g1 As New GradeBook(AAA 70)
Dim g2 As New GradeBook(BBB 50)
Dim g3 As New GradeBook(CCC 100)
Dim g4 As New GradeBook(DDD 80)
‘add g1 g2 g3 and g4 in a array and display all student scores
Dim gradeBooks As GradeBook() = {g1 g2 g3 g4}
display(gradeBooks Scores for all students: )
‘create a LINQ which get all scores in ascending order and display them.
‘create a LINQ which get all students who passed the exam
‘display number of passed students their names and scores
End Sub
‘display gradeBook’s information
Private Sub display(ByVal gradeBooks As IEnumerable ByVal header As String)
Console.WriteLine(header)
For Each g As GradeBook In gradeBooks
g.displayGradeBook()
Next
Console.WriteLine()
End Sub
End Module
Here is output: (See next page)