0

Hi! to everyone
I'm starting out in programming,I need help to develop a class diagram for a Shape class. Include generalizations for child classes Rectangle, Circle and Triangle.

Please can you help me here!?

Eager Student

2
Contributors
4
Replies
5
Views
11 Years
Discussion Span
Last Post by Eager Student
0

Just construct a shape class with a couple of methods. The methods you have should be general enough so that each subclass could use them..Such as color. Just find some common relationships between the Rectangle, Circle, and Triangle, and that should give you the class. Since it's a generalized class, it won't be very specific, and it wont be very big. You could have some accessor and mutator methods involved, but I don't know if that's the best thing to do in this case.

0

Hey! Server Crash

Can you give me a pseudocode so that I can get a clear shout.

Eager Student

0

I don't like pseudo code, so I'll just do an example of the class. There are endless possibilities for this, so this is just one that could work. Some of the things probably shouldn't go, but that's ok.

public class Shape
{
      private Color color;
      private String shape;
      private int sides;
      public Shape(Color color)
      {
              this.color = color;
      }

      public void changeColor(Color color)
     {
            this.color = color;
     }
     
     public void setShape(String shape)
    {
                 this.shape = shape;
    }
    public void getShape()
    {
             return this.shape;
    }
    public void setSides(int sides)
   {
          this.sides = sides;
   }
   public void getSides()
   {
         return this.sides;
   }

   public void getInfo()
   {
             return "Generic Shape..This method needs to be overriden";
   }
}
0

Hey! Server Crash
Howzit!? I'm not in quite serenity here.Actually the syntax is Java and I'm instructed now to use C#, so that is why I were seeking for the pseudocode, however I will strive to do the pseudocode and I highly appreciate your help or If you give me the pseudocode for the code you gave me I will be grateful.Thanks
Eager Student
PS.I highly appreciate your help.

I don't like pseudo code, so I'll just do an example of the class. There are endless possibilities for this, so this is just one that could work. Some of the things probably shouldn't go, but that's ok.

public class Shape
{
      private Color color;
      private String shape;
      private int sides;
      public Shape(Color color)
      {
              this.color = color;
      }

      public void changeColor(Color color)
     {
            this.color = color;
     }
     
     public void setShape(String shape)
    {
                 this.shape = shape;
    }
    public void getShape()
    {
             return this.shape;
    }
    public void setSides(int sides)
   {
          this.sides = sides;
   }
   public void getSides()
   {
         return this.sides;
   }

   public void getInfo()
   {
             return "Generic Shape..This method needs to be overriden";
   }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.