Challenge: Grade Sorter
Part of the Logic & Flow section of Coddy's Dart journey — lesson 63 of 65.
Challenge
EasyCreate 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:
- Parse the JSON string into a Map using appropriate Dart methods
- Create an empty list called
passingStudentsto store the names of students who passed - Iterate through the map and add the names of students who scored 60 or higher to the
passingStudentslist - Sort the
passingStudentslist alphabetically using thesort()method - Print the total number of students who took the exam with the exact format:
Total students: X - Print the number of students who passed with the exact format:
Students who passed: X - Print the number of students who failed with the exact format:
Students who failed: X - Print the passing students in alphabetical order, each on a new line, with the exact format:
Passing student: [name] - 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
1Advanced List Manipulation
List Properties: first & lastList State: isEmpty & isNotEmpReversing a ListAdding to a List: insertList Removal: removeWhereFinding in a List: indexOfSorting a ListShuffling a ListRecap - List Organizer4Advanced Map Manipulation
Iterating Over a MapChecking for Keys and ValuesMap Properties: keys & valuesConditional Add: putIfAbsentRemoving Entries from a MapNested MapsRecap - Inventory Update2Functional List Operations
Transforming with 'map'Filtering with 'where'Using '.toList()'Checking Conditions with 'any'Conditions with 'every'Finding with 'firstWhere'Recap - Data Filtering5Project: Shopping Cart Calc
Project SetupAdding Items to the Cart3Sets
What is a Set?Creating a SetAdding and Removing from SetsChecking for Elements in a SetConverting a List to a SetSet UnionSet IntersectionSet DifferenceRecap - Unique Guest List