Created with <3 with dartpad.dev.
Last active
October 28, 2022 21:06
-
-
Save faruking/2aae15e493cb568d93cffea7d61a4ac0 to your computer and use it in GitHub Desktop.
HNGi9_Task1_Mobile
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'; | |
void main() { | |
// Circle objects | |
Circle circle1 = Circle(); | |
Circle circle2 = Circle.onlyRad(radius: 2); | |
Circle circle3 = Circle.radAndColor(radius: 2, color: 'blue'); | |
// Printing circles | |
print(''' | |
Circle 1: | |
Area: ${circle1.getArea()} | |
Circumference: ${circle1.getCircumference()} | |
${circle1.getDescription()} | |
Color: ${circle1.color} | |
'''); | |
print(''' | |
Circle 2: | |
Area: ${circle2.getArea()} | |
Circumference: ${circle2.getCircumference()} | |
${circle2.getDescription()} | |
Color: ${circle2.color} | |
'''); | |
print(''' | |
Circle 3: | |
Area: ${circle3.getArea()} | |
Circumference: ${circle3.getCircumference()} | |
${circle3.getDescription()} | |
Color: ${circle3.color} | |
'''); | |
} | |
class Circle{ | |
// Properties | |
final double radius; | |
final String color; | |
// Constructors | |
Circle({ this.color = 'red', this.radius = 1}); | |
Circle.onlyRad({required this.radius}): color = 'red'; | |
Circle.radAndColor({required this.color, required this.radius}); | |
// Methods | |
double getArea() { | |
return pi * pow(radius, 2); | |
} | |
double getCircumference() { | |
return 2 * pi * radius; | |
} | |
String getDescription() { | |
return 'Description: Radius: $radius Color: $color'; | |
} | |
String getColor() { | |
return 'Color: $color'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment