Browse Source

Added writeToFile Method to Student class

remotes/origin/fdai7780
fdai7887 11 months ago
parent
commit
dda4d4f83b
  1. 15
      src/main/java/org/example/Student.java

15
src/main/java/org/example/Student.java

@ -1,4 +1,9 @@
package org.example;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
/**
* Represents an student user in the system.
*/
@ -61,4 +66,14 @@ public class Student {
System.out.println("Role: " + getRole());
}
public void writeToFile(Student student, String filename) throws IOException {
try(BufferedWriter writer = new BufferedWriter(new FileWriter(filename))){
String attributes = student.getName() + "\n" + student.getId() + "\n" + student.getRole();
writer.write(attributes);
}
}
}
Loading…
Cancel
Save