Answer the question
In order to leave comments, you need to log in
How to correctly rewrite these classes in TypeScript?
Just started using TypeScript help rewrite my code and explain what is wrong
class Students {
public name: string;
public surname: string;
public age: number;
}
constructor(name:string,surname:string,age:number) {
this.name = name;
this.surname = surname;
this.age = age;
}
public refactorStudent(name:string, surname:string,age:number):void {
this.name = typeof name !== 'undefined' ? name : this.name;
this.surname = typeof surname !== 'undefined' ? surname : this.surname;
this.age = typeof age !== 'undefined' ? age : this.age;
}
public toString():object{} {
return `\nName: ${this.name}, Surname: ${this.surname} Age: ${this.age}`
}
class Group{
public nameGroup: string;
public course: string;
public specialization: string;
public students: array[string,string,number];
constructor(nameGroup:string,course:string,specialization:string) {
this.nameGroup = nameGroup;
this.course = course;
this.specialization = specialization;
this.students = [];
}
public refactorInfo(nameGroup:string, course:string,specialization:string) {
this.nameGroup = typeof nameGroup !== 'undefined' ? nameGroup : this.nameGroup;
this.course = typeof course !== 'undefined' ? course : this.course;
this.specialization = typeof specialization !== 'undefined' ? specialization : this.specialization;
}
public addStudent(...students:object{}) {
this.students.push(...students);
}
public toString():object{}{
return `Name of Group: ${this.nameGroup}; \nCourse: ${this.course}; \nSpecialization: ${this.specialization};\nStudents: ${this.students}`
}
}
let student1 = new Students("Aladin","Indus", 20);
let student2 = new Students("Allah","Babah", 25);
let student3 = new Students("Krishna","harehare", 23);
let student4 = new Students("Shiva","4Hends", 24);
let student5 = new Students("Zorro","baf", 19);
let student6 = new Students("Barry","Allen", 28);
let Devs = new Group("D-11",4,"Front-end");
Devs.refactorInfo("D-12");
Devs.addStudent(student1,student2,student3,student4,student5,student6);
student1.refactorStudent("Super");
console.log(Devs.toString());
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question