0% found this document useful (0 votes)
7 views3 pages

Java Record 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Java Record 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

DEPARTMENT OF COMPUTERSCIENCE AND ENGINEERING 23CSR306 – JAVA PROGRAMMING

Ex no: 4
UML CLASS DIAGRAM
Date:

Question
Consider the following UML class diagram:

• Write a Java class for the Circle class based on the UML class
diagram.
• Write a main class TestCircle that creates two objects for the
Circle class and invoke all the methods.
Aim
To develop java class for the given UML class diagram .
Code
package CircleChar;
public class Circle {
private double radius;
private String color;
public Circle() {
radius=1.0;
color="red";
}
public Circle(double radius) {
this.radius=radius;
color="red";
}
public double getRadius() {
return radius;
}
public String getColor() {
return color;
}
public void setRadius(double radius) {
this.radius=radius;
}

7 717823P149
DEPARTMENT OF COMPUTERSCIENCE AND ENGINEERING 23CSR306 – JAVA PROGRAMMING

public void setColor(String Color) {


this.color=color;
}
public String toString() {
return "Circle{Radius:"+radius+",Color="+color+"}";
}
public double getArea() {
return Math.PI * radius * radius;
}

}package CircleChar;
public class TestCircle {
public static void main(String[] args) {
Circle a1=new Circle();
System.out.println(a1.getRadius());
System.out.println(a1.getColor());
System.out.println(a1.getArea());
System.out.println(a1.toString());
Circle a2=new Circle();
System.out.println(a2.getRadius());
a2.setColor("blue");
System.out.println(a2.getColor());
System.out.println(a2.getArea());
System.out.println(a2.toString());
}
}

Output

8 717823P149
DEPARTMENT OF COMPUTERSCIENCE AND ENGINEERING 23CSR306 – JAVA PROGRAMMING

Result
Thus, the Java program for the given relationship has been successfully developed and the
output was verified.

9 717823P149

You might also like