From d810a104730b1a0208ef154cac06120963a18139 Mon Sep 17 00:00:00 2001 From: Ozan-Can Ekinci Date: Sun, 15 Jan 2023 19:52:13 +0100 Subject: [PATCH] refactoring: changed countFileLines and readFile methods --- src/main/java/game/runGame.java | 8 ++++---- src/test/java/game/runGameTest.java | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/game/runGame.java b/src/main/java/game/runGame.java index 747704a..8fb7550 100644 --- a/src/main/java/game/runGame.java +++ b/src/main/java/game/runGame.java @@ -10,8 +10,8 @@ public class runGame { public static String QuestionsPath = "QandA/Questions.txt"; public static String AnswersPath = "QandA/Answers.txt"; public static int lines = CountFileLines(QuestionsPath); - public static String[] arrQuestions = readFile(QuestionsPath); - public static String[] arrAnswers = readFile(AnswersPath); + public static String[] arrQuestions = readFile(QuestionsPath, lines); + public static String[] arrAnswers = readFile(AnswersPath, lines); public static String[] splitAns; public void run(int i) { @@ -40,9 +40,9 @@ public class runGame { } - public static String[] readFile(String Path) { + public static String[] readFile(String Path, int Lines) { BufferedReader reader; - String[] Arr = new String[lines]; + String[] Arr = new String[Lines]; try { reader = new BufferedReader(new FileReader(Path)); String line = reader.readLine(); diff --git a/src/test/java/game/runGameTest.java b/src/test/java/game/runGameTest.java index 0330d04..7af2aa0 100644 --- a/src/test/java/game/runGameTest.java +++ b/src/test/java/game/runGameTest.java @@ -47,7 +47,8 @@ class runGameTest { writer.write("Zeile 2\n"); writer.write("Zeile 3\n"); writer.close(); - String[] lines = runGame.readFile(file.getAbsolutePath()); + int numLine = runGame.CountFileLines(file.getAbsolutePath()); + String[] lines = runGame.readFile(file.getAbsolutePath(), numLine); assertEquals("Zeile 1", lines[0]); assertEquals("Zeile 2", lines[1]); assertEquals("Zeile 3", lines[2]);