changed TextLogik.java error handling

This commit is contained in:
schrom01 2021-11-11 21:59:47 +01:00
parent 13cbaba268
commit 9874bf4129
2 changed files with 9 additions and 11 deletions

View File

@ -25,9 +25,6 @@ public class Text {
* @return returns true if the given paragraph exists and is added successfully
*/
public boolean add(int paragraphNumber, String text) {
if(text.length() < 1) {
return false;
}
if (paragraphExists(paragraphNumber)) {
this.text.add((paragraphNumber - 1), text);
return true;
@ -42,9 +39,6 @@ public class Text {
* @return returns true if the paragraph is added successfully
*/
public boolean add(String text) {
if(text.length() < 1) {
return false;
}
this.text.add(text.replaceAll("[^A-Za-z0-9 .,:?!\"'-]",""));
return true;
}

View File

@ -12,21 +12,25 @@ public class TextLogik {
textOutput = new TextOutput();
String[] command;
textOutput.userInfoOutput("######################");
textOutput.userInfoOutput("#######################");
textOutput.userInfoOutput("#WELCOME TO THE EDITOR#");
textOutput.userInfoOutput("######################");
textOutput.userInfoOutput("#######################");
do {
textOutput.userInfoOutput("Please enter a Command: ");
command = TextInput.checkForInput();
switch (command[0]) {
case "ADD":
String inputText = "";
while(inputText.length() == 0) {
textOutput.userInfoOutput("Please enter your text: ");
inputText = TextInput.getTextInput();
}
if (command.length == 1) {
checkIfSuccess(text.add(TextInput.getTextInput()));
checkIfSuccess(text.add(inputText));
} else if (isNumeric(command[1])) {
int line = Integer.parseInt(command[1]);
checkIfSuccess(text.add(line, TextInput.getTextInput()));
checkIfSuccess(text.add(line, inputText));
} else {
textOutput.errorInvalidCommand();
}