Browse Source

Adding writeToFile method in Course class

remotes/origin/fdai7780
fdai7921 11 months ago
parent
commit
46c2dc1b9e
  1. 15
      src/main/java/org/example/Course.java

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

@ -1,4 +1,7 @@
package org.example;
import java.io.*;
/**
* The Course class represents a course in a curriculum.
@ -96,4 +99,16 @@ public class Course {
System.out.println("Course Code: " + courseCode);
System.out.println("Course Credits: " + courseCredit);
}
public void writeToFile(String filename) {
try (PrintWriter writer = new PrintWriter(new FileWriter(filename))) {
writer.println(courseName);
writer.println(courseCode);
writer.println(courseCredit);
// Add any other fields you want to save
} catch (IOException e) {
e.printStackTrace();
}
}
}
Loading…
Cancel
Save