Skip to content

Instantly share code, notes, and snippets.

@mbaka-bilal
Last active October 28, 2022 11:17
Show Gist options
  • Save mbaka-bilal/73f10add5a73dae2018f16257a477e9f to your computer and use it in GitHub Desktop.
Save mbaka-bilal/73f10add5a73dae2018f16257a477e9f to your computer and use it in GitHub Desktop.
hngstage 1 task
import 'dart:math';
class Circle {
double? radius;
String? color;
Circle()
: radius = 1,
color = 'red';
Circle.withColor({this.radius}) : color = 'red';
Circle.withAll({this.color, this.radius});
double getArea() {
return (pi * pow(radius!, 2));
}
double getCircumference() {
return (2 * pi * radius!);
}
String getDescription() {
return "Radius: $radius Color: $color";
}
String getColor() {
return color!;
}
}
void runExample({required int circleNumber,String? color,double? radius,}) {
Circle circle;
if (color == null && radius == null){
circle = Circle();
}else if (color == null && radius != null){
circle = Circle.withColor(radius: radius);
}else{
circle = Circle.withAll(color: color,radius: radius);
}
print("Circle $circleNumber:");
print("Area: ${circle.getArea()}");
print("Circumference: ${circle.getCircumference()}");
print("Description: ${circle.getDescription()}");
print("Color: ${circle.getColor()}\n\n");
}
void main() {
runExample(circleNumber: 1);
runExample(circleNumber: 2,radius: 2);
runExample(circleNumber: 3,radius: 2,color: "blue");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment