Monday, October 3
Shadow

Challenge code for Dart’s session 7

void main() {}

/// The class for the `Student` object
class Student {
  List<double> marks = [];
  bool isRegistered = false;
  String name;
  String password;

  /// Creates an object of type `Student` given a [name] and a [password]
  Student(this.name, this.password);

  /// Adds the given [mark] to `marks`
  void addMark(double mark) {
    marks.add(mark);
  }

  /// Registers student by setting `isRegistered` to `true`
  void register() {
    isRegistered = true;
  }

  /// Replaces `password` with [newPass] only if it's different and long enough
  void updatePassword(String newPass) {
    if (password != newPass && newPass.length >= 8) {
      password = newPass;
    }
  }

  @override
  String toString() {
    if (isRegistered) {
      return '$name is a registered student with marks: $marks';
    }
    return '$name still needs to register';
  }
}

Leave a Reply