Browse Source

Added writeToFile Method in Admin Class

remotes/origin/fdai7780
Tobias Herbert 11 months ago
parent
commit
7fa8826342
  1. 12
      src/main/java/org/example/Admin.java

12
src/main/java/org/example/Admin.java

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