Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2324S1#4 from AY2324S1-CS2113-F11-3/m…
Browse files Browse the repository at this point in the history
…aster

Update
  • Loading branch information
Cheezeblokz authored Oct 20, 2023
2 parents f0693f5 + 913c42c commit b60ffc3
Show file tree
Hide file tree
Showing 32 changed files with 415 additions and 81 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ Steps for publishing documentation to the public:
1. Scroll down to the `GitHub Pages` section.
1. Set the `source` as `master branch /docs folder`.
1. Optionally, use the `choose a theme` button to choose a theme for your documentation.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ checkstyle {
toolVersion = '10.2'
}

run{
run {
standardInput = System.in
enableAssertions = true
}
2 changes: 2 additions & 0 deletions data/events/event.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
submit v1.0 | 2023-10-29T23:59:59 | 2023-10-30T23:59:59
eat dinner | 2023-12-20T19:00 | 2023-12-20T20:00
8 changes: 8 additions & 0 deletions data/flashcards/flashcard.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
d | a | - | - | -
dfdf | dfdf | - | - | -
dfdf | asdfdf | - | - | -
ddf | dfdf | - | - | -
hello | bye | - | - | -
hello | bye | - | - | -
end program | hello | - | - | -
hello | world | - | - | -
13 changes: 9 additions & 4 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

package seedu.duke;

import seedu.duke.flashcard.Flashcard;
import seedu.duke.calendar.CalendarManager;
import seedu.duke.flashcard.FlashcardComponent;
import seedu.duke.flashcard.FlashcardDirectory;

import java.util.ArrayList;
import java.util.Scanner;
Expand All @@ -17,7 +16,8 @@ public static void main(String[] args) {
}

private void run() {
FlashcardComponent fc = new FlashcardComponent(new ArrayList<Flashcard>());
FlashcardComponent fc = new FlashcardComponent();
CalendarManager cm = new CalendarManager(new ArrayList<>());

Scanner scanner = new Scanner(System.in);
String input;
Expand All @@ -28,8 +28,13 @@ private void run() {

if (fc.isResponsible(input)) {
fc.processInput(input);

} else if (cm.isResponsible(input)) {
cm.processInput(input);
} else {
System.out.println(" Invalid command! Please try again.");
}
}

}
}
}
4 changes: 3 additions & 1 deletion src/main/java/seedu/duke/calendar/Calendar.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//@@ kherlenbayasgalan & jingxizhu

package seedu.duke.calendar;

public class Calendar {
EventStorage eventStorage;
EventList eventList;
}
2 changes: 2 additions & 0 deletions src/main/java/seedu/duke/calendar/CalendarCommandParser.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@@ kherlenbayasgalan & jingxizhu

package seedu.duke.calendar;

import seedu.duke.calendar.command.AddEventCommand;
Expand Down
60 changes: 57 additions & 3 deletions src/main/java/seedu/duke/calendar/CalendarManager.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,72 @@
//@@ kherlenbayasgalan & jingxizhu

package seedu.duke.calendar;

import seedu.duke.calendar.command.EventCommand;
import seedu.duke.calendar.command.UnknownCommand;
import seedu.duke.calendar.Event;
import seedu.duke.flashcard.FlashcardStorage;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class CalendarManager {
Calendar calendar;
CalendarUi calendarUi;
EventList eventList;
CalendarCommandParser calendarCommandParser;
Scanner scanner;

private EventStorage storage;

public CalendarManager(ArrayList<Event> events) {

EventDirectory eventdirectory = new EventDirectory();
eventdirectory.listEventFiles();

storage = new EventStorage("./data/events/event.txt");

try{
eventList = storage.loadEvents();
} catch (FileNotFoundException e){
System.out.println("Making new file for Events");
eventList = new EventList(events);
}

public CalendarManager() {
calendar = new Calendar();
calendarUi = new CalendarUi();
calendarUi = new CalendarUi(eventList);
calendarCommandParser = new CalendarCommandParser();
scanner = new Scanner(System.in);

}

public void start() {
public EventStorage getStorage(){
return this.storage;
}

public boolean validCommand(String input) {
EventCommand command = calendarCommandParser.parseInput(input);

return !(command instanceof UnknownCommand);
}

public boolean isResponsible(String input) {
return validCommand(input);
}

public void processInput(String input) {
startCalendar(input);

storage.saveEvents(eventList.getEvent());
}

public void startCalendar(String input) {
EventCommand command = calendarCommandParser.parseInput(input);
assert !(command instanceof seedu.duke.calendar.command.UnknownCommand) :
"Command cannot be " + "unknown";
calendarUi.executeCommand(command);
//calendarCommandParser.parseInput(command);
}

}
15 changes: 15 additions & 0 deletions src/main/java/seedu/duke/calendar/CalendarUi.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package seedu.duke.calendar;

import seedu.duke.calendar.command.EventCommand;

import java.util.Scanner;

public class CalendarUi {
private Scanner scanner;
private EventList eventList;

public CalendarUi (EventList eventList) {
scanner = new Scanner(System.in);
this.eventList = eventList;
}

public void executeCommand(EventCommand command) {
command.execute(scanner, eventList);
}
}
20 changes: 11 additions & 9 deletions src/main/java/seedu/duke/calendar/Event.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//@@author @@kherlenbayasgalan & @@ Jingxizhu

package seedu.duke.calendar;

import java.time.LocalDate;
import java.time.LocalDateTime;

public class Event {
String name;
LocalDate from;
LocalDate to;
private String name;
private LocalDateTime from;
private LocalDateTime to;

public Event(String name, LocalDate from, LocalDate to) {
public Event(String name, LocalDateTime from, LocalDateTime to) {
this.name = name;
this.from = from;
this.to = to;
Expand All @@ -21,19 +23,19 @@ public void setName(String name) {
this.name = name;
}

public LocalDate getFrom() {
public LocalDateTime getFrom() {
return from;
}

public void setFrom(LocalDate from) {
public void setFrom(LocalDateTime from) {
this.from = from;
}

public LocalDate getTo() {
public LocalDateTime getTo() {
return to;
}

public void setTo(LocalDate to) {
public void setTo(LocalDateTime to) {
this.to = to;
}

Expand Down
67 changes: 67 additions & 0 deletions src/main/java/seedu/duke/calendar/EventDirectory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package seedu.duke.calendar;

import java.io.File;

/**
* directory for directory
* can list-up txt files in text folder
* In version 1, using only event.txt
* In version 2, can select or create
*/

public class EventDirectory {
String path;
File file;

public EventDirectory(){
path = "./data/events";

file = new File(path);
if(!file.exists()){
if(file.mkdir()){
System.out.println(" Created events directory");
} else{
System.out.println(" Failed to create directory");
}
} else{
System.out.println(" Using data/events directory");
}
}

/**
* list-up saved files
* selecting file is for version 2
*/
public void listEventFiles(){
String[] eventFiles = file.list();
if(eventFiles == null){
System.out.println("Failed to find files");
} else if(eventFiles.length == 0){
System.out.println("No files exist");
} else{
for(String eventFile : eventFiles){
System.out.println(" "+eventFile);
}
}
}

/**
* return default directory
* for version 1
* @return directory for flashcard txt file
*/
public String defaultDirectory() {
return this.path + "/event.txt";
}

/**
* return directory of flashcard txt file
* for version 2
* @param path
* @return
*/
public String eventDirectory(String path) {
return this.path + path;
}

}
32 changes: 32 additions & 0 deletions src/main/java/seedu/duke/calendar/EventList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package seedu.duke.calendar;


import java.util.ArrayList;

public class EventList {
private ArrayList<Event> eventList;

public EventList(ArrayList<Event> eventList) {
this.eventList = eventList;
}

public void addEvent(Event event) {
eventList.add(event);
}

public ArrayList<Event> getEvent() {
return eventList;
}

public int getSize(){ return eventList.size();}

public void deleteEvent(String name) {
eventList.removeIf(event -> event.getName().equals(name));
}
@Override
public String toString() {
return "EventStorage{" +
"events=" + eventList +
'}';
}
}
Loading

0 comments on commit b60ffc3

Please sign in to comment.