1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16export class Student {
17  name: string;
18  age: number;
19  grade: number;
20
21  constructor(name: string, age: number, grade: number) {
22      this.name = name;
23      this.age = age;
24      this.grade = grade;
25  }
26
27  introduce() {
28      console.log(`Hi, I'm ${this.name}. I'm ${this.age} years old and I'm in grade ${this.grade}.`);
29  }
30}
31
32class Classroom {
33  className: string;
34  students: Student[];
35
36  constructor(className: string, students: Student[]) {
37      this.className = className;
38      this.students = students;
39  }
40
41  listStudents() {
42      console.log(`Class ${this.className} has the following students:`);
43      this.students.forEach(student => {
44          console.log(`${student.name}, age ${student.age}, grade ${student.grade}`);
45      });
46  }
47}
48
49const student1 = new Student('Alice', 15, 9);
50const student2 = new Student('Bob', 14, 8);
51const student3 = new Student('Charlie', 16, 10);
52
53const classroom = new Classroom('Class A', [student1, student2, student3]);
54
55classroom.listStudents();
56