Skip to content

Commit 418ce43

Browse files
Merge pull request nus-cs2113-AY2324S1#34 from wendelinwemhoener/unify-flashcard-and-calendar-mode
Unify calendar and flashcard mode
2 parents 012d36d + 647b47e commit 418ce43

File tree

5 files changed

+22
-61
lines changed

5 files changed

+22
-61
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ Steps for publishing documentation to the public:
6262
1. Scroll down to the `GitHub Pages` section.
6363
1. Set the `source` as `master branch /docs folder`.
6464
1. Optionally, use the `choose a theme` button to choose a theme for your documentation.
65+

data/flashcard.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ hello | bye | - | - | -
66
hello | bye | - | - | -
77
end program | hello | - | - | -
88
hello | world | - | - | -
9+
dfdf | aaa | - | - | -

src/main/java/seedu/duke/Duke.java

Lines changed: 10 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
//@@author wendelinwemhoener & kherlenbayasgalan
1+
//@@author wendelinwemhoener
22

33
package seedu.duke;
44

5-
import seedu.duke.flashcard.Flashcard;
6-
import seedu.duke.flashcard.FlashcardComponent;
75
import seedu.duke.calendar.CalendarManager;
8-
import seedu.duke.calendar.Event;
6+
import seedu.duke.flashcard.FlashcardComponent;
97

108
import java.util.ArrayList;
119
import java.util.Scanner;
@@ -17,71 +15,25 @@ public static void main(String[] args) {
1715
new Duke().run();
1816
}
1917

20-
private void runCalendar() {
21-
System.out.println("Enter your command: ");
22-
23-
CalendarManager manager = new CalendarManager(new ArrayList<Event>());
24-
25-
Scanner scanner = new Scanner(System.in);
26-
String input;
27-
boolean isDone = false;
28-
29-
while (!isDone) {
30-
input = scanner.nextLine();
31-
32-
if (input.equals("end program")) {
33-
System.out.println("Bye bye");
34-
break;
35-
} else if (input.equals("flashcard")) {
36-
System.out.println(" Switched to flashcard functions");
37-
runFlashcard();
38-
} else if (manager.validCommand(input)) {
39-
manager.startCalendar(input);
40-
} else {
41-
System.out.println("Invalid command! Enter a valid command.");
42-
}
43-
}
44-
}
45-
46-
private void runFlashcard() {
47-
FlashcardComponent fc = new FlashcardComponent(new ArrayList<Flashcard>());
18+
private void run() {
19+
FlashcardComponent fc = new FlashcardComponent();
20+
CalendarManager cm = new CalendarManager(new ArrayList<>());
4821

4922
Scanner scanner = new Scanner(System.in);
5023
String input;
5124
boolean shouldTerminate = false;
5225

53-
System.out.print("Enter your command: ");
5426
while (!shouldTerminate) {
5527
input = scanner.nextLine();
5628

57-
if (input.equals("end program")) {
58-
System.out.println("Bye bye");
59-
break;
60-
} else if (input.equals("calendar")) {
61-
System.out.println(" Switched to calendar functions");
62-
runCalendar();
63-
} else if (fc.isResponsible(input)) {
29+
if (fc.isResponsible(input)) {
6430
fc.processInput(input);
31+
} else if (cm.isResponsible(input)) {
32+
cm.processInput(input);
6533
} else {
66-
System.out.println(" Invalid command! Sorry; please try again.");
34+
System.out.println(" Invalid command! Please try again.");
6735
}
6836
}
69-
}
7037

71-
private void run() {
72-
String flashcardOrCalendar;
73-
Scanner scanner = new Scanner(System.in);
74-
75-
System.out.println("Do you choose flashcard or calendar? ");
76-
flashcardOrCalendar = scanner.nextLine();
77-
78-
if (flashcardOrCalendar.equals("flashcard")) {
79-
runFlashcard();
80-
} else if (flashcardOrCalendar.equals("calendar")) {
81-
runCalendar();
82-
} else {
83-
System.out.println("Invalid command! Sorry; please try again.");
84-
run();
85-
}
8638
}
87-
}
39+
}

src/main/java/seedu/duke/calendar/CalendarManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public boolean validCommand(String input) {
3030
return !(command instanceof UnknownCommand);
3131
}
3232

33+
public boolean isResponsible(String input) {
34+
return validCommand(input);
35+
}
36+
37+
public void processInput(String input) {
38+
startCalendar(input);
39+
}
40+
3341
public void startCalendar(String input) {
3442
EventCommand command = calendarCommandParser.parseInput(input);
3543
assert !(command instanceof seedu.duke.calendar.command.UnknownCommand) :

src/main/java/seedu/duke/flashcard/FlashcardComponent.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ public class FlashcardComponent {
1616
private FlashcardStorage storage;
1717

1818

19-
public FlashcardComponent(ArrayList<Flashcard> flashcards) {
19+
public FlashcardComponent() {
2020
parser = new FlashcardCommandParser();
2121

2222
//@@author junhyeong0411
23-
2423
FlashcardDirectory flashcarddirectory = new FlashcardDirectory();
2524
flashcarddirectory.listFlashcardFiles();
2625

@@ -29,7 +28,7 @@ public FlashcardComponent(ArrayList<Flashcard> flashcards) {
2928
flashcardList = storage.loadFlashcards();
3029
} catch (FileNotFoundException e){
3130
System.out.println("Making New file");
32-
flashcardList = new FlashcardList(flashcards);
31+
flashcardList = new FlashcardList(new ArrayList<>());
3332
}
3433

3534
//@@author wendelinwemhoener

0 commit comments

Comments
 (0)