Menu
Coddy logo textTech

Challenge: Grade Sorter

Part of the Logic & Flow section of Coddy's Dart journey — lesson 63 of 65.

challenge icon

Challenge

Easy

Create a comprehensive student grade management system that processes student data from a map, filters passing students, and organizes them alphabetically. This challenge combines map iteration, conditional filtering, list operations, and sorting.

You are provided with the following input:

  • A JSON string representing a map of student names (keys) and their test scores (values)

The JSON string will look like this: {"Alice": 85, "Bob": 45, "Charlie": 92, "Diana": 58, "Eve": 76, "Frank": 39, "Grace": 88}

Your task is to:

  1. Parse the JSON string into a Map using appropriate Dart methods
  2. Create an empty list called passingStudents to store the names of students who passed
  3. Iterate through the map and add the names of students who scored 60 or higher to the passingStudents list
  4. Sort the passingStudents list alphabetically using the sort() method
  5. Print the total number of students who took the exam with the exact format: Total students: X
  6. Print the number of students who passed with the exact format: Students who passed: X
  7. Print the number of students who failed with the exact format: Students who failed: X
  8. Print the passing students in alphabetical order, each on a new line, with the exact format: Passing student: [name]
  9. If no students passed, print: No students passed the exam

Your program should demonstrate proper map iteration, conditional logic for filtering data based on the passing threshold of 60, list manipulation, and sorting operations. The output must match the exact format specified above, with passing students listed in alphabetical order.

Try it yourself

import 'dart:io';
import 'dart:convert';

void main() {
  // Read the JSON string input
  String? jsonString = stdin.readLineSync();
  
  // Parse the JSON string into a Map
  Map<String, dynamic> studentGrades = jsonDecode(jsonString!);
  
  // Create an empty list to store passing students
  List<String> passingStudents = [];
  
  // TODO: Write your code below
  // 1. Iterate through the map and filter students who scored 60 or higher
  // 2. Add passing student names to the passingStudents list
  // 3. Sort the passingStudents list alphabetically
  // 4. Calculate and print the required statistics
  // 5. Print the passing students in the specified format
  
  // Output the results (replace with your implementation)
  print("Total students: ");
  print("Students who passed: ");
  print("Students who failed: ");
  // Print passing students or "No students passed the exam" message
}

All lessons in Logic & Flow