Informatika Test

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Class RECTANGLE

using System.Windows.Forms;

namespace WindowsFormsApp3
{
class Rectangle
{
private int length;
private int width;
public int Length
{
get { return this.length; }
set
{
if (value > 0)
this.length = value;
else
MessageBox.Show("Improper lenght");
}
}
public int Width
{
get { return this.width; }
set
{
if (value > 0)
this.width = value;
else
MessageBox.Show("Improper width");
}
}

public int CalcPerimeter()


{
return this.length * this.width;
}
}
}
*******************************************
Form1.cs

using System.Windows.Forms;

namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
Random r = new Random();
int random;
public int[] rectangleArray = new int[6];

public Form1()
{
InitializeComponent();
}

private void buttonCalcP_Click(object sender, EventArgs e)


{
Rectangle rectangleOne = new Rectangle();

rectangleOne.Length = int.Parse(textBoxLenght.Text);
rectangleOne.Width = int.Parse(textBoxWidth.Text);

random = r.Next(0, 7);


textBoxGenID.Text = random.ToString();

int Perimeter = rectangleOne.CalcPerimeter();


textBoxPerimeter.Text = Perimeter.ToString();
}

private void buttonATArray_Click(object sender, EventArgs e)


{
rectangleArray[int.Parse(textBoxGenID.Text)] =
int.Parse(textBoxGenID.Text);
}
}
}

You might also like