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

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.

Hey! Server Crash

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

Eager Student

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";
   }
}

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";
   }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.