Answer to Question #166515 in C# for Habib Ur Rehman

Question #166515

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.


1
Expert's answer
2021-02-25T11:46:20-0500
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();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS