Has relationship (Association) | Java UML to source code

Table of Contents

Has relationship(Association)
Has relationship(Association) UML Diagram

Line

package Association;

public class Line {
	private int length;
	public Line(int length) {
		this.length = length;
		
	}
	
	public void display() {
		System.out.println("Lenght:" + length);
	}
}

Circle

package Association;

public class Circle {
	private double radius;
	
	public Circle(double radius) {
		this.radius = radius;
		
	}
	
	public void display() {
		System.out.println("radius:" + radius);
	}
}

Rectangle

package Association;

public class Rectangle {
	
	private int height, width;
	Circle c;
	Line l;
	
	
	
	public Rectangle(int height, int width, Circle c, Line l) {
		this.height = height;
		this.width = width;
		this.c = c;
		this.l = l;
		
	}
	
	
	
	public void display() {
		
		System.out.println("\n" + "Height:" + height + "\nWidth:" + width);
		c.display();
		l.display();
		
	}
	
	
	
	public static void main(String[] args) {
		Circle c1 = new Circle(12.0);
		Line l1 = new Line(20);
		
		
		Rectangle r1 = new Rectangle(10, 20, c1, l1);
		r1.display();
		
		Rectangle r2 = new Rectangle(13, 50, c1, l1);
		r2.display();
		
		
		
		
	}
	
}

Output

Has relationship (Association) | Java UML to source code 1