-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.dart
More file actions
53 lines (42 loc) · 987 Bytes
/
main.dart
File metadata and controls
53 lines (42 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import 'dart:async';
import 'dart:io';
import 'dart:math';
// Interface
abstract class Shape {
double area();
}
// Base class
class Circle implements Shape {
double radius;
Circle(this.radius);
@override
double area() {
return pi * pow(radius, 2);
}
}
// Derived class
class Cylinder extends Circle {
double height;
Cylinder(this.height, double radius) : super(radius);
@override
double area() {
return 2 * super.area() + 2 * pi * radius * height;
}
}
// Method that demonstrates the use of a loop
void printNNumbers(int n) {
for (int i = 1; i <= n; i++) {
print(i);
}
}
Future<void> main() async {
// Initialize an instance of a class with data from a file
final file = File('circle.txt');
final data = await file.readAsString();
final circle = Circle(double.parse(data));
// Override an inherited method
final cylinder = Cylinder(5, 3);
print('Area of cylinder: ${cylinder.area()}');
// Use a loop
printNNumbers(10);
}