forked from hummel/PR1-Spreadsheet
parent
f922de14d2
commit
a882441dd3
|
@ -46,6 +46,12 @@ public class Axel {
|
||||||
|
|
||||||
|
|
||||||
//? User input for a program command or a position
|
//? User input for a program command or a position
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prompts the user to input a command for the program or a position.
|
||||||
|
* May be called multiple times, if the input is faulty.
|
||||||
|
* @return The user inputted position or command as a string.
|
||||||
|
*/
|
||||||
public static String userCommandPositionInput() {
|
public static String userCommandPositionInput() {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("Input a command for the program or a position");
|
System.out.println("Input a command for the program or a position");
|
||||||
|
@ -56,6 +62,14 @@ public class Axel {
|
||||||
return userCommandPositionComputation(userCommandPositionInput);
|
return userCommandPositionComputation(userCommandPositionInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First method in the error check chain for the user input for a command or a position.
|
||||||
|
* This method may call userCommandPositionInput() again, if the input is faulty.
|
||||||
|
* Checks if the input is empty and if not decides if the input is a command or a position.
|
||||||
|
* Calls different methods to check for different errors.
|
||||||
|
* @param userCommandPositionInput The user inputted position or command as a string.
|
||||||
|
* @return The user inputted position or command as a string.
|
||||||
|
*/
|
||||||
public static String userCommandPositionComputation(String userCommandPositionInput) {
|
public static String userCommandPositionComputation(String userCommandPositionInput) {
|
||||||
|
|
||||||
if (userCommandPositionInput.isEmpty()) {
|
if (userCommandPositionInput.isEmpty()) {
|
||||||
|
@ -86,6 +100,13 @@ public class Axel {
|
||||||
return userCommandPositionInput;
|
return userCommandPositionInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the user inputted command is valid.
|
||||||
|
* Simply checks if the input equals one of the program commands.
|
||||||
|
* Case does not matter.
|
||||||
|
* @param CommandToCheck The user inputted command as a string.
|
||||||
|
* @return true if the command is valid, false otherwise.
|
||||||
|
*/
|
||||||
public static boolean userCommandErrorCheck(String CommandToCheck) {
|
public static boolean userCommandErrorCheck(String CommandToCheck) {
|
||||||
//? true if valid
|
//? true if valid
|
||||||
//? valid inputs are: *clear, *exit, *save, *load, *help (and all upper case variants)
|
//? valid inputs are: *clear, *exit, *save, *load, *help (and all upper case variants)
|
||||||
|
@ -97,6 +118,14 @@ public class Axel {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the user inputted position is valid.
|
||||||
|
* Checks if the input is the right length and if it is in the right format.
|
||||||
|
* Case does not matter.
|
||||||
|
* @param positionToCheck The user inputted position as a string.
|
||||||
|
* @param spr The spreadsheet object. (This input is needed for tests)
|
||||||
|
* @return true if the position is valid, false otherwise.
|
||||||
|
*/
|
||||||
public static boolean userPositionErrorCheck(String positionToCheck, Spreadsheet spr) {
|
public static boolean userPositionErrorCheck(String positionToCheck, Spreadsheet spr) {
|
||||||
//? true if valid
|
//? true if valid
|
||||||
//? valid inputs are: A1, B14, C79, E99, F1, G99, J1, M98, ... (and all lower case variants)
|
//? valid inputs are: A1, B14, C79, E99, F1, G99, J1, M98, ... (and all lower case variants)
|
||||||
|
@ -122,6 +151,13 @@ public class Axel {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the user inputted position is in the bounds of the spreadsheet.
|
||||||
|
* Case does not matter.
|
||||||
|
* @param positionToCheck The user inputted position as a string.
|
||||||
|
* @param spr The spreadsheet object. (This input is needed for tests)
|
||||||
|
* @return true if the position is in the bounds, false otherwise.
|
||||||
|
*/
|
||||||
public static boolean userPositionBoundsErrorCheck(String positionToCheck, Spreadsheet spr) {
|
public static boolean userPositionBoundsErrorCheck(String positionToCheck, Spreadsheet spr) {
|
||||||
//? true if valid
|
//? true if valid
|
||||||
|
|
||||||
|
@ -136,6 +172,13 @@ public class Axel {
|
||||||
|
|
||||||
|
|
||||||
//? User input for a value or a formula
|
//? User input for a value or a formula
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prompts the user to input a value or a formula for the selected position.
|
||||||
|
* May be called multiple times, if the input is faulty.
|
||||||
|
* @param currentPos The position the user is currently inputting a value or a formula for.
|
||||||
|
* @return The user inputted value or formula as a string.
|
||||||
|
*/
|
||||||
public static String userValueFormulaInput(String currentPos) {
|
public static String userValueFormulaInput(String currentPos) {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.printf("Input a value of a formula for the selected position: %s.%n", currentPos);
|
System.out.printf("Input a value of a formula for the selected position: %s.%n", currentPos);
|
||||||
|
@ -146,6 +189,15 @@ public class Axel {
|
||||||
return userValueFormulaComputation(userCommandInput, currentPos);
|
return userValueFormulaComputation(userCommandInput, currentPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First method in the error check chain for the user input for a value or a formula.
|
||||||
|
* This method may call userValueFormulaInput() again, if the input is faulty.
|
||||||
|
* Checks if the input is empty and if not decides if the input is a value or a formula.
|
||||||
|
* Calls different methods to check for different errors.
|
||||||
|
* @param userValueFormulaInput The user inputted value or formula as a string.
|
||||||
|
* @param currentPos The position the user is currently inputting a value or a formula for.
|
||||||
|
* @return The user inputted value or formula as a string.
|
||||||
|
*/
|
||||||
public static String userValueFormulaComputation(String userValueFormulaInput, String currentPos) {
|
public static String userValueFormulaComputation(String userValueFormulaInput, String currentPos) {
|
||||||
if (userValueFormulaInput.isEmpty()) {
|
if (userValueFormulaInput.isEmpty()) {
|
||||||
System.out.println("Input is empty!");
|
System.out.println("Input is empty!");
|
||||||
|
@ -170,6 +222,15 @@ public class Axel {
|
||||||
return userValueFormulaInput;
|
return userValueFormulaInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the user inputted formula is a function or expression.
|
||||||
|
* Removes the '=' at the beginning.
|
||||||
|
* To decide if a formula is a function, it simply checks if the formula starts with one of the function names.
|
||||||
|
* Calls different methods to check for different errors.
|
||||||
|
* Case does not matter.
|
||||||
|
* @param formulaToCheck The user inputted formula as a string.
|
||||||
|
* @return true if the formula is valid, false otherwise.
|
||||||
|
*/
|
||||||
public static boolean userFormulaErrorCheck(String formulaToCheck) {
|
public static boolean userFormulaErrorCheck(String formulaToCheck) {
|
||||||
//? true if valid
|
//? true if valid
|
||||||
//? valid inputs are: =7*6, =SUM(A1:A3), =A1, =A1+A2, =A1-A2, ... (and all lower case variants)
|
//? valid inputs are: =7*6, =SUM(A1:A3), =A1, =A1+A2, =A1-A2, ... (and all lower case variants)
|
||||||
|
@ -184,6 +245,13 @@ public class Axel {
|
||||||
return userFormulaExpressionErrorCheck(formulaToCheck);
|
return userFormulaExpressionErrorCheck(formulaToCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks a function formula for errors.
|
||||||
|
* Checks if the formula is in the right format and if the cells in the formula are in the bounds of the spreadsheet.
|
||||||
|
* Checks for some special cases for different functions.
|
||||||
|
* @param functionToCheck The user inputted formula as a string.
|
||||||
|
* @return true if the formula is valid, false otherwise.
|
||||||
|
*/
|
||||||
public static boolean userFormulaFunctionErrorCheck(String functionToCheck) {
|
public static boolean userFormulaFunctionErrorCheck(String functionToCheck) {
|
||||||
String[] functionCorners = spr.isolateFunctionCorners(functionToCheck);
|
String[] functionCorners = spr.isolateFunctionCorners(functionToCheck);
|
||||||
|
|
||||||
|
@ -227,11 +295,23 @@ public class Axel {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks an expression formula for errors.
|
||||||
|
* To be done in the future.
|
||||||
|
* @param expressionToCheck The user inputted expression formula as a string.
|
||||||
|
* @return true if the formula is valid, false otherwise.
|
||||||
|
*/
|
||||||
public static boolean userFormulaExpressionErrorCheck(String expressionToCheck) {
|
public static boolean userFormulaExpressionErrorCheck(String expressionToCheck) {
|
||||||
//TODO ME: Maybe not worth the time
|
//TODO ME
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the user inputted value is valid.
|
||||||
|
* Checks if the input is a positive or negative integer.
|
||||||
|
* @param valueToCheck The user inputted value as a string.
|
||||||
|
* @return true if the value is valid, false otherwise.
|
||||||
|
*/
|
||||||
public static boolean userValueErrorCheck(String valueToCheck) {
|
public static boolean userValueErrorCheck(String valueToCheck) {
|
||||||
//? true if valid
|
//? true if valid
|
||||||
//? valid inputs are: 7, 1337, 0, , -213,...
|
//? valid inputs are: 7, 1337, 0, , -213,...
|
||||||
|
@ -246,7 +326,12 @@ public class Axel {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a program command.
|
||||||
|
* @param command The user inputted command as a string.
|
||||||
|
* @return Nothing.
|
||||||
|
* @throws FileNotFoundException If the file to load or save to is not found.
|
||||||
|
*/
|
||||||
public static void executeCommand(String command) throws FileNotFoundException {
|
public static void executeCommand(String command) throws FileNotFoundException {
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "*clear":
|
case "*clear":
|
||||||
|
@ -267,6 +352,10 @@ public class Axel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the program command to clear the table.
|
||||||
|
* @return Nothing.
|
||||||
|
*/
|
||||||
private static void progClear(){
|
private static void progClear(){
|
||||||
System.out.println("Are you sure you want to clear the table? (yes/no)");
|
System.out.println("Are you sure you want to clear the table? (yes/no)");
|
||||||
System.out.print("Input: ");
|
System.out.print("Input: ");
|
||||||
|
@ -278,17 +367,33 @@ public class Axel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the program command to load a table from a csv file.
|
||||||
|
* @return Nothing.
|
||||||
|
* @throws FileNotFoundException If the file to load is not found.
|
||||||
|
*/
|
||||||
private static void progLoad() throws FileNotFoundException {
|
private static void progLoad() throws FileNotFoundException {
|
||||||
spr.readCsv(saveFilePath, ",", "Amogus");
|
spr.readCsv(saveFilePath, ",", "Amogus");
|
||||||
System.out.println("File loaded!");
|
System.out.println("File loaded!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the program command to save the table to a csv file.
|
||||||
|
* @return Nothing.
|
||||||
|
* @throws FileNotFoundException If the file to save to is not found.
|
||||||
|
*/
|
||||||
private static void progSave() throws FileNotFoundException {
|
private static void progSave() throws FileNotFoundException {
|
||||||
String savePath = saveFilePath;
|
String savePath = saveFilePath;
|
||||||
spr.saveCsv(savePath);
|
spr.saveCsv(savePath);
|
||||||
System.out.println("File saved");
|
System.out.println("File saved");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the program command to exit the program and asks the user to save the table.
|
||||||
|
* Case does not matter.
|
||||||
|
* @return Nothing.
|
||||||
|
* @throws FileNotFoundException If the file to save to is not found.
|
||||||
|
*/
|
||||||
private static void progExit() throws FileNotFoundException {
|
private static void progExit() throws FileNotFoundException {
|
||||||
System.out.println("Do you want to save befor you exit? (yes/no)");
|
System.out.println("Do you want to save befor you exit? (yes/no)");
|
||||||
System.out.print("Input: ");
|
System.out.print("Input: ");
|
||||||
|
|
Loading…
Reference in New Issue