5 Replies - 261 Views - Last Post: 10 October 2012 - 03:33 PM Rate Topic: -----

#1 xforsakend  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-October 12

Very confused about UML

Posted 08 October 2012 - 04:10 PM

Hello I am new to this forum so if this is the incorrect spot I apologize. I am also a beginner programmer. For an assignment I have to use UML but I am extremely confused on how to go about doing so. Below is the code im trying to put into UML. If anyone could help out with that or just examples if you find it unethical to show me with my code or whatever I just really need to figure it out and the most basic layout will do just fine Thanks!


package rectangle;

public class Rectangle {
    
    private double width = 1;
    private double height = 1;
    private String color = "white";
    
    public Rectangle(double w, double h, String c)
    {
        width = w;
        height = h;
        color = c;
    }

    public double getWidth()
    {
        return width;
    }
    public double getHeight()
    {
        return height; 
    }
    public String getColor()
    {
        return color;
    }
    public void setWidth(double w)
    {
        width = w; 
    }
    public void setHeight(double h)
    {
        height = h;
    }
    public void setColor(String c)
    {
        color = c;
    }
    public double getArea()
    {
        return height*width; 
    }
    public double getPerimeter()
    {
        return (height*2)+(width*2);
    }
    
    public static void main(String[] args) {
        
    Rectangle rec = new Rectangle(1, 1, "white");
    
    System.out.println("\n Height = " + rec.getHeight() );
    System.out.println("\n Width = " + rec.getWidth() );
    System.out.println("\n Color = " + rec.getColor() );
    
    rec.setHeight(13);
    rec.setWidth(8);
    
    System.out.println("\n\n Height = " + rec.getHeight() );
    System.out.println("\n Width = " + rec.getWidth() );
    System.out.println("\n Area = " + rec.getArea() );
    System.out.println("\nPerimeter = " + rec.getPerimeter());
        
    
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Very confused about UML

#2 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Very confused about UML

Posted 08 October 2012 - 04:21 PM

UML is a large field, what type of diagram do you have to do? If its a class diagram, all you need to do is draw a box and fill it out in this format

CLASS NAME

VARIABLE NAMES

METHOD NAMES
Was This Post Helpful? 1
  • +
  • -

#3 xforsakend  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-October 12

Re: Very confused about UML

Posted 08 October 2012 - 04:30 PM

I'm sorry yes its a class UML. So something like this....

Rectangle
------------
width
height
color
-------------
getWidth
setWidth
etc.
-------------

Does that look right?
Was This Post Helpful? 0
  • +
  • -

#4 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Very confused about UML

Posted 08 October 2012 - 04:50 PM

Thats pretty much it on a basic level. You can add more info though

Quote

Rectangle

width : double
height : double
color : String

getWidth()
setWidth(w : double)
etc


Try to use better variable names than w, h etc. The variable name should represent what it is, so rectWidth, rectHeight, etc would be more appropiate.
Was This Post Helpful? 2
  • +
  • -

#5 ronpopo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-October 12

Re: Very confused about UML

Posted 10 October 2012 - 02:45 PM

View Postxforsakend, on 08 October 2012 - 04:30 PM, said:

I'm sorry yes its a class UML. So something like this....

Rectangle
------------
width
height
color
-------------
getWidth
setWidth
etc.
-------------

Does that look right?


Yes, some professors are a little pickier, my professor always had us indicate if the method/variable was public or private with + or -

example:

Rectangle
---------
-width
-height
-color
---------
+getWidth
+setWidth
Was This Post Helpful? 0
  • +
  • -

#6 CasiOo  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1357
  • View blog
  • Posts: 2,992
  • Joined: 05-April 11

Re: Very confused about UML

Posted 10 October 2012 - 03:33 PM

View Postronpopo, on 10 October 2012 - 09:45 PM, said:

View Postxforsakend, on 08 October 2012 - 04:30 PM, said:

I'm sorry yes its a class UML. So something like this....

Rectangle
------------
width
height
color
-------------
getWidth
setWidth
etc.
-------------

Does that look right?


Yes, some professors are a little pickier, my professor always had us indicate if the method/variable was public or private with + or -

example:

Rectangle
---------
-width
-height
-color
---------
+getWidth
+setWidth


That is not being picky lol

You need constructors
You need return types and type of your variables
There are missing parameters on your methods
You also need to model your color = "white" :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1