Please design a UML for the following code (Code is in C#) namespace projectone { abstract class GraphObject {

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Please design a UML for the following code (Code is in C#) namespace projectone { abstract class GraphObject {

Post by answerhappygod »

Please design a UML for the following code (Code is in
C#)
namespace projectone
{
abstract class GraphObject
{
public abstract double
calc_area();
public abstract double
calc_perimeter();
protected double area;
protected double perimeter;
}
class RightTriangle : GraphObject
{
public RightTriangle(int ht, int
bs)
{
height = ht;
bas = bs;
}
public override double
calc_area()
{
area = 0.5 * height *
bas;
return area;
}
public override double
calc_perimeter()
{
var hypotenuse =
Math.Sqrt(Math.Pow(height, 2) + Math.Pow(bas, 2));
perimeter = height + bas
+ hypotenuse;
return perimeter;
}
public override string
ToString()
{
return string.Format("A
triangle,height = {0},base = {1} area = {2},perimeter = {3}",
height, bas, calc_area(), calc_perimeter());
}
private int height;
private int bas;
}
class Square : GraphObject
{
public Square(int seg)
{
segment = seg;
}
public override double
calc_area()
{
area = Math.Pow(segment,
2);
return area;
}
public override double
calc_perimeter()
{
perimeter = 4 *
segment;
return perimeter;
}
public override string
ToString()
{
return string.Format("A
square,segment = {0},area = {1},perimeter = {2}", segment,
calc_area(), calc_perimeter());
}
private int segment;
}
class Utilities
{
public void FindLargest(GraphObject[]
graphObjects, bool isArea, ref int index)
{
if (isArea)
{
double
maxArea = 0.0;
foreach
(var obj in graphObjects)
{

if (obj.calc_area() > maxArea)

{

maxArea = obj.calc_area();

index++;

}
}
}
else
{
double
maxPerimeter = 0.0;
foreach
(var obj in graphObjects)
{

if (obj.calc_perimeter() > maxPerimeter)

{

maxPerimeter = obj.calc_perimeter();

index++;

}
}
}
}
}
class Program
{
static void Main(string[] args)
{
GraphObject obj = new
RightTriangle(6, 8);
GraphObject obj1 = new
Square(8);
GraphObject obj2 = new
RightTriangle(5, 15);
GraphObject obj3 = new
Square(7);
GraphObject[] arr = new
GraphObject[4];
arr.SetValue(obj,
0);
arr.SetValue(obj1,
1);
arr.SetValue(obj2,
2);
arr.SetValue(obj3,
3);
int count = 1;
foreach (var item in
arr)
{

Console.WriteLine($"\n#{count} object: " + item);

count++;
}
int index = 0;
new
Utilities().FindLargest(arr, true, ref index);

Console.WriteLine($"\n{index} object has the largest area of
{arr[index - 1].calc_area()}");
int index1 = 0;
new
Utilities().FindLargest(arr, false, ref index1);

Console.WriteLine($"\n{index1} object has the largest perimeter of
{arr[index1 - 1].calc_perimeter()}\n");
}
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply