PrepAway - Latest Free Exam Questions & Answers

What option suitably represents the necessary code?

You are employed as a developer at ABC.com. You make use of C# and ASP.NET for
development purposes.
You are instructed to develop a new Rectangle class. The new class should allow for Rectangle
objects to be compared.
What option suitably represents the necessary code?

PrepAway - Latest Free Exam Questions & Answers

A.
class Rectangle : IConvertible
{
public double Length { get; set; }
public double Width { get; set; }
public double GetArea()
{
return Length * Width;
}
public intCompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
double diff = this.GetArea() – target.GetArea();
if (diff == 0)
return 0;
else if (diff > 0)
return 1;
else return -1;
}
}

B.
class Rectangle : IComparable
{
public Length { get; set; }
public Width { get; set; }
public GetArea()
{
return Area;
}
public intCompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
double diff = this.GetArea() – target.GetArea();
if (diff == 0)
return 0;
else if (diff > 0)
return 1;
else return -1;
}
}

C.
class Rectangle : IComparable
{
private double Length { get; set; }
private double Width { get; set; }
private double GetArea()
{
return Length * Width;
}
private intCompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
double diff = this.GetArea() – target.GetArea();
if (diff == 0)
return 0;
else if (diff > 0)
return 1;
else return -1;
}
}

D.
class Rectangle : IComparable
{
private Length { get; set; }
private Width { get; set; }
private GetArea()
{
return Area;
}
private intCompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
double diff = this.GetArea() – target.GetArea();
if (diff == 0)
return 0;
else if (diff > 0)
return 1;
else return -1;
}
}

4 Comments on “What option suitably represents the necessary code?


Leave a Reply