Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace TeglalapOsztalya
- {
- class Rectangle
- {
- private float length = 1;
- private float width = 1;
- public Rectangle(float length, float width)
- {
- Length = length;
- Width = width;
- }
- public float Length
- {
- get { return this.length; }
- set {
- if (value <= 0.0f)
- this.length = 1.0f;
- else
- this.length = value;
- }
- }
- public float Width
- {
- get { return this.width; }
- set
- {
- if (value <= 0.0f)
- this.width = 1.0f;
- else
- this.width = value;
- }
- }
- public float Perimeter
- {
- get
- {
- return (Length + Width) * 2;
- }
- }
- public float Area
- {
- get
- {
- return (Length * Width);
- }
- }
- public override string ToString()
- {
- return string.Format("Perimeter is {0:F2} and the area is {1:F2}", Perimeter, Area);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- float length, width;
- Console.WriteLine("Write down the Length of the rectangle: ");
- length = float.Parse(Console.ReadLine());
- Console.WriteLine("Write down the Width of the rectangle: ");
- width = float.Parse(Console.ReadLine());
- Rectangle rect = new Rectangle(length, width);
- Console.WriteLine(rect);
- Console.ReadLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment