Created with <3 with dartpad.dev.
Last active
October 29, 2022 15:08
-
-
Save c0d33ngr/b6282564b4421a030bc40ad33a9d220c to your computer and use it in GitHub Desktop.
Stage 1 Task: Mobile
This file contains hidden or 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' as math; | |
| class Circle { | |
| late double radius; | |
| late String color; | |
| Circle() { | |
| radius = 1; | |
| color = "red"; | |
| } | |
| Circle.withColor(this.radius) { | |
| color = "red"; | |
| } | |
| Circle.withBoth(this.radius, this.color); | |
| double getArea() { | |
| return math.pi * math.pow(radius,2); | |
| } | |
| double getCircumference() { | |
| return 2 * math.pi * radius; | |
| } | |
| String getDescription() { | |
| return "Radius: $radius Color: $color"; | |
| } | |
| String getColor() { | |
| return color; | |
| } | |
| } | |
| void main() { | |
| double circleArea, circleCircum; | |
| String circleDescription, circleColor; | |
| Circle circle3 = new Circle.withBoth(2, "blue"); | |
| Circle circle2 = new Circle.withColor(2); | |
| Circle circle1 = new Circle(); | |
| //circle1 | |
| circleArea = circle1.getArea(); | |
| circleCircum = circle1.getCircumference(); | |
| circleDescription = circle1.getDescription(); | |
| circleColor = circle1.getColor(); | |
| print("Circle 1: \nArea: $circleArea\nCircumference: $circleCircum \nDescription: $circleDescription \nColor: $circleColor\n"); | |
| //circle2 | |
| circleArea = circle2.getArea(); | |
| circleCircum = circle2.getCircumference(); | |
| circleDescription = circle2.getDescription(); | |
| circleColor = circle2.getColor(); | |
| print("Circle 2: \nArea: $circleArea\nCircumference: $circleCircum \nDescription: $circleDescription \nColor: $circleColor\n"); | |
| //circle3 | |
| circleArea = circle3.getArea(); | |
| circleCircum = circle3.getCircumference(); | |
| circleDescription = circle3.getDescription(); | |
| circleColor = circle3.getColor(); | |
| print("Circle 3: \nArea: $circleArea\nCircumference: $circleCircum \nDescription: $circleDescription \nColor: $circleColor\n"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment