Skip to content

Commit

Permalink
Merge pull request #43 from Geinzit/master
Browse files Browse the repository at this point in the history
improve code style.
  • Loading branch information
Geinzit authored Apr 3, 2024
2 parents a4e4d94 + 3d95139 commit 1fde2dc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 45 deletions.
6 changes: 2 additions & 4 deletions src/main/java/seedu/duke/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ private static ArrayList<Object> toSuffix(ArrayList<Object> formula) {
while( !opStack.empty()){
if(!prior(op,opStack.peek()) ){
suffix.add(opStack.pop());
}
else {
} else {
break;
}
}
Expand Down Expand Up @@ -127,8 +126,7 @@ private static ArrayList<Object> 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++;
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/seedu/duke/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class Checker {
private int correctNumber;
private double accuracy;
private long time;
List<Problem> wrongProblem= new ArrayList<>();
List<String> wrongAnswer = new ArrayList<>();
private List<Problem> wrongProblem= new ArrayList<>();
private List<String> wrongAnswer = new ArrayList<>();

public Checker(Test test){
assert test != null: "Input null test!";
Expand Down Expand Up @@ -50,8 +50,7 @@ void getUserAnswer() {
if (checkCorrectness(problem, answer)) {
correctNumber++;
isCorrect[i] = true;
}
else {
} else {
wrongAnswer.add(userInput);
wrongProblem.add(problem);
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/seedu/duke/Problem.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public String unsolved() {
return description + "__";
}

public String getDescription() {return description;}

public double getAnswer() {
return answer;
}
Expand Down
39 changes: 4 additions & 35 deletions src/main/java/seedu/duke/ProblemGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,49 +91,18 @@ private Test generate(HashMap<String, String> 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<length;j++){
int temp_random_number = (int) (Math.random() * max);
descriptionBuilder.append(temp_random_number);
int tempRandomNumber = (int) (Math.random() * max);
descriptionBuilder.append(tempRandomNumber);

if(j != length - 1){
String temp_random_operator = operations.get((int) (Math.random() * operations.size()));
descriptionBuilder.append(temp_random_operator);
String tempRandomOperator = operations.get((int) (Math.random() * operations.size()));
descriptionBuilder.append(tempRandomOperator);
}
}

Expand Down

0 comments on commit 1fde2dc

Please sign in to comment.