Skip to content

Commit 0c057fa

Browse files
Merge pull request nus-cs2113-AY2324S1#29 from junhyeong0411/master
Show saved flashcardList size
2 parents 5df026d + 3c2c4e6 commit 0c057fa

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

data/flashcard.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ ddf | dfdf | - | - | -
55
hello | bye | - | - | -
66
hello | bye | - | - | -
77
end program | hello | - | - | -
8-
d | d | - | - | -
8+
hello | world | - | - | -

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public FlashcardComponent(ArrayList<Flashcard> flashcards) {
2727
storage = new FlashcardStorage("./data/flashcard.txt");
2828
try {
2929
flashcardList = storage.loadFlashcards();
30-
System.out.println("Loading existed File");
3130
} catch (FileNotFoundException e){
3231
System.out.println("Making New file");
3332
flashcardList = new FlashcardList(flashcards);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public FlashcardDirectory(){
2020
file = new File(path);
2121
if(!file.exists()){
2222
if(file.mkdir()){
23-
System.out.println("Created data directory");
23+
System.out.println(" Created data directory");
2424
} else{
25-
System.out.println("Failed to create directory");
25+
System.out.println(" Failed to create directory");
2626
}
2727
} else{
28-
System.out.println("Using data directory");
28+
System.out.println(" Using data directory");
2929
}
3030
}
3131

@@ -41,7 +41,7 @@ public void listFlashcardFiles(){
4141
System.out.println("No files exist");
4242
} else{
4343
for(String flashcardFile : flashcardFiles){
44-
System.out.println(flashcardFile);
44+
System.out.println(" "+flashcardFile);
4545
}
4646
}
4747
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public ArrayList<Flashcard> getFlashcards() {
1515
return flashcards;
1616
}
1717

18+
// @@author junhyeong0411
19+
public int getSize(){
20+
return flashcards.size();
21+
}
22+
1823

1924
public void add(Flashcard flashcard) {
2025
flashcards.add(flashcard);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public boolean isStorageAvailable(){
3333
* @return Flashcard object
3434
*/
3535
private Flashcard loadFlashcard(String[] tokens){
36+
37+
assert tokens.length == 5: "Token length should be 5";
38+
3639
String frontText = tokens[0].trim();
3740
String backText = tokens[1].trim();
3841
String[] tags = tokens[2].trim().split("/");
@@ -82,11 +85,14 @@ public FlashcardList loadFlashcards() throws FileNotFoundException{
8285
flashcardList.add(loadFlashcard(flashTokens));
8386
}
8487

88+
System.out.println(String.format(" There are currently %d flashcards in the savefile", flashcardList.getSize()));
89+
8590
return flashcardList;
8691

8792
}
8893

8994
public void saveFlashcards(ArrayList<Flashcard> flashcardList) {
95+
9096
try {
9197
FileWriter fw = new FileWriter(path);
9298

0 commit comments

Comments
 (0)