Java intro course. 2) 2.1 Show what is printed on the screen when this program i
ID: 3844657 • Letter: J
Question
Java intro course.
2) 2.1 Show what is printed on the screen when this program is executed.
2.2 Draw UML outline for Circle class given here.
----------------------------------------------------------
public class TestCircle {
public static void main(String [] args) {
Circle c0 = new Circle();
c0.name = "oval";
c0.radius = 5;
Circle c1 = new Circle();
c1.name = "curved";
c1.radius = 15;
Circle c2 = new Circle();
c2.name = "elliptical";
c2.radius = 20;
System.out.println("Names: " + c0.name + " " +
c1.name + " " + c2.name);
c1.radius = 13;
c0.radius = c2.radius + c0.radius;
System.out.println("radius = " + c0.radius + " " +
c1.radius + " " + c2.radius);
3
c2.setRadius(25);
c2.name = "Bigger elliptical";
System.out.println(c2.getRadius() + " " + c2.name);
}
}
----------------------------------------------------------
public class Circle {
String name;
int radius;
public Circle(){
}
public Circle(int newRadius){
this.name = "default";
this.radius = 1;
}
public void setRadius(int newRadius){
this.radius = newRadius;
}
public int getRadius(){
return this.radius;
}
public double getArea(){
double area = Math.PI * this.radius * this.radius;
return area;
}
}
----------------------------------------------------------
Print output:
UML Diagram for the above class Circle .
Explanation / Answer
Output of the program is
Names: oval curved elliptical
radius = 25 13 20
25 Bigger elliptical
UML of Circle class
Circle radius: intname: String + Circle()
+ Circle(string = "default", int =1)
+ setRadius(int): void
+ getRadius(): int
+ getArea() : double
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.