Skip to content

Instantly share code, notes, and snippets.

@abdorll
Created October 16, 2023 00:30
Show Gist options
  • Save abdorll/e2f99f6901ccce190e68c594b5017c4c to your computer and use it in GitHub Desktop.
Save abdorll/e2f99f6901ccce190e68c594b5017c4c to your computer and use it in GitHub Desktop.
class Student {
// ========== Properties (Attributes of a stident)
String? name, department;
int? age, matricNumber;
double? gpa;
// ========== Methods (Actions a student can do)
// Methods 1: switchDepartment
void switchDepartment(String newDepartment) {
department = newDepartment;
}
// Methods 2: updateGPA
void updateGPA(double newGpa) {
gpa = newGpa;
}
// Methods 3: printBioData
void printBioData() {
print("\n");
print("Name: $name");
print("Matric Number: $matricNumber");
print("Age: $age");
print("Department: $department");
print("GPA: $gpa");
}
}
// Main Function
void main(){
// ================== Examples
// 01:
Student student1 = Student();
student1.name = "Bisola";
student1.matricNumber = 1010101010;
student1.age = 17;
student1.department = "Maths";
student1.gpa = 4.6;
student1.printBioData();
student1.updateGPA(4.7);
student1.printBioData();
student1.switchDepartment("Chemistry");
student1.printBioData();
print("\n");
// 02:
// Student ahmad = Student();
// student1.name = "Ahmad";
// student1.matricNumber = 23232323423;
// student1.age = 16;
// student1.department = "Economics";
// student1.gpa = 4.3;
// student1.printBioData();
// student1.updateGPA(4.8);
// student1.printBioData();
// student1.switchDepartment("Accounting");
// student1.printBioData();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment