Jump to content

In need of help with C# pleaseee

SickSix66
{    interface IDisplayable    {        void showDimension();    }}{    abstract class Shape    {        public string Color;        public string ShapeType;        public double Area;        public void showMainFeature()        {            Console.WriteLine("Shape Type : {0}", ShapeType);            Console.WriteLine("Color : {0}", Color);                    }        abstract protected void computeArea();    }}{    class Rectangle : Shape, IDisplayable    {        public double Length;        public double Width;        public Rectangle()        {            Length = 0;            Width = 0;            ShapeType = "Rectangle";            Console.WriteLine("Rectangle object is created");        }        protected override void computeArea()        {            Area = Length * Width;        }        public void showDimension()        {                       }            }}{    class Triangle : Shape, IDisplayable    {        public double BaseLength;        public double Height;        public Triangle()        {            BaseLength = 0;            Height = 0;            ShapeType = "Triangle";            Console.WriteLine("Triangle object is created");        }        protected override void computeArea()        {            Area = 0.5 * BaseLength * Height;        }        public void showDimension()        {                   }    }}{    class Program    {        static void Main(string[] args)        {            Console.WriteLine("Welcome to Shape Management");            Rectangle rectangle1 = new Rectangle();            rectangle1.Color = "red";            rectangle1.Length = 2.0;            rectangle1.Width = 3.0;            rectangle1.showMainFeature();            rectangle1.showDimension();            Triangle triangle2 = new Triangle();            triangle2.Color = "blue";            triangle2.BaseLength = 2.0;            triangle2.Height = 3.0;            triangle2.showMainFeature();        }    }}

Hey guys, I really need help here. So far everything is fine however i can't get the expected out which is this:

Welcome to Shape Management
Rectangle object is created
Shape Type : Rectangle
Color : red
Length : 2
Width : 3
Area : 6
Triangle object is created
Shape Type : Triangle
Color : blue
BaseLength : 2
Height : 3
Area : 3
 
I'm only getting this :
Welcome to Shape Management
Rectangle object is created
Shape Type : Rectangle
Color : red
Triangle object is created
Shape Type : Triangle
Color : blue
 
Please help me thanks.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Your showDimension() functions are empty.

{    class Rectangle : Shape, IDisplayable    {        public double Length;        public double Width;        public Rectangle()        {            Length = 0;            Width = 0;            ShapeType = "Rectangle";            Console.WriteLine("Rectangle object is created");        }        protected override void computeArea()        {            Area = Length * Width;        }        public void showDimension()        {            Console.WriteLine("Length : 2");            Console.WriteLine("Width : 3");           }            }}{    class Triangle : Shape, IDisplayable    {        public double BaseLength;        public double Height;        public Triangle()        {            BaseLength = 0;            Height = 0;            ShapeType = "Triangle";            Console.WriteLine("Triangle object is created");        }        protected override void computeArea()        {            Area = 0.5 * BaseLength * Height;        }        public void showDimension()        {            Console.WriteLine("BaseLength : 2");            Console.WriteLine("Height : 3");        }    }}

Is this correct? Is this hardcoding? I got it just like the expected output but without the Area.

 

Link to comment
Share on other sites

Link to post
Share on other sites

Is this correct? Is this hardcoding? I got it just like the expected output but without the Area.

Yes, that is hardcording and you shouldn't do it. Instead, you can use the writeline method that takes a string format and additional arguments that reads from the variables you made.  So for the triangle it would be something like

public void showDimension(){    Console.WriteLine("BaseLength : {0}",BaseLength);    Console.WriteLine("Height : {0}",Height);}

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

 

Yes, that is hardcording and you shouldn't do it. Instead, you can use the writeline method that takes a string format and additional arguments that reads from the variables you made.  So for the triangle it would be something like

public void showDimension(){    Console.WriteLine("BaseLength : {0}",BaseLength);    Console.WriteLine("Height : {0}",Height);}

Yeap, I did that too eventually including Area which is:

Console.WriteLine("Area : {0}", Area);

However the output for my Area is 0. I have yet to make any changes with regards to Area

Link to comment
Share on other sites

Link to post
Share on other sites

Yeap, I did that too eventually including Area which is:

Console.WriteLine("Area : {0}", Area);

However the output for my Area is 0. I have yet to make any changes with regards to Area

Yeah, that's because you need to update width and length with values. Right now they just stay at 0.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×