Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat all Java source files according to style guide #15

Merged
merged 1 commit into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
/out/
/*.iml

# VSCode setting files
.vscode/

# Gradle build files
/.gradle/
/build/
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void run() {
Command command = parser.parseCommand(inputText);
command.execute(flashcardList, ui);
}

public static void main() {
new Main().run();
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* A type of command that will instruct to add a new element into the ArrayList
* of flashcards.
*/
public class AddCommand extends Command{
public class AddCommand extends Command {
String questionText;
String answerText;

Expand All @@ -23,8 +23,8 @@ public String toString() {

@Override
public void execute(FlashcardList flashcardList, Ui display) {
flashcardList.addNewFlashcard(questionText,answerText);
display.printSuccessfulAddMessage(questionText,answerText);
flashcardList.addNewFlashcard(questionText, answerText);
display.printSuccessfulAddMessage(questionText, answerText);
}

}
2 changes: 1 addition & 1 deletion src/main/java/commands/UnknownCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import objects.FlashcardList;
import ui.Ui;

public class UnknownCommand extends Command{
public class UnknownCommand extends Command {
@Override
public void execute(FlashcardList flashcardList, Ui display) {
display.printInvalidInput();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/objects/FlashcardList.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public FlashcardList() {
}

public void addNewFlashcard(String questionText, String answerText) {
Flashcard newFlashcard = new Flashcard(questionText,answerText);
Flashcard newFlashcard = new Flashcard(questionText, answerText);
flashcards.add(newFlashcard);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package objects.exceptions;

public class EmptyFlashcardAnswerException extends Exception{
public class EmptyFlashcardAnswerException extends Exception {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package objects.exceptions;

public class EmptyFlashcardQuestionException extends Exception{
public class EmptyFlashcardQuestionException extends Exception {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package objects.exceptions;

public class InvalidAddFlashcardInputException extends Exception{
public class InvalidAddFlashcardInputException extends Exception {
}
1 change: 0 additions & 1 deletion src/main/java/objects/flashcard/Flashcard.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package objects.flashcard;


public class Flashcard {
private String questionText;
private String answerText;
Expand Down
32 changes: 20 additions & 12 deletions src/main/java/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
public class Parser {
public static final String QUESTION_START_INDICATOR = "/q";
public static final String ANSWER_START_INDICATOR = "/a";

public Command parseCommand(String userInput) {
String commandPhrase = userInput.split(" ")[0];
switch (commandPhrase) {
case "add":
try {
return reformatAddCommandInput(userInput);
} catch (InvalidAddFlashcardInputException e) {
System.out.println("The input is in an incorrect format, please follow the format in user guide");
System.out.println(
"The input is in an incorrect format, please follow the format in user guide");
} catch (EmptyFlashcardQuestionException e) {
System.out.println("The question of this card is empty, please enter one.");
} catch (EmptyFlashcardAnswerException e) {
Expand All @@ -31,14 +33,18 @@ public Command parseCommand(String userInput) {
}

/**
* Constructs an AddCommand from the input of the user, if the input is of an incorrect
* format, a respective exception will be thrown.
* Constructs an AddCommand from the input of the user, if the input is of an
* incorrect format, a respective exception will be thrown.
*
* @param userInput The input collected by Ui from the user.
* @return An AddCommand with the question and answer text extracted from user input.
* @throws InvalidAddFlashcardInputException If the start indicators cannot be found.
* @throws EmptyFlashcardQuestionException If the string is empty after QUESTION_START_INDICATOR.
* @throws EmptyFlashcardAnswerException If the string is empty after ANSWER_START_INDICATOR.
* @return An AddCommand with the question and answer text extracted from user
* input.
* @throws InvalidAddFlashcardInputException If the start indicators cannot be
* found.
* @throws EmptyFlashcardQuestionException If the string is empty after
* QUESTION_START_INDICATOR.
* @throws EmptyFlashcardAnswerException If the string is empty after
* ANSWER_START_INDICATOR.
*/
public AddCommand reformatAddCommandInput(String userInput)
throws InvalidAddFlashcardInputException, EmptyFlashcardQuestionException,
Expand All @@ -48,16 +54,18 @@ public AddCommand reformatAddCommandInput(String userInput)
if (positionOfStartOfAnswer == -1 || positionOfStartOfQuestion == -1) {
throw new InvalidAddFlashcardInputException();
}
String questionText = userInput.substring(positionOfStartOfQuestion +
QUESTION_START_INDICATOR.length(), positionOfStartOfAnswer).trim();
String answerText = userInput.substring(positionOfStartOfAnswer +
ANSWER_START_INDICATOR.length()).trim();
String questionText = userInput
.substring(positionOfStartOfQuestion + QUESTION_START_INDICATOR.length(),
positionOfStartOfAnswer)
.trim();
String answerText = userInput
.substring(positionOfStartOfAnswer + ANSWER_START_INDICATOR.length()).trim();
if (questionText.isEmpty()) {
throw new EmptyFlashcardQuestionException();
}
if (answerText.isEmpty()) {
throw new EmptyFlashcardAnswerException();
}
return new AddCommand(questionText,answerText);
return new AddCommand(questionText, answerText);
}
}
6 changes: 2 additions & 4 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ public class Duke {
* Main entry-point for the java.duke.Duke application.
*/
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println("What is your name?");
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ public Ui(InputStream in, PrintStream out) {
}

/**
* Prompts for the command and reads the text entered by the user.
* Ignores empty, pure whitespace, and comment lines.
* Echos the command back to the user.
* Prompts for the command and reads the text entered by the user. Ignores
* empty, pure whitespace, and comment lines. Echos the command back to the
* user.
*
* @return command (full line) entered by the user
*/
public String getUserCommand() {
return in.nextLine();
}

public void printSuccessfulAddMessage(String questionText, String answerText) {
System.out.println("A new card is now added:" + System.lineSeparator() +
"Question: " + questionText + System.lineSeparator() +
"Answer: " + answerText);
System.out.println("A new card is now added:" + System.lineSeparator() + "Question: "
+ questionText + System.lineSeparator() + "Answer: " + answerText);
}

public void printInvalidInput() {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/objects/flashcard/FlashcardTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

package objects.flashcard;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;


class FlashcardTest {
@Test
public void constructNewFlashcard_correctlyFormattedInputs_success() {
Flashcard testCard = new Flashcard("QUESTION","ANSWER");
Flashcard testCard = new Flashcard("QUESTION", "ANSWER");
assertEquals("QUESTION", testCard.getQuestionText());
assertEquals("ANSWER", testCard.getAnswerText());
}
Expand Down
1 change: 0 additions & 1 deletion src/test/java/parser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;


class ParserTest {
@Test
public void parseAddCommand_correctlyFormattedInput_successful() {
Expand Down