Created
October 31, 2022 17:01
-
-
Save MrazTevin/3243c91c07897fb5d4bc2195b44ae600 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Circle { | |
private double radius; | |
private String color; | |
// default value for radius and color | |
public Circle () { | |
radius = 1.0; | |
color = "red"; | |
} | |
// radius as parameter and default color | |
public Circle (double r) { | |
radius = r; | |
color = "red"; | |
} | |
public Circle (double radius, String color) { | |
this.radius = radius; | |
this.color = color; | |
} | |
public double getRadius() { | |
return radius; | |
} | |
public double getArea() { | |
return radius*radius*Math.PI; | |
} | |
public double getCircumference() { | |
return 2 * radius * Math.PI; | |
} | |
public String getDescription() { | |
String radiusToString = String.valueOf(radius); | |
return "Radius:" + radiusToString + "Color:" + color; | |
} | |
public String getColor() { | |
return "Color:" + color; | |
} | |
public static void main(String[] args) { | |
Circle circle = new Circle(); | |
System.out.println(circle.getArea()); | |
System.out.println(circle.getCircumference()); | |
System.out.println(circle.getDescription()); | |
System.out.println(circle.getColor()); | |
Circle circle2 = new Circle(2); | |
System.out.println(circle2.getArea()); | |
System.out.println(circle2.getCircumference()); | |
System.out.println(circle2.getDescription()); | |
System.out.println(circle2.getColor()); | |
Circle circle3 = new Circle(3, "blue"); | |
System.out.println(circle3.getArea()); | |
System.out.println(circle3.getCircumference()); | |
System.out.println(circle3.getDescription()); | |
System.out.println(circle3.getColor()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment