Class FileManager

java.lang.Object
theLocalLoop.FileManager

public class FileManager extends Object
FileManager class for handling file input and output operations related to events.
Contains methods for saving events to a file, loading events from a file, adding an event to the file, editing an event in the file, and deleting an event from the file.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The name of the file to save events to.
  • Method Summary

    Modifier and Type
    Method
    Description
    addEvent(Event event)
    Adds an event to the file by first loading the current events from the file, adding the new event to the list, then saving the updated list back to the file.
    static void
    Deletes an event from the file by first loading the current events from the file, removing the specified event from the list, then saving the updated list back to the file.
    static void
    editEvent(Event event, Scanner input)
    Edits an event in the file by first loading the current events from the file, finding the specified event in the list and updating its details, then saving the updated list back to the file.
    Loads events from a file called "events.txt" and returns them as a LinkedList of Event objects.
    static void
    Saves a list of events to a file called "events.txt".

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • saveEvents

      public static void saveEvents(LinkedList<Event> events)
      Saves a list of events to a file called "events.txt". Each event is saved in the following format:
      name | date | time | duration | type(s) | format | organizer | password | location
      Parameters:
      events - LinkedList of Event objects representing the list of events to save to the file.
    • loadEvents

      public static LinkedList<Event> loadEvents()
      Loads events from a file called "events.txt" and returns them as a LinkedList of Event objects.
      Returns:
      LinkedList of Event objects representing the events loaded from the file. If the file does not exist or an error occurs while reading the file, an empty LinkedList is returned.
    • addEvent

      public static LinkedList<Event> addEvent(Event event)
      Adds an event to the file by first loading the current events from the file, adding the new event to the list, then saving the updated list back to the file.
      Parameters:
      event - Event object representing the event to add to the file.
      Returns:
      LinkedList of Event objects representing the updated list of events after adding the new event.
    • deleteEvent

      public static void deleteEvent(Event event)
      Deletes an event from the file by first loading the current events from the file, removing the specified event from the list, then saving the updated list back to the file.
      Parameters:
      event - Event object representing the event to delete from the file.
    • editEvent

      public static void editEvent(Event event, Scanner input)
      Edits an event in the file by first loading the current events from the file, finding the specified event in the list and updating its details, then saving the updated list back to the file.
      Parameters:
      event - Event object representing the event to edit in the file.
      input - Scanner object for user input to determine which attribute of the event to edit and the new value for that attribute.