From 1e492b43ee211aa9c5c9c934d914ea622453f4c8 Mon Sep 17 00:00:00 2001 From: junhyeong0411 Date: Thu, 19 Oct 2023 21:16:57 +0900 Subject: [PATCH] Show saved flashcardList size --- data/flashcard.txt | 1 + .../java/seedu/duke/flashcard/FlashcardComponent.java | 1 - .../java/seedu/duke/flashcard/FlashcardDirectory.java | 8 ++++---- src/main/java/seedu/duke/flashcard/FlashcardList.java | 5 +++++ src/main/java/seedu/duke/flashcard/FlashcardStorage.java | 6 ++++++ 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/data/flashcard.txt b/data/flashcard.txt index ea364105f2..3007b598ab 100644 --- a/data/flashcard.txt +++ b/data/flashcard.txt @@ -5,3 +5,4 @@ ddf | dfdf | - | - | - hello | bye | - | - | - hello | bye | - | - | - end program | hello | - | - | - +hello | world | - | - | - diff --git a/src/main/java/seedu/duke/flashcard/FlashcardComponent.java b/src/main/java/seedu/duke/flashcard/FlashcardComponent.java index e37135afb2..ae5fd1c04d 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardComponent.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardComponent.java @@ -27,7 +27,6 @@ public FlashcardComponent(ArrayList 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); diff --git a/src/main/java/seedu/duke/flashcard/FlashcardDirectory.java b/src/main/java/seedu/duke/flashcard/FlashcardDirectory.java index a932ed87ce..ad25a31f82 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardDirectory.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardDirectory.java @@ -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"); } } @@ -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); } } } diff --git a/src/main/java/seedu/duke/flashcard/FlashcardList.java b/src/main/java/seedu/duke/flashcard/FlashcardList.java index c6d317619e..cce69c2d36 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardList.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardList.java @@ -15,6 +15,11 @@ public ArrayList getFlashcards() { return flashcards; } + // @@author junhyeong0411 + public int getSize(){ + return flashcards.size(); + } + public void add(Flashcard flashcard) { flashcards.add(flashcard); diff --git a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java index 3cc01d28c1..8376d283e7 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java @@ -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("/"); @@ -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 flashcardList) { + try { FileWriter fw = new FileWriter(path);