mirror of
https://github.com/londonappbrewery/Flutter-Course-Resources/
synced 2024-11-15 05:44:55 +00:00
36 lines
765 B
Dart
36 lines
765 B
Dart
|
import 'dart:math';
|
||
|
|
||
|
class CalculatorBrain {
|
||
|
CalculatorBrain({this.height, this.weight});
|
||
|
|
||
|
final int height;
|
||
|
final int weight;
|
||
|
|
||
|
double _bmi;
|
||
|
|
||
|
String calculateBMI() {
|
||
|
_bmi = weight / pow(height / 100, 2);
|
||
|
return _bmi.toStringAsFixed(1);
|
||
|
}
|
||
|
|
||
|
String getResult() {
|
||
|
if (_bmi >= 25) {
|
||
|
return 'Overweight';
|
||
|
} else if (_bmi > 18.5) {
|
||
|
return 'Normal';
|
||
|
} else {
|
||
|
return 'Underweight';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
String getInterpretation() {
|
||
|
if (_bmi >= 25) {
|
||
|
return 'You have a higher than normal body weight. Try to exercise more.';
|
||
|
} else if (_bmi >= 18.5) {
|
||
|
return 'You have a normal body weight. Good job!';
|
||
|
} else {
|
||
|
return 'You have a lower than normal body weight. You can eat a bit more.';
|
||
|
}
|
||
|
}
|
||
|
}
|