/******************************************************************************
Online C# Compiler.
Code, Compile, Run and Debug C# program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
using System;
class HelloWorld {
public static Rectangle Create(int x, int y)
{
return new Rectangle(x, y);
}
public static int TotalArea(Rectangle r1,Rectangle r2)
{
return r1.Area() + r2.Area();
}
public static void PrintObject(Rectangle R)
{
R.Print();
}
public static Rectangle Max3(Rectangle r1, Rectangle r2, Rectangle r3)
{
if (r1.Area() > r2.Area() && r1.Area() > r3.Area())
return r1;
else if (r2.Area() > r1.Area() && r2.Area() > r3.Area())
return r2;
else
return r3;
}
private static void TestObjectsMethod()
{
Rectangle r1 = new Rectangle(20, 30);
Rectangle r2 = new Rectangle(4, 5);
Rectangle r3 = Create(10, 11);
Rectangle r4 = Create(3, 7);
PrintObject(r1);
PrintObject(r2);
int total = TotalArea(r1, r2);
Console.WriteLine("Total: {0}", total);
Console.WriteLine("Total: {0}", TotalArea(r3, r4));
Rectangle x = Max3(r4, r2, r3);
Console.WriteLine(r3);
//x.Print();
if (r1.Equals(r1))
Console.WriteLine("are Equal");
else
Console.WriteLine("are not Equal");
}
static void Main() {
Console.WriteLine("Hello World");
TestObjectsMethod();
}
}
using System;
public class Rectangle
{
private int x;
private int y;
public Rectangle(int x, int y)
{
this.x = x;
this.y = y;
}
public void Print()
{
Console.WriteLine("x:{0},y:{1}", this.x, this.y); ;
}
public int Area()
{
return this.x *this.y;
}
public override string ToString()
{
return " Rectangle x: "+this.x+",y:"+this.y;
}
public bool Equals(Rectangle that)
{
if (this.x != that.x)
return false;
if (this.y != that.y)
return false;
return true;
}
}