Ejercicio
Tabla + coffetable + array
Objetivo
Cree un proyecto denominado "Tablas2", basado en el proyecto "Tablas".
En él, cree una clase "CoffeeTable" que herede de "Table". Su método "ShowData", además de escribir el ancho y el alto, debe mostrar "(Mesa de café)".
Cree una matriz que contenga 5 mesas y 5 mesas de centro. Las mesas deben tener tamaños aleatorios entre 50 y 200 cm, y las mesas de centro de 40 a 120 cm. Muestra todos sus datos.
Código
Imports System
Namespace Tables2
Class CoffeeTable
Inherits Table
Public Sub New(ByVal width As Single, ByVal height As Single)
Me.width = width
Me.height = height
End Sub
Public Overrides Sub ShowData()
Console.WriteLine("(Coffee table) Width: {0}, Heigth: {1}", width, height)
End Sub
End Class
Class Table
Protected width, height As Single
Public Sub New()
End Sub
Public Sub New(ByVal width As Single, ByVal height As Single)
Me.width = width
Me.height = height
End Sub
Public Property Width As Single
Set(ByVal value As Single)
width = value
End Set
Get
Return width
End Get
End Property
Public Property Height As Single
Set(ByVal value As Single)
height = value
End Set
Get
Return height
End Get
End Property
Public Overridable Sub ShowData()
Console.WriteLine("Width: {0}, Heigth: {1}", width, height)
End Sub
End Class
Class TestTables
Private Shared Sub Main()
Dim debug As Boolean = False
Dim myTables As Table() = New Table(9) {}
Dim rnd As Random = New Random()
For i As Integer = 1 To 10
If (i Mod 2 = 0) AndAlso (i <> 1) Then
myTables(i - 1) = New Table(rnd.[Next](50, 201), rnd.[Next](50, 201))
myTables(i - 1).ShowData()
Else
myTables(i - 1) = New CoffeeTable(rnd.[Next](40, 121), rnd.[Next](40, 121))
myTables(i - 1).ShowData()
End If
Next
If debug Then Console.ReadLine()
End Sub
End Class
End Namespace