Skip to content

Commit

Permalink
Merge pull request #116 from classskipper351/master
Browse files Browse the repository at this point in the history
Changed the style of my code and fixed bugs
  • Loading branch information
classskipper351 authored Apr 15, 2024
2 parents c08e0fc + 7a5a52d commit cb3ca03
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 106 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.
9 changes: 9 additions & 0 deletions recordList.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
2024-04-15 17:59:04 0.0 0.0 60559209 user-DIY 463d_,23.0
2024-04-15 18:01:52 31.57894736842105 0.0 78253069 auto-generated 87-58,29.0 90*60,5400.0 65/5,13.0 71*50,3550.0 43+46,89.0 32+56,88.0 43*81,3483.0 75/8,9.375 30+52,82.0 68/9,7.556
2024-04-15 18:03:47 3.75 1.0 60559209 user-DIY 463d_,23.0
2024-04-15 18:14:21 0.0 0.0 1234776916 user-DIY 2][,343.0
2024-04-15 18:14:49 3.333333333333333 1.0 1234776916 user-DIY 2][,343.0
2024-04-15 22:21:39 54.54545454545455 0.0 -76978608 auto-generated 92*88,8096.0 63-56,7.0 49-12,37.0 24-57,-33.0 86-77,9.0 46-37,9.0 22+23,45.0 84-14,70.0 40/1,40.0 72*73,5256.0
2024-04-15 22:33:39 100.0 0.0 -76978608 auto-generated 59+28,87.0 9/8,1.125 67-86,-19.0 18-28,-10.0 47*52,2444.0 10/8,1.25 18-93,-75.0 2/3,0.667 19/7,2.714 89*10,890.0
2024-04-15 22:36:06 120.0 0.0 -76978608 auto-generated 57*40,2280.0 12/2,6.0 21*17,357.0 38+16,54.0 84+34,118.0 23+86,109.0 85+57,142.0 71+15,86.0 3*30,90.0 50/6,8.333
2024-04-15 22:38:40 300.0 0.0 -76978608 auto-generated 96*82,7872.0 16+77,93.0 98+9,107.0 25/6,4.167 17+66,83.0 44+36,80.0 86/8,10.75 19-81,-62.0 45-54,-9.0 78/7,11.143
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 cb3ca03

Please sign in to comment.