Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* 'master' of https://github.com/AY2324S2-CS2113-T13-1/tp:
  gradle check passed
  修改了我的代码风格以及exit的bug Fixed my code style and  bugs in exit

# Conflicts:
#	recordList.txt
  • Loading branch information
Celineyaa committed Apr 15, 2024
2 parents 0a3daf1 + dd8e7aa commit 756d7aa
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 108 deletions.
14 changes: 0 additions & 14 deletions docs/diagrams/caculator.puml

This file was deleted.

53 changes: 41 additions & 12 deletions docs/diagrams/problemgenerator.puml
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
@startuml

package seedu.duke {
class ProblemGenerator {
-DEFAULT_NUMBER: String = "10"
-DEFAULT_MAX_DIGITS: String = "2"
-DEFAULT_OPERATORS: String = "+-*/"
-PROBLEM_FORM: String
-in: Scanner
+typeChoose(): Test
-generate(parameter: HashMap<String, String>): Test
+parseCommand(command: String): HashMap<String, String>
-defaultOptions(command: String, options: HashMap<String, String>): void
}


class ProblemGenerator {
- MINIMUM_NUMBER: int
- MAXIMUM_NUMBER: int
- MINIMUM_DIGIT: int
- MAXIMUM_DIGITS: int
- MINIMUM_LENGTH: int
- VALID_OPERATORS: String
- MAXIMUM_LENGTH: int
- DEFAULT_NUMBER: String
- DEFAULT_MAX_DIGITS: String
- DEFAULT_OPERATORS: String
- DEFAULT_LENGTH: String
+ parseCommand(command: String): HashMap<String, String>
- defaultOptions(options: HashMap<String, String>): HashMap<String, String>
+ typeChoose(command: String): Test
- checkValidity(parameter: HashMap<String, String>): HashMap<String, String>
- checkOperations(parameter: HashMap<String, String>)
- checkLength(parameter: HashMap<String, String>)
- checkMaxDigit(parameter: HashMap<String, String>)
- checkNumber(parameter: HashMap<String, String>)
- generate(parameter: HashMap<String, String>): Test
- buildFormula(length: int, max: int, descriptionBuilder: StringBuilder, operations: ArrayList<String>)
- getOperations(op: String): ArrayList<String>
- division_check(sb: StringBuilder): StringBuilder
}




class Test {
-operators: String
Expand All @@ -34,6 +53,16 @@ package seedu.duke {
class Ui {
+missingMessage(option: String): void
}
class Calculator {
- Stack<Double> numStack
- Stack<String> opStack
+ calculate(sb: StringBuilder): double
- calculateTwo(num1: double, num2: double, op: String): double
- toSuffix(formula: ArrayList<Object>): ArrayList<Object>
- prior(op1: String, op2: String): boolean
- getPriority(op: String): int
- toFormula(sb: StringBuilder): ArrayList<Object>
}
}


Expand All @@ -42,5 +71,5 @@ Test --> Problem: contains
ProblemGenerator --> Test: create
ProblemGenerator --> Test: generate
ProblemGenerator --> Ui: displayMessage

ProblemGenerator --> Calculator : calculate
@enduml
5 changes: 5 additions & 0 deletions docs/heinzhuang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Heinz Huang

GitHub username: Geinzit

Professional Gamer. Amateur Coder.
3 changes: 1 addition & 2 deletions recordList.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
2024-04-15 23:05:09 0.0 0.0 403716541 user-DIY 12*13等于多少,156.0
2024-04-15 23:05:30 6.666666666666666 1.0 403716541 user-DIY 12*13等于多少,156.0

1 change: 1 addition & 0 deletions src/main/java/seedu/duke/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private static String getExplanation(double num1, double num2, String op, double
}
alignedProblem = builder.toString();


}
return start + alignedProblem + "\n";
}
Expand Down
44 changes: 27 additions & 17 deletions src/main/java/seedu/duke/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Checker {
private long time;

public Checker(Test test) {
assert test != null : "You must intialize the checker with a test!";
assert test != null : "Input null test!";
this.userAnswer = new String[test.getNumber()];
this.test = test;
this.isCorrect = new Boolean[test.getNumber()];
Expand All @@ -25,54 +25,65 @@ public Checker(Test test) {
}

public static void showExplanation(Problem problem) {
assert problem != null : "You must give a problem to show the explanation!";
String explanations = problem.getExplanations();
Ui ui = new Ui("");
ui.print("The explanation of the problem: " + problem.solved());
ui.print("Let us caculate it step by step:");
ui.print(explanations);

ui.print("From all the steps above, we can get the answer: " + problem.solved()+"\n");

}


Boolean checkCorrectness(Problem problem, double answer) {
if(Math.abs(problem.getAnswer() - answer) < 0.01) {
return true;
}
return false;
return Math.abs(problem.getAnswer() - answer) < 0.01;
}

void getUserAnswer() {
long startTime = System.currentTimeMillis();
ui.startAnswerTest();
String userInput = ui.readCommand();

ui.print(
"you can type \"exit\" to quit the test when answering the question...");
//
boolean isQuit = false;
for (int i = 0; i < test.getNumber(); i++) {

if (isQuit){
break;
}

Problem problem = test.getProblem().get(i);
ui.print(problem.unsolved());
userInput = ui.readCommand();
String userInput = ui.readCommand();
userAnswer[i] = userInput;
double answer = Double.NEGATIVE_INFINITY;

boolean isValid = false;
if (userInput.equals("exit")) {
ui.exitTest();
ui.print("Exit the test! All the test not finished will be marked as wrong!");
break;
}
while (!isValid) {

try {
answer = Double.parseDouble(userInput);
isValid = true;

} catch (NumberFormatException e) {

ui.print("Invalid Input, please enter a number");
ui.print(problem.unsolved());
userInput = ui.readCommand();

if (userInput.equals("exit")) {
ui.print("Exit the test! All the test not finished will be marked as wrong!");
isQuit = true;
break;
}
}
}
if (isQuit){
break;
}

if (checkCorrectness(problem, answer)) {
correctNumber++;
Expand All @@ -86,12 +97,11 @@ void getUserAnswer() {
// hand with time and acc
long endTime = System.currentTimeMillis();
accuracy = (double) correctNumber / test.getNumber();
// millisecond to second
//millisecond to second
this.time = (endTime - startTime) / 1000;
for (int i = 0; i < test.getNumber(); i++) {
if (isCorrect[i] = false) {
Problem problem = test.getProblem().get(i);
wrongProblem.add(problem);
wrongProblem.add(test.getProblem().get(i));
wrongAnswer.add(userAnswer[i]);
}
}
Expand Down
Loading

0 comments on commit 756d7aa

Please sign in to comment.