Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2324S1#29 from junhyeong0411/master
Browse files Browse the repository at this point in the history
Show saved flashcardList size
  • Loading branch information
junhyeong0411 authored Oct 19, 2023
2 parents 5df026d + 3c2c4e6 commit 0c057fa
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion data/flashcard.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ ddf | dfdf | - | - | -
hello | bye | - | - | -
hello | bye | - | - | -
end program | hello | - | - | -
d | d | - | - | -
hello | world | - | - | -
1 change: 0 additions & 1 deletion src/main/java/seedu/duke/flashcard/FlashcardComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public FlashcardComponent(ArrayList<Flashcard> flashcards) {
storage = new FlashcardStorage("./data/flashcard.txt");
try {
flashcardList = storage.loadFlashcards();
System.out.println("Loading existed File");
} catch (FileNotFoundException e){
System.out.println("Making New file");
flashcardList = new FlashcardList(flashcards);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/duke/flashcard/FlashcardDirectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public FlashcardDirectory(){
file = new File(path);
if(!file.exists()){
if(file.mkdir()){
System.out.println("Created data directory");
System.out.println(" Created data directory");
} else{
System.out.println("Failed to create directory");
System.out.println(" Failed to create directory");
}
} else{
System.out.println("Using data directory");
System.out.println(" Using data directory");
}
}

Expand All @@ -41,7 +41,7 @@ public void listFlashcardFiles(){
System.out.println("No files exist");
} else{
for(String flashcardFile : flashcardFiles){
System.out.println(flashcardFile);
System.out.println(" "+flashcardFile);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/duke/flashcard/FlashcardList.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public ArrayList<Flashcard> getFlashcards() {
return flashcards;
}

// @@author junhyeong0411
public int getSize(){
return flashcards.size();
}


public void add(Flashcard flashcard) {
flashcards.add(flashcard);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/duke/flashcard/FlashcardStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public boolean isStorageAvailable(){
* @return Flashcard object
*/
private Flashcard loadFlashcard(String[] tokens){

assert tokens.length == 5: "Token length should be 5";

String frontText = tokens[0].trim();
String backText = tokens[1].trim();
String[] tags = tokens[2].trim().split("/");
Expand Down Expand Up @@ -82,11 +85,14 @@ public FlashcardList loadFlashcards() throws FileNotFoundException{
flashcardList.add(loadFlashcard(flashTokens));
}

System.out.println(String.format(" There are currently %d flashcards in the savefile", flashcardList.getSize()));

return flashcardList;

}

public void saveFlashcards(ArrayList<Flashcard> flashcardList) {

try {
FileWriter fw = new FileWriter(path);

Expand Down

0 comments on commit 0c057fa

Please sign in to comment.