Create a class named "Table". It must have a constructor, indicating the width and height of the board. It will have a method "ShowData" which will write on the screen the width and that height of the table. Create an array containing 10 tables, with random sizes between 50 and 200 cm, and display all the data.
using System;
namespace Table
{
class Table
{
private int width = 0;
private int height = 0;
public Table(int width, int height)
{
if (width >= 0) this.width = width;
if (height >= 0) this.height = height;
}
public void ShowData()=> Console.WriteLine("Height - {0} cm, width - {1} cm", height, width);
}
class Program
{
static void Main(string[] args)
{
Table[] arr = new Table[10];
Random value = new Random();
for(int i = 0; i<10; i++)
arr[i] = new Table(value.Next(50, 200), value.Next(50,200));
foreach (var i in arr)
i.ShowData();
}
}
}
Comments
Leave a comment