【发布时间】:2021-02-24 20:54:29
【问题描述】:
我是 dart 的初学者,目前正在学习类和方法。我只想将我在兴趣类中创建的方法调用到主函数,以便它执行定义操作。我不想在 main.js 中实现任何函数或变量。我不知道我是否有可能尝试一些东西;这可能是当您想向公众隐藏一些业务逻辑时。请帮我。我相信有,但我就是找不到。
import 'dart:io';
class Interest {
double principal;
double rate;
int time;
Interest(double aPrincipal, double aRate, int aTime) {
this.principal = aPrincipal;
this.rate = aRate;
this.time = aTime;
}
double interestAmnt() {
print(
"This is a program to Calculate the over all amount back for your loan");
print("What is the Amount of loan you have taken: ");
this.principal = double.parse(stdin.readLineSync());
print("What is the interest on your loan: ");
this.rate = double.parse(stdin.readLineSync());
print("How long are paying for the long: ");
this.time = int.parse(stdin.readLineSync());
return this.principal * (1 + (this.rate * this.time));
}
}
main(List<String> args) {
}
【问题讨论】:
标签: function flutter class dart methods