Skip to content

Commit

Permalink
Merge a221cec into e80c887
Browse files Browse the repository at this point in the history
  • Loading branch information
limhawjia committed Oct 30, 2019
2 parents e80c887 + a221cec commit 89455c8
Show file tree
Hide file tree
Showing 22 changed files with 152 additions and 176 deletions.
117 changes: 56 additions & 61 deletions questionBank.json
Original file line number Diff line number Diff line change
@@ -1,98 +1,93 @@
{
"questions" : [ {
"title" : "Two Number Adder",
"status" : "ATTEMPTED",
"status" : "NEW",
"difficulty" : "EASY",
"isBookmarked" : false,
"topics" : ["OTHERS"],
"topics" : [ "OTHERS" ],
"testCases" : [ {
"input": "1 2",
"expectedResult": "3"
},
{
"input": "100 2",
"expectedResult": "102"
}],
"input" : "1 2",
"expectedResult" : "3"
}, {
"input" : "100 2",
"expectedResult" : "102"
} ],
"userProgram" : {
"canonicalName": "Main",
"sourceCode": "public class Main {\n\tpublic static void main(String[] args) {\n\t}\n}"
"canonicalName" : "Adder",
"sourceCode" : "public class Adder { public static void main(String[] args) { } }"
},
"description" : "hello"
"description" : "Given an array of integers, return indices of the two numbers such that they add up to a specific target.\n\nYou may assume that each input would have exactly one solution, and you may not use the same element twice.\n\nExample:\n\nGiven nums = [2, 7, 11, 15], target = 9,\n\nBecause nums[0] + nums[1] = 2 + 7 = 9,\nreturn [0, 1]."
}, {
"title" : "Valid Sudoku",
"status" : "ATTEMPTED",
"status" : "NEW",
"difficulty" : "MEDIUM",
"isBookmarked" : false,
"topics" : ["OTHERS", "ARRAY", "DYNAMIC_PROGRAMMING"],
"isBookmarked" : true,
"topics" : [ "DYNAMIC_PROGRAMMING", "OTHERS", "ARRAY" ],
"testCases" : [ {
"input": "1 2 3 4 5 6 7 8 9",
"expectedResult": "True"
},
{
"input": "-1 -1 -1 -1",
"expectedResult": "False"
}],
"input" : "1 2 3 4 5 6 7 8 9",
"expectedResult" : "True"
}, {
"input" : "-1 -1 -1 -1",
"expectedResult" : "False"
} ],
"userProgram" : {
"canonicalName": "Main",
"sourceCode": "public class Main {\n\tpublic static void main(String[] args) {\n\t}\n}"
"canonicalName" : "Sudoku",
"sourceCode" : "public class Sudoku { public static void main(String[] args) { } }"
},
"description" : "hello"
"description" : "Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.\n\nYou may assume no duplicates in the array.\n\nExample 1:\n\nInput: [1,3,5,6], 5\nOutput: 2\nExample 2:\n\nInput: [1,3,5,6], 2\nOutput: 1\nExample 3:\n\nInput: [1,3,5,6], 7\nOutput: 4\nExample 4:\n\nInput: [1,3,5,6], 0\nOutput: 0"
}, {
"title" : "Palindrome Number",
"status" : "PASSED",
"status" : "NEW",
"difficulty" : "EASY",
"isBookmarked" : true,
"topics" : ["OTHERS", "RECURSION"],
"topics" : [ "OTHERS", "RECURSION" ],
"testCases" : [ {
"input": "12321",
"expectedResult": "True"
},
{
"input": "10111",
"expectedResult": "False"
}],
"input" : "12321",
"expectedResult" : "True"
}, {
"input" : "10111",
"expectedResult" : "False"
} ],
"userProgram" : {
"canonicalName": "Main",
"sourceCode": "public class Main {\n\tpublic static void main(String[] args) {\n\t}\n}"
"canonicalName" : "Palindrome",
"sourceCode" : "public class Palindrome { public static void main(String[] args) { } }"
},
"description" : "hello"
"description" : "Given a linked list, determine if it has a cycle in it.\n\nTo represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.\n\n \n\nExample 1:\n\nInput: head = [3,2,0,-4], pos = 1\nOutput: true\nExplanation: There is a cycle in the linked list, where tail connects to the second node.\n\n\nExample 2:\n\nInput: head = [1,2], pos = 0\nOutput: true\nExplanation: There is a cycle in the linked list, where tail connects to the first node.\n\n\nExample 3:\n\nInput: head = [1], pos = -1\nOutput: false\nExplanation: There is no cycle in the linked list."
}, {
"title" : "Swap nodes in pairs",
"status" : "NEW",
"difficulty" : "MEDIUM",
"isBookmarked" : false,
"topics" : ["GRAPH", "DYNAMIC_PROGRAMMING"],
"topics" : [ "DYNAMIC_PROGRAMMING", "GRAPH" ],
"testCases" : [ {
"input": "5 12 33 23",
"expectedResult": "4132"
},
{
"input": "2 31 01",
"expectedResult": "1232"
}],
"input" : "5 12 33 23",
"expectedResult" : "4132"
}, {
"input" : "2 31 01",
"expectedResult" : "1232"
} ],
"userProgram" : {
"canonicalName": "Main",
"sourceCode": "public class Main {\n\tpublic static void main(String[] args) {\n\t}\n}"
"canonicalName" : "NodePairs",
"sourceCode" : ""
},
"description" : "hello"
"description" : "Write an algorithm to determine if a number is \"happy\".\n\nA happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.\n\nExample: \n\nInput: 19\nOutput: true\nExplanation: \n12 + 92 = 82\n82 + 22 = 68\n62 + 82 = 100\n12 + 02 + 02 = 1"
}, {
"title" : "Merge k Sorted Lists",
"status" : "NEW",
"difficulty" : "HARD",
"isBookmarked" : true,
"topics" : ["SORTING", "LINKED_LIST"],
"isBookmarked" : false,
"topics" : [ "LINKED_LIST", "SORTING" ],
"testCases" : [ {
"input": "3 5 3 4 1 99 0 21 34 123 3 21 3 1",
"expectedResult": "0 1 3 4 21 34 99 123"
},
{
"input": "1 4 1 2 3 4",
"expectedResult": "1 2 3 4"
}],
"input" : "3 5 3 4 1 99 0 21 34 123 3 21 3 1",
"expectedResult" : "0 1 3 4 21 34 99 123"
}, {
"input" : "1 4 1 2 3 4",
"expectedResult" : "1 2 3 4"
} ],
"userProgram" : {
"canonicalName": "Main",
"sourceCode": "public class Main {\n\tpublic static void main(String[] args) {\n\t}\n}"
"canonicalName" : "Merge",
"sourceCode" : "public class Merge { public static void main(String[] args) { } }"
},
"description" : "hello"
}]
"description" : "Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengths.\n\nIf it is impossible to form any triangle of non-zero area, return 0.\n\n \n\nExample 1:\n\nInput: [2,1,2]\nOutput: 5\nExample 2:\n\nInput: [1,2,1]\nOutput: 0\nExample 3:\n\nInput: [3,2,3,4]\nOutput: 10\nExample 4:\n\nInput: [3,6,2,3]\nOutput: 8\n \n\nNote:\n\n3 <= A.length <= 10000\n1 <= A[i] <= 10^6"
} ]
}
4 changes: 0 additions & 4 deletions src/main/java/com/dukeacademy/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import com.dukeacademy.logic.question.QuestionsLogicManager;
import com.dukeacademy.model.prefs.ReadOnlyUserPrefs;
import com.dukeacademy.model.prefs.UserPrefs;
import com.dukeacademy.model.question.QuestionBank;
import com.dukeacademy.model.util.SampleDataUtil;
import com.dukeacademy.storage.prefs.JsonUserPrefsStorage;
import com.dukeacademy.storage.prefs.UserPrefsStorage;
import com.dukeacademy.storage.question.JsonQuestionBankStorage;
Expand Down Expand Up @@ -240,9 +238,7 @@ private void createQuestionBankFile(Path questionBankFilePath) {
try {
logger.info("Creating new question bank.");
// Copy default questions
QuestionBank qb = SampleDataUtil.getSampleQuestionBank();
Path defaultQuestions = Paths.get("questionBank.json");
QuestionBankStorage.saveQuestionBank(qb, defaultQuestions);
FileUtil.createIfMissing(questionBankFilePath);
Files.copy(defaultQuestions, questionBankFilePath, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
Expand Down
52 changes: 5 additions & 47 deletions src/main/java/com/dukeacademy/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,20 @@ public class CommandResult {

private final boolean view;

private final boolean bookmark;

private final boolean attempt;

private final boolean submit;

/**
* Constructs a {@code CommandResult} with the specified fields.
*
* @param feedbackToUser the feedback to user
* @param feedbackToUser the feedback to user
* @param showHelp the show help
* @param exit the exit
* @param home the home
* @param view the view
* @param bookmark the bookmark
*/
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit, boolean home, boolean view,
boolean bookmark, boolean attempt, boolean submit) {
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit, boolean home, boolean view) {
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = showHelp;
this.exit = exit;
this.home = home;
this.view = view;
this.bookmark = bookmark;
this.attempt = attempt;
this.submit = submit;
}

/**
Expand All @@ -57,8 +45,8 @@ public CommandResult(String feedbackToUser, boolean showHelp, boolean exit, bool
* @param feedbackToUser the feedback to user
*/
public CommandResult(String feedbackToUser) {
this(feedbackToUser, false, false, false, false, false,
false, false);
this(feedbackToUser, false, false, false, false
);
}

/**
Expand Down Expand Up @@ -106,33 +94,6 @@ public boolean isView() {
return view;
}

/**
* Is bookmark boolean.
*
* @return the boolean
*/
public boolean isBookmark() {
return bookmark;
}

/**
* Is attempt boolean.
*
* @return the boolean
*/
public boolean isAttempt() {
return attempt;
}

/**
* Is submit boolean.
*
* @return the boolean
*/
public boolean isSubmit() {
return submit;
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -148,10 +109,7 @@ public boolean equals(Object other) {
return feedbackToUser.equals(otherCommandResult.feedbackToUser)
&& showHelp == otherCommandResult.showHelp
&& exit == otherCommandResult.exit
&& view == otherCommandResult.view
&& bookmark == otherCommandResult.bookmark
&& attempt == otherCommandResult.attempt
&& submit == otherCommandResult.submit;
&& view == otherCommandResult.view;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public CommandResult execute() throws CommandException {
// Notify user that he has already passed this question
String feedback = "Reattempting question " + (index + 1) + " : " + userSelection.getTitle() + " - "
+ "You have already passed this question successfully.";
return new CommandResult(feedback, false, false, false, false, false,
true, false);
return new CommandResult(feedback, false, false, false, false
);
} else {
// Update status of question to ATTEMPTED
Question questionToAttempt = this.questionsLogic.getQuestion(index).withNewStatus(Status.ATTEMPTED);
Expand All @@ -62,8 +62,8 @@ public CommandResult execute() throws CommandException {
this.programSubmissionLogic.setCurrentQuestion(questionToAttempt);

String feedback = "Attempting question " + (index + 1) + " : " + questionToAttempt.getTitle();
return new CommandResult(feedback, false, false, false, false, false,
true, false);
return new CommandResult(feedback, false, false, false, false
);
}

} catch (IndexOutOfBoundsException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public CommandResult execute() throws CommandException {
// Simply notify user that question is already bookmarked
String feedback = "Question " + (index + 1) + " : " + userSelection.getTitle()
+ " - is already bookmarked.";
return new CommandResult(feedback, false, false, false, false, true,
false, false);
return new CommandResult(feedback, false, false, false, false
);
} else {
// Update isBookmarked of question
Question bookmarkedQuestion = userSelection.withNewIsBookmarked(true);
Expand All @@ -57,8 +57,8 @@ public CommandResult execute() throws CommandException {

// Notify user of successful bookmark action
String feedback = "Bookmarked question " + (index + 1) + " : " + bookmarkedQuestion.getTitle();
return new CommandResult(feedback, false, false, false, false, true,
false, false);
return new CommandResult(feedback, false, false, false, false
);
}

} catch (IndexOutOfBoundsException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public CommandResult execute() throws CommandException {
String feedback = "List all questions that contains the corresponding"
+ " keywords as long as they appear in title, topics, description,"
+ " status or difficulty.";
return new CommandResult(feedback, false, false, false, false, false,
false, false);
return new CommandResult(feedback, false, false, false, false
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public CommandResult execute() {
}

return new CommandResult("Exiting application...", false,
true, false, false, false, false, false);
true, false, false);
}

private void saveQuestion(Question oldQuestion, Question newQuestion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public CommandResult execute() throws CommandException {
logger.info("Listing questions that contains keywords specified.");
String feedback = "List all questions that contains the corresponding"
+ " keywords.";
return new CommandResult(feedback, false, false, false, false, false,
false, false);
return new CommandResult(feedback, false, false, false, false
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public CommandResult execute() {
}

return new CommandResult("Returning to home page...", false,
false, true, false, false, false, false);
false, true, false);
}

private void saveQuestion(Question oldQuestion, Question newQuestion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public CommandResult execute() {
this.questionsLogic.filterQuestionsList(allQuestions);
logger.info("Listing all questions...");
String feedback = "List all questions...";
return new CommandResult(feedback, false, false, false, false, false,
false, false);
return new CommandResult(feedback, false, false, false, false
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public CommandResult execute() throws CommandException {
if (questionList.size() == 0) {
feedback = "Sorry. Couldn't manage to load any new questions.";
}
return new CommandResult(feedback, false, false, false, false, false,
false, false);
return new CommandResult(feedback, false, false, false, false
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ public CommandResult execute() throws CommandException {
if (isSuccessful) {
Question successfulQuestion = questionWithNewProgram.withNewStatus(Status.PASSED);
this.questionsLogic.replaceQuestion(questionWithNewProgram, successfulQuestion);
} else {
Question failedQuestion = questionWithNewProgram.withNewStatus(Status.ATTEMPTED);
this.questionsLogic.replaceQuestion(questionWithNewProgram, failedQuestion);
}

// Give user feedback
Expand All @@ -90,7 +87,7 @@ public CommandResult execute() throws CommandException {
} else {
feedback = feedback + "failed";
}
return new CommandResult(feedback, false, false, false, false, false,
false, true);
return new CommandResult(feedback, false, false, false, false
);
}
}

0 comments on commit 89455c8

Please sign in to comment.