Skip to content

Instantly share code, notes, and snippets.

@devRaphe
Created October 31, 2022 14:13
Show Gist options
  • Save devRaphe/13c35ecac46058bcfd76aca6b8c2d171 to your computer and use it in GitHub Desktop.
Save devRaphe/13c35ecac46058bcfd76aca6b8c2d171 to your computer and use it in GitHub Desktop.
silent-marble-5507
void main() {
Circle circle1 = Circle();
Circle circle2 = Circle.second(12.4);
Circle circle3 = Circle.third(radius: 22.3, color: 'blue');
print('''
Circle 1:
Area: ${circle1.getArea()};
Circumference: ${circle1.getCircumference()}
Description: ${circle1.getDescription()}
Color: ${circle1.getColor()}
Circle 2:
Area: ${circle2.getArea()};
Circumference: ${circle2.getCircumference()}
Description: ${circle2.getDescription()}
Color: ${circle2.getColor()}
Circle 3:
Area: ${circle3.getArea()};
Circumference: ${circle3.getCircumference()}
Description: ${circle3.getDescription()}
Color: ${circle3.getColor()}
''');
}
const double PI = 3.14;
class Circle {
double? radius;
String? color;
Circle()
: radius = 1,
color = 'red';
Circle.second(this.radius) : color = 'red';
Circle.third({required this.radius, required this.color});
double? getArea() {
return PI * radius! * radius!;
}
double? getCircumference() {
if (radius != null) {
return 2 * PI * radius!;
}
return null;
}
String? getDescription() {
return '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