From 7fa88263422b50e9e7ccea68801d39981bacef5a Mon Sep 17 00:00:00 2001 From: Tobias Herbert Date: Tue, 6 Feb 2024 21:05:18 +0100 Subject: [PATCH] Added writeToFile Method in Admin Class --- src/main/java/org/example/Admin.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/org/example/Admin.java b/src/main/java/org/example/Admin.java index abe8cbc..d7b4ff0 100644 --- a/src/main/java/org/example/Admin.java +++ b/src/main/java/org/example/Admin.java @@ -1,5 +1,9 @@ package org.example; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; + /** * Represents an administrative user in the system. */ @@ -53,4 +57,12 @@ public class Admin { System.out.println("ID: " + getId()); 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); + } + + } }