Console App in Dart that Shows Students' Data Using Maps (and its methods

Console App in Dart that Shows Students' Data Using Maps (and its methods

Is been five weeks since I started my Tech Internship journey with the ADA Tech team it has not been an easy journey juggling this whole tech thing with motherhood, family and work but then it's worth all the sacrifice but omo this particular project showed me pepper but then finally we are here with the result.

Task Overview

The principal of Evergreen was highly impressed by your previous solution and now requests that you build a new solution that will make the work of the registrar easier. But starting with jss1 students.

These are the requirements: The registrar should be able to upload all the students names, date of birth, height, state of origin They should be able to view this data in the console.

Objective Of The Task:

Improve your logic skills Help you experiment with maps in dart and it's methods. Solidify the basics you've been practicing with.

Steps I Used To Achieve this Code

  1. I imported dart:io and dart:core which we will use to input student data and create map that is needed respectively,then created an empty list and called it STUDENT, created a function addStudent() to store the different data inputs from the registrar. The data inputs included two strings and three integers which includes ; name, date of birth, age, height, state of origin and used stdin.readLineSync() which can be found in dart:io, to pass either as a string or converting to an integer . To convert integer inputs using stdin.readLineSync, I used int.parse(stdin.readLineSync).
  1. I also created a map which contains the keys and values and made sure to call the variables created above into the values.

  2. I then used the .add method in the map to add each Student data created from the input into our [] just like this, STUDENTS.add(Student).

  3. A function called printStudents() was created a nested for...in loop that will take the data above and print out each keys and values.

  4. Then in the main function I called the addStudent() function then created a while loop that always return true. I want this loop to ask the registrar to press 1 to continue adding student's name (i.e addstudent function) or press 0 to view the data of the student(s) he had already inputted (printStudent function)which will come out as a map because of what I created. To enable this loop, I introduced the if/else statement.

Code

import 'dart:io';
import 'dart:core';

final STUDENTS = [];

void addStudent() {
  print(
      "Hello, this is the JSS1 students database, please enter student's name.");
  final String name = stdin.readLineSync()!;

  print("Enter student's age.");
  final int age = int.parse(stdin.readLineSync()!);

  print("Enter student's date of birth.");
  final String dateOfBirth = stdin.readLineSync()!;

  print("Enter height in centimeters.");
  final int height = int.parse(stdin.readLineSync()!);

  print("Enter student's state of origin.");
  final String stateOfOrigin = stdin.readLineSync()!;

  var Student = {
    "name": name,
    "age": age,
    "dateOfBirth": dateOfBirth,
    "height": height,
    "stateOfOrigin": stateOfOrigin,
  };
  STUDENTS.add(Student);


}

void printStudents() {
  print(STUDENTS);
}


void main() {
addStudent();

  while(true) {
    print("Enter 1 to continue or enter 0 to end.");
  final int userInput = int.parse(stdin.readLineSync()!);
    if(userInput == 1){
    addStudent();
    }else if(userInput == 0){
      print(STUDENTS);
      break;
    }else{
      print('Invalid input');
    }
  }

}