From e4f352e491e6bee1e281a3aeac2b5cbec16e50ce Mon Sep 17 00:00:00 2001 From: ryanlohyr Date: Sun, 15 Oct 2023 01:22:18 +0800 Subject: [PATCH] fix window os bug --- .../controllers/ModulePlannerController.java | 35 ++++++++++--------- .../ModulePlannerControllerTest.java | 6 ++-- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/main/java/seedu/duke/controllers/ModulePlannerController.java b/src/main/java/seedu/duke/controllers/ModulePlannerController.java index ad732347b0..738344246e 100644 --- a/src/main/java/seedu/duke/controllers/ModulePlannerController.java +++ b/src/main/java/seedu/duke/controllers/ModulePlannerController.java @@ -2,36 +2,39 @@ import seedu.duke.views.CommandLineView; import seedu.duke.utils.Parser; + import java.util.Scanner; public class ModulePlannerController { private CommandLineView view; - private Parser parser; - public ModulePlannerController(){ + private Parser parser; + + public ModulePlannerController() { this.view = new CommandLineView(); this.parser = new Parser(); } - public void start(){ + + public void start() { view.displayWelcome(); Scanner in = new Scanner(System.in); String userInput = in.nextLine(); - while(!userInput.equals("Bye")){ + while (!userInput.equals("Bye")) { String[] words = userInput.split(" "); String initialWord = words[0]; - switch(initialWord){ - case "hi":{ + switch (initialWord) { + case "hi": { view.displayMessage("can put the commands here"); break; } - case "hello":{ + case "hello": { view.displayMessage("yup"); break; } - case "pace":{ + case "pace": { //assumed that everyone graduates at y4s2 //waiting for retrieving logic int modulesCreditsCompleted = 100; @@ -40,7 +43,7 @@ public void start(){ computePace(words, creditsLeft); break; } - default:{ + default: { view.displayMessage("Hello " + userInput); break; } @@ -54,18 +57,18 @@ public void start(){ * Computes the recommended pace for completing a degree based on the provided academic year * and credits left until graduation. * - * @param userInput An array of user input where userInput[0] is the command and userInput[1] is the academic year. + * @param userInput An array of user input where userInput[0] is the command and userInput[1] is the academic year. * @param creditsLeft The number of credits left until graduation. * @throws IllegalArgumentException if the provided academic year is invalid. */ - public void computePace(String[] userInput,int creditsLeft){ + public void computePace(String[] userInput, int creditsLeft) { boolean argumentProvided = userInput.length != 1; //wait for text file logic - if(!argumentProvided){ + if (!argumentProvided) { view.displayMessage("You currently have " + creditsLeft + " MCs till graduation"); return; } - if(!parser.isValidAcademicYear(userInput[1])){ + if (!parser.isValidAcademicYear(userInput[1])) { return; } @@ -81,8 +84,8 @@ public void computePace(String[] userInput,int creditsLeft){ int semesterIntValue = Character.getNumericValue(semester.charAt(1)); //if we are at y2s1, we have 5 semesters left int semestersLeft = (lastYearOfDegree - yearIntValue) * 2 + (lastSemesterOfYear - semesterIntValue); - int creditsPerSem = Math.round((float) creditsLeft /semestersLeft) ; - view.displayMessage("You currently have " + creditsLeft + "MCs for " + semestersLeft + " semesters"); - view.displayMessage("Recommended Pace: " +creditsPerSem + "MCs per sem until graduation"); + int creditsPerSem = Math.round((float) creditsLeft / semestersLeft); + view.displayMessage("You have " + creditsLeft + "MCs for " + semestersLeft + " semesters. " + + "Recommended Pace: "+ creditsPerSem + "MCs per sem until graduation"); } } diff --git a/src/test/java/seedu/duke/controllers/ModulePlannerControllerTest.java b/src/test/java/seedu/duke/controllers/ModulePlannerControllerTest.java index fe4dcc7616..96fc877626 100644 --- a/src/test/java/seedu/duke/controllers/ModulePlannerControllerTest.java +++ b/src/test/java/seedu/duke/controllers/ModulePlannerControllerTest.java @@ -78,10 +78,8 @@ void computePaceValidYear() { String test = "hi"; // Capture the printed output String printedOutput = outputStream.toString().trim(); - String lineOne = "You currently have 60MCs for 5 semesters\n"; - String lineTwo = "Recommended Pace: 12MCs per sem until graduation"; - String expectedOutput = lineOne + lineTwo; + String line = "You have 60MCs for 5 semesters. Recommended Pace: 12MCs per sem until graduation"; // Assert the printed output matches the expected value - assertEquals(printedOutput, expectedOutput); + assertEquals(printedOutput, line); } }