Create a class named TestCircle whose main() method declares several Circle objects. Using the setRadius() method, assign one Circle a small radius value, and assign another a larger radius value. Do not assign a value to the radius of the third circle; instead, retain the value assigned at construction. Display all the values for all the Circle objects. Save the applicationas TestCircle.java.
public class Circle {
int radius;
public Circle() {
}
public Circle(int radius) {
this.radius = radius;
}
public void setRadius(int radius) {
this.radius = radius;
}
@Override
public String toString() {
return "Circle [radius=" + radius + "]";
}
}
public class TestCircle {
public static void main(String[] args) {
Circle circleOne=new Circle();
circleOne.setRadius(3);
Circle circleTwo=new Circle();
circleTwo.setRadius(7);
Circle circleThree=new Circle(5);
System.out.println("Circe one has radius: "+circleOne.radius);
System.out.println("Circe two has radius: "+circleTwo.radius);
System.out.println("Circe three has radius: "+circleThree.radius);
}
}
Comments
Leave a comment