Project Overview
This mini project stores student records, displays them, and calculates an average score. It uses interfaces, classes, arrays, methods, and optional expansion into separate modules.
Define the Student Interface
interface Student {
id: number;
name: string;
age: number;
score: number;
}
Create the Manager Class
class StudentManager {
private students: Student[] = [];
addStudent(student: Student): void {
this.students.push(student);
}
showStudents(): void {
for (let student of this.students) {
console.log(student.name + " - " + student.score);
}
}
getAverageScore(): number {
let total = 0;
for (let student of this.students) {
total += student.score;
}
return this.students.length > 0 ? total / this.students.length : 0;
}
}
Use the Class
let manager = new StudentManager();
manager.addStudent({ id: 1, name: "Ali", age: 20, score: 85 });
manager.addStudent({ id: 2, name: "Siti", age: 21, score: 92 });
manager.showStudents();
console.log("Average Score: " + manager.getAverageScore());
How to Extend the Project
- Add a search-by-ID method
- Remove a student by ID
- Store letter grades
- Split the project into modules
- Create a simple HTML interface
Tip: Small projects are one of the best ways to learn because they combine multiple language features into one practical example.
Summary
You have completed the TypeScript tutorial with a mini project that shows how real programs combine structured data, reusable classes, arrays, functions, and project organization.