From 3d95139e7eca9396debcc98b5fee7f8d88bef809 Mon Sep 17 00:00:00 2001 From: Geinzit Date: Wed, 3 Apr 2024 22:08:30 +0800 Subject: [PATCH] improve code style. --- src/main/java/seedu/duke/Calculator.java | 6 +-- src/main/java/seedu/duke/Checker.java | 7 ++-- src/main/java/seedu/duke/Problem.java | 2 - .../java/seedu/duke/ProblemGenerator.java | 39 ++----------------- 4 files changed, 9 insertions(+), 45 deletions(-) diff --git a/src/main/java/seedu/duke/Calculator.java b/src/main/java/seedu/duke/Calculator.java index 7084265fa3..eb8f965b21 100644 --- a/src/main/java/seedu/duke/Calculator.java +++ b/src/main/java/seedu/duke/Calculator.java @@ -68,8 +68,7 @@ private static ArrayList toSuffix(ArrayList formula) { while( !opStack.empty()){ if(!prior(op,opStack.peek()) ){ suffix.add(opStack.pop()); - } - else { + } else { break; } } @@ -127,8 +126,7 @@ private static ArrayList toFormula(StringBuilder sb) { Integer num = Integer.parseInt(sb.substring(numStart,numEnd)) ; formula.add(num); i = numEnd; - } - else{ + } else{ formula.add (Character.toString(sb.charAt(i)) ); i++; } diff --git a/src/main/java/seedu/duke/Checker.java b/src/main/java/seedu/duke/Checker.java index ac51d02fb9..2e3b5d2f7c 100644 --- a/src/main/java/seedu/duke/Checker.java +++ b/src/main/java/seedu/duke/Checker.java @@ -10,8 +10,8 @@ public class Checker { private int correctNumber; private double accuracy; private long time; - List wrongProblem= new ArrayList<>(); - List wrongAnswer = new ArrayList<>(); + private List wrongProblem= new ArrayList<>(); + private List wrongAnswer = new ArrayList<>(); public Checker(Test test){ assert test != null: "Input null test!"; @@ -50,8 +50,7 @@ void getUserAnswer() { if (checkCorrectness(problem, answer)) { correctNumber++; isCorrect[i] = true; - } - else { + } else { wrongAnswer.add(userInput); wrongProblem.add(problem); } diff --git a/src/main/java/seedu/duke/Problem.java b/src/main/java/seedu/duke/Problem.java index 9783749c03..454bc8329a 100644 --- a/src/main/java/seedu/duke/Problem.java +++ b/src/main/java/seedu/duke/Problem.java @@ -18,8 +18,6 @@ public String unsolved() { return description + "__"; } - public String getDescription() {return description;} - public double getAnswer() { return answer; } diff --git a/src/main/java/seedu/duke/ProblemGenerator.java b/src/main/java/seedu/duke/ProblemGenerator.java index 4803735b52..cbd043627f 100644 --- a/src/main/java/seedu/duke/ProblemGenerator.java +++ b/src/main/java/seedu/duke/ProblemGenerator.java @@ -91,49 +91,18 @@ private Test generate(HashMap parameter) { Test test = new Test(op, maxDigit, number,length); for (int i = 0; i < number; i++) { -/* - String description; - double answer; - int max = (int) Math.pow(10, maxDigit); - int op1 = (int) (Math.random() * max); - int op2 = (int) (Math.random() * max); - String tempOperator = operations.get((int) (Math.random() * operations.size())); - - - switch (tempOperator) { - case ("+"): - answer = op1 + op2; - break; - case ("-"): - answer = op1 - op2; - break; - case ("*"): - answer = op1 * op2; - break; - case ("/"): - if (op2 == 0) { - continue; - } - answer = (double) op1 / op2; - break; - default: - continue; - } - - description = op1 + tempOperator + op2 + "="; -*/ StringBuilder descriptionBuilder = new StringBuilder(); double answer; int max = (int) Math.pow(10, maxDigit); for (int j = 0;j