From 1211419687f7264722dd6ba080cd01092951e7ea Mon Sep 17 00:00:00 2001 From: fdai7600 Date: Wed, 7 Feb 2024 14:47:36 +0100 Subject: [PATCH] Added writeToFile for the Professor Data --- src/main/java/org/example/Professor.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/org/example/Professor.java b/src/main/java/org/example/Professor.java index 10b1079..5388030 100644 --- a/src/main/java/org/example/Professor.java +++ b/src/main/java/org/example/Professor.java @@ -1,4 +1,13 @@ package org.example; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; /** * Represents a professor in the system. * This class holds the details of a professor including their ID, name, and role. @@ -101,4 +110,10 @@ public class Professor { ", role='" + role + '\'' + '}'; } + public void writeToFile() throws IOException { + try (BufferedWriter writer = new BufferedWriter(new FileWriter("professorData.txt", true))) { + writer.write(this.toString()); + writer.newLine(); + } + } }