🔒 Closed Pa help po dart po

Status
Not open for further replies.
Code:
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:
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.
 
Code:
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:
Thank you so much po <3
 
Status
Not open for further replies.

About this Thread

  • 3
    Replies
  • 304
    Views
  • 2
    Participants
Last reply from:
Hesoyam-

Online now

Members online
1,165
Guests online
4,289
Total visitors
5,454

Forum statistics

Threads
2,278,332
Posts
28,982,547
Members
1,228,312
Latest member
pulak
Back
Top