Last active
October 29, 2022 16:20
-
-
Save azeezco/dc35f3bc0ffe5eda1bcae68942c6fa1f to your computer and use it in GitHub Desktop.
HNG9 Mobile track task 1.
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
import 'dart:math'; | |
main() { | |
//Create circles | |
Circle circle1 = Circle(); | |
Circle circle2 = Circle.withRadius(2); | |
Circle circle3 = Circle.withRadiusAndClor(2, "blue"); | |
//Print circles | |
print("Circle 1: "); | |
print("Area: ${circle1.getArea()}"); | |
print("Circumference: ${circle1.getCircumfrence()}"); | |
print("Description: ${circle1.getDescription()}"); | |
print("Color: ${circle1.getColor()}"); | |
print(""); | |
print(""); | |
print("Circle 2: "); | |
print("Area: ${circle2.getArea()}"); | |
print("Circumference: ${circle2.getCircumfrence()}"); | |
print("Description: ${circle2.getDescription()}"); | |
print("Color: ${circle2.getColor()}"); | |
print(""); | |
print(""); | |
print("Circle 3: "); | |
print("Area: ${circle3.getArea()}"); | |
print("Circumference: ${circle3.getCircumfrence()}"); | |
print("Description: ${circle3.getDescription()}"); | |
print("Color: ${circle3.getColor()}"); | |
} | |
class Circle { | |
//Properties | |
double radius = 0; | |
String color = "black"; | |
//Constructors | |
Circle() { | |
radius = 1; | |
color = "red"; | |
} | |
Circle.withRadius(this.radius) { | |
color = "red"; | |
} | |
Circle.withRadiusAndClor(this.radius,this.color); | |
//Methods | |
double getArea() { | |
return pi * pow(radius, 2); | |
} | |
double getCircumfrence() { | |
return 2 * pi * radius; | |
} | |
String getDescription() { | |
return "Radius: ${radius.toInt()} Color: $color"; | |
} | |
String getColor() { | |
return color; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment