| |
|
|
| |
|
|
| |
| |
|
Public Class Point
Public x_coordinate as Short
Public y_coordinate as Short
End Class
Public Class TopLevel
Shared Sub Main()
Dim Points(99) as Point
Dim i as Short
For i = 0 To 99 Step 1
Points(i) = New Point()
Next i
Points(0).x_coordinate = 100
End Sub
End Class
Public Class Point
Private x_coordinate as Short
Private y_coordinate as Short
Public Function GetX() as Short
return(x_coordinate)
End Function
Public Function GetY() as Short
return(y_coordinate)
End Function
Public Sub SetX(ByVal X as Short)
x_coordinate = X
End Sub
Public Sub SetY(ByVal Y as Short)
y_coordinate = Y
End Sub
End Class
Public Class TopLevel
Shared Sub Main()
Dim Points(99) as Point
Dim i as Short
For i = 0 To 99 Step 1
Points(i) = New Point()
Next i
Points(0).setX(100)
End Sub
End Class
Public Class XYZPoint
Public x_coordinate as Short
Public y_coordinate as Short
Public z_coordinate as Short
End Class
Public Class XYZPoint
Inherits Point
Public z_coordinate as Short
End Class
Public Class PaleAndFireLine
Shared Sub Main()
Dim buckets(9) As Boolean
Dim water_dumped As Short = 0
Dim i, j As Short
'initialize all buckets to be absent; i.e., nobody has a bucket (not really needed)
For i = 0 To 9 Step 1
buckets(i) = False
Next i
For i = 1 To 20 Step 1 'simulate 20 buckets to be processed
'update the bucket line
'do all buckets except the last
For j = 8 To 0 Step -1 'work backwards!
If (buckets(j) = True) Then
buckets(j + 1) = True
buckets(j) = False
End IF
Next j
'now do the last bucket
If (buckets(9) = True) Then
water_dumped = water_dumped + CShort(1)
buckets(9) = False
End IF
'do the first bucket
buckets(0) = True'print out the bucket lineNext i
For j = 0 To 9 Step 1
If (buckets(j) = True) Then
System.Console.Write("X")
Else
System.Console.Write(".")
End IF
Next j
System.Console.Write(" " + CStr(water_dumped))
System.Console.WriteLine()
End Sub
End Class
Public Class FireLine
Public Shared water_dumped As Short = 0
Public Shared FFers(9) As FireFighter
Public Shared Sub Main()
Dim i As Short
'initialize all firefighters
For i = 9 To 0 Step -1
FFers(i) = New FireFighter(i)
Next i
'let the first FFer process 20 buckets
For i = 1 To 20 Step 1
FFers(0).process_bucket()
DisplayLine()
Next i
End Sub
Public Shared Sub DisplayLine()
Dim i As Short
For i = 0 To 9 Step 1
If FFers(i).bucket = True Then
System.Console.Write("X")
Else
System.Console.Write(".")
End IF
Next i
System.Console.Write(" " + CStr(water_dumped))
System.Console.WriteLine()
End Sub
End Class
Public Class FireFighter
Private next_neighbor As FireFighter
Public bucket As Boolean
'class constructor
Public Sub New(ByVal number As Short)
If number < 9 Then 'not last firefighter
next_neighbor = Fireline.FFers(number + CShort(1))
End IF
bucket = False 'not needed but always nice
End Sub
Public Sub process_bucket()
If bucket = True Then 'passing a buck(et)
If next_neighbor is nothing Then
FireLine.water_dumped = FireLine.water_dumped + CShort(1)
Else 'recursively call the next neighbor
next_neighbor.process_bucket()
End IF
Else 'receiving a bucket
bucket = True
End IF
End Sub
End Class
Public Shared FFers(10) As FireFighter 'declaration
FFers(i) = New FireFighter(i) 'instantiation
Public Sub New(ByVal number As Short) 'initialization
bucket = False
Public Class Foo
Public var_1 As Short
End Class
Public Class Goo
Inherits Foo 'weird, but has to sit on separate line
Public var_2 As Short
End Class
Public Class MainClass
Shared Sub Main()
Dim mine As New Goo()
mine.var_1 = 10
mine.var_2 = 20
System.Console.Write(CStr(mine.var_1) + " " + CStr(mine.var_2))
System.Console.WriteLine()
End Sub
End Class
Public Class Hello
Shared Sub Main()
System.Console.WriteLine("Hello World...")
End Sub
End Class
Module Hello
Sub Main()
System.Console.WriteLine("Hello World...")
End Sub
End Module