import 'dart:io';
class Student {
Student(this.name, this.score);
final String name;
final int score;
}
void main() {
final students = <Student>[];
while (true) {
stdout.write("Enter your name: ");
final name = stdin.readLineSync();
if (name?.toLowerCase() == 'stop') {
break;
}
stdout.write("Enter your score: ");
final score = stdin.readLineSync();
final student = Student(name!, int.parse(score!));
students.add(student);
}
final highScore = students.reduce(
(a, b) => a.score > b.score ? a : b,
);
final lowestScore = students.reduce(
(a, b) => a.score < b.score ? a : b,
);
print('${highScore.name} got the highest score.');
print('${lowestScore.name} got the lowest score.');
}
Enter your name: John
Enter your score: 70
Enter your name: Mary
Enter your score: 40
Enter your name: Sue
Enter your score: 60
Enter your name: Bob
Enter your score: 80
Enter your name: stop
Bob got the highest score.
Mary got the lowest score.
Thank you so much po <3Code:import 'dart:io'; class Student { Student(this.name, this.score); final String name; final int score; } void main() { final students = <Student>[]; while (true) { stdout.write("Enter your name: "); final name = stdin.readLineSync(); if (name?.toLowerCase() == 'stop') { break; } stdout.write("Enter your score: "); final score = stdin.readLineSync(); final student = Student(name!, int.parse(score!)); students.add(student); } final highScore = students.reduce( (a, b) => a.score > b.score ? a : b, ); final lowestScore = students.reduce( (a, b) => a.score < b.score ? a : b, ); print('${highScore.name} got the highest score.'); print('${lowestScore.name} got the lowest score.'); }
Output: