From b6cb9f7973e81fd0737fbd6547a3fa73f73ea1d7 Mon Sep 17 00:00:00 2001 From: Reid Campolong Date: Tue, 24 Sep 2019 16:01:13 -0400 Subject: [PATCH 1/9] Setup basic architecture for application --- src/Application.java | 9 +++++++++ src/parser/VoiceParser.java | 5 +++++ src/parser/components/Keyboard.java | 4 ++++ 3 files changed, 18 insertions(+) create mode 100644 src/Application.java create mode 100644 src/parser/VoiceParser.java create mode 100644 src/parser/components/Keyboard.java diff --git a/src/Application.java b/src/Application.java new file mode 100644 index 0000000..22b36f0 --- /dev/null +++ b/src/Application.java @@ -0,0 +1,9 @@ +import parser.VoiceParser; + +public class Application { + + public static void main(String[] args) { + VoiceParser parser = new VoiceParser(); + } + +} diff --git a/src/parser/VoiceParser.java b/src/parser/VoiceParser.java new file mode 100644 index 0000000..f73d327 --- /dev/null +++ b/src/parser/VoiceParser.java @@ -0,0 +1,5 @@ +package parser; + +public class VoiceParser { + +} diff --git a/src/parser/components/Keyboard.java b/src/parser/components/Keyboard.java new file mode 100644 index 0000000..befb3d9 --- /dev/null +++ b/src/parser/components/Keyboard.java @@ -0,0 +1,4 @@ +package parser.components; + +public class Keyboard { +} From 18e96dbf51b976d363a5be4b5d47495ff36a9e94 Mon Sep 17 00:00:00 2001 From: Reid Campolong Date: Tue, 24 Sep 2019 16:51:10 -0400 Subject: [PATCH 2/9] Added basic modules and read in file input --- input.txt | 2 ++ src/Application.java | 16 ++++++++++++++++ src/InputReader.java | 23 +++++++++++++++++++++++ src/parser/VoiceParser.java | 3 +++ 4 files changed, 44 insertions(+) create mode 100644 input.txt create mode 100644 src/InputReader.java diff --git a/input.txt b/input.txt new file mode 100644 index 0000000..f7c69a8 --- /dev/null +++ b/input.txt @@ -0,0 +1,2 @@ +IT Crowd +Input Test \ No newline at end of file diff --git a/src/Application.java b/src/Application.java index 22b36f0..619eef0 100644 --- a/src/Application.java +++ b/src/Application.java @@ -1,9 +1,25 @@ import parser.VoiceParser; +import java.io.FileNotFoundException; +import java.util.List; + public class Application { public static void main(String[] args) { + + List inputFileLines; + try { + inputFileLines = InputReader.getLinesFromFile("input.txt"); + } catch (FileNotFoundException e) { + System.out.println("Could not find that file!"); + return; + } + VoiceParser parser = new VoiceParser(); + for(String line : inputFileLines) { + String output = parser.parseDirections(line); + System.out.println(line + ": " + output); + } } } diff --git a/src/InputReader.java b/src/InputReader.java new file mode 100644 index 0000000..6eb9cf1 --- /dev/null +++ b/src/InputReader.java @@ -0,0 +1,23 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class InputReader { + + public static List getLinesFromFile(String fileName) throws FileNotFoundException { + File file = new File(fileName); + Scanner scanner = new Scanner(file); + + List fileLines = new ArrayList<>(); + + while(scanner.hasNext()) { + fileLines.add(scanner.nextLine()); + } + + scanner.close(); + return fileLines; + } + +} diff --git a/src/parser/VoiceParser.java b/src/parser/VoiceParser.java index f73d327..2c45133 100644 --- a/src/parser/VoiceParser.java +++ b/src/parser/VoiceParser.java @@ -2,4 +2,7 @@ public class VoiceParser { + public String parseDirections(String line) { + + } } From ae5283c271e0f4a453fd03d8bf2067fa01cbafd4 Mon Sep 17 00:00:00 2001 From: Reid Campolong Date: Tue, 24 Sep 2019 19:35:44 -0400 Subject: [PATCH 3/9] Added parsing of directions for characters --- src/Application.java | 2 +- src/parser/VoiceParser.java | 15 +++++- src/parser/components/Keyboard.java | 75 +++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) diff --git a/src/Application.java b/src/Application.java index 619eef0..3f944a2 100644 --- a/src/Application.java +++ b/src/Application.java @@ -17,7 +17,7 @@ public static void main(String[] args) { VoiceParser parser = new VoiceParser(); for(String line : inputFileLines) { - String output = parser.parseDirections(line); + String output = parser.parseDirectionsForPhrase(line); System.out.println(line + ": " + output); } } diff --git a/src/parser/VoiceParser.java b/src/parser/VoiceParser.java index 2c45133..642d0b0 100644 --- a/src/parser/VoiceParser.java +++ b/src/parser/VoiceParser.java @@ -1,8 +1,21 @@ package parser; +import parser.components.Keyboard; + public class VoiceParser { - public String parseDirections(String line) { + private Keyboard keyboard; + + public VoiceParser() { + this.keyboard = new Keyboard(); + } + + public String parseDirectionsForPhrase(String line) { + return ""; + } + + private String getDirectionsForCharacter(char c) { + return keyboard.processCharacter(c); } } diff --git a/src/parser/components/Keyboard.java b/src/parser/components/Keyboard.java index befb3d9..1c5c4e3 100644 --- a/src/parser/components/Keyboard.java +++ b/src/parser/components/Keyboard.java @@ -1,4 +1,79 @@ package parser.components; public class Keyboard { + + private int cursorRow, cursorCol; + private char[][] keyboard; + + public Keyboard() { + initializeKeyboard(); + } + + private void initializeKeyboard() { + this.cursorRow = 0; + this.cursorCol = 0; + this.keyboard = new char[][] { + {'A', 'B', 'C', 'D', 'E', 'F'}, + {'G', 'H', 'I', 'J', 'K', 'L'}, + {'M', 'N', 'O', 'P', 'Q', 'R'}, + {'S', 'T', 'U', 'V', 'W', 'X'}, + {'Y', 'Z', '1', '2', '3', '4'}, + {'5', '6', '7', '8', '9', '0'}, + }; + } + + public String processCharacter(char command) { + if(command == ' ') + return "S,"; + + command = mapCommandToKeyboard(command); + + // Determine left/right + int cursorXPosition = (getCurrentCharacter() - 65) % 6; + int commandXPosition = (command - 65) % 6; + int colDistance = commandXPosition - cursorXPosition; + + String colCharacter = (colDistance > 0) ? "R" : "L"; + moveCursor(0, colDistance); + + // Determine up/down + int rowDistance = (command - getCurrentCharacter()) / 6; + String rowCharacter = (rowDistance > 0) ? "D" : "U"; + moveCursor(rowDistance, 0); + + // Parse string + String outputCommand = ""; + for (int i = 0; i < Math.abs(rowDistance); i++) + outputCommand += rowCharacter + ","; + for (int i = 0; i < Math.abs(colDistance); i++) + outputCommand += colCharacter + ","; + + outputCommand += "#"; + return outputCommand; + } + + /** + * Convert a letter to upper case or digit to map after Z + * @param c + * @return + */ + private char mapCommandToKeyboard(char c) { + return (Character.isDigit(c) ? mapDigitToKeyboard(c) : Character.toUpperCase(c)); + } + + private char mapDigitToKeyboard(char c) { + return (char) (c + 42); + } + + private void moveCursor(int rowOffset, int colOffset) { + this.cursorRow += rowOffset; + this.cursorCol += colOffset; + } + + private char getCurrentCharacter() { + char c = this.keyboard[cursorRow][cursorCol]; + if(Character.isDigit(c)) + return mapDigitToKeyboard(c); + return c; + } } From df113a5f3c06b16e9d99acf523bc94b6205fba38 Mon Sep 17 00:00:00 2001 From: Reid Campolong Date: Tue, 24 Sep 2019 19:46:58 -0400 Subject: [PATCH 4/9] Added documentation and error handling --- src/parser/VoiceParser.java | 5 ++++- src/parser/components/Keyboard.java | 30 +++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/parser/VoiceParser.java b/src/parser/VoiceParser.java index 642d0b0..120840f 100644 --- a/src/parser/VoiceParser.java +++ b/src/parser/VoiceParser.java @@ -11,7 +11,10 @@ public VoiceParser() { } public String parseDirectionsForPhrase(String line) { - return ""; + String outputCommand = ""; + for(char c : line.toCharArray()) + outputCommand += getDirectionsForCharacter(c) + ","; + return outputCommand; } diff --git a/src/parser/components/Keyboard.java b/src/parser/components/Keyboard.java index 1c5c4e3..cc15f50 100644 --- a/src/parser/components/Keyboard.java +++ b/src/parser/components/Keyboard.java @@ -22,11 +22,19 @@ private void initializeKeyboard() { }; } + private boolean isValidCharacter(char command) { + return (65 <= command && command <= 101); + } + public String processCharacter(char command) { if(command == ' ') - return "S,"; + return "S"; command = mapCommandToKeyboard(command); + if(!isValidCharacter(command)) { + System.out.println("INVALID COMMAND ENTERED!"); + System.exit(0); + } // Determine left/right int cursorXPosition = (getCurrentCharacter() - 65) % 6; @@ -53,7 +61,7 @@ public String processCharacter(char command) { } /** - * Convert a letter to upper case or digit to map after Z + * Determine whether to convert a letter to upper case or digit to map it after Z * @param c * @return */ @@ -61,15 +69,33 @@ private char mapCommandToKeyboard(char c) { return (Character.isDigit(c) ? mapDigitToKeyboard(c) : Character.toUpperCase(c)); } + /** + * Fits 0-9 into our array after Z by using our own ASCII + * @param c + * @return + */ private char mapDigitToKeyboard(char c) { + // 0 Needs to come after 9 + if (c == '0') + c += 9; return (char) (c + 42); } + /** + * Moves cursor for keyboard + * @param rowOffset + * @param colOffset + */ private void moveCursor(int rowOffset, int colOffset) { this.cursorRow += rowOffset; this.cursorCol += colOffset; } + /** + * Gets current character at the cursor. + * If it's a digit, map it to our custom ascii + * @return + */ private char getCurrentCharacter() { char c = this.keyboard[cursorRow][cursorCol]; if(Character.isDigit(c)) From 0e6d7783907022ddade7ad415552ccb113321e57 Mon Sep 17 00:00:00 2001 From: Reid Campolong Date: Tue, 24 Sep 2019 19:56:29 -0400 Subject: [PATCH 5/9] Read through all lines of file and show outputs --- model.png | Bin 0 -> 16348 bytes src/Application.java | 2 +- src/parser/VoiceParser.java | 13 ++++++++++++- src/parser/components/Keyboard.java | 20 ++++++++++++++++---- 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 model.png diff --git a/model.png b/model.png new file mode 100644 index 0000000000000000000000000000000000000000..07f248592ce3d307d37728d991fa958b18c74316 GIT binary patch literal 16348 zcmeHucT|&0*DoFrR0NI+C-f+Gkx)dCu3|)`NiPNv5do1BTBwPDfD)PoP^t#$y-7j> zC@58kp@kM&D4`^j&`ID1&UwFYz3Z;K?)|>MzIB&>WIfN!GkedTJ$v@-{hP_F`+8bD zM}&{Cv9a;oy>rWujg14z#>W2Q5UYZXLx483_i(tOdxMRwG?trTdyrK=X?Mp^myON; z92?v77i?@>tg7b}Ha2e=Hn!P^Y;4N!+1LQ?Db)t5tPg)Y($>1gwi^-qvyN3d?0(0> zlZ_2@dhd6@H&erhRmtUbR~O7hJ}d~3J@70N0%2oQ$KSnm!`OF#n%e#$U-|g;!=V>& z>1uh(l58%LaUiV{cj%=(K&fhQpRVA!>8gM52!luT!he@)>?V7&6tyf$M&p3Jp zhqXJ?7!!Ox%x#=UOX!X-tm#ga7<--bk&$1XZ(f*R3?FL#25!+T;Ma7W7)4E-GL1Z? z=;3a#{HNrPI1wfE1;3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IKsYp5!NTTsfQ#`lP)Ir}&9=SlC}FmPc|a*MoU z-?1)Ps_}_{@zJw`^xQl%{WsOUt4qc1eEtAAKVx9i*ZDj3Im^KfDm@`B$0~ zZP>Y}$~m4ZnFq|*nl~ic&TL(@eUFPCB%}ED*j)yw<>aJBD5vh${Ono|ec!V(EGO!r zv1JI}t&^&Q)G~amfSk7{RhO`-({;j-6$4hV1)M}d#l2tINF~~wU9VeL*=6g#26oP_ zdEu1o*}78aCozqHGc3(A5xL8!^U2HQ(gf*)KzG9VJ)ONnHdcP>QL6BRPAlX!q0rAM$nBcZjvb}Z&HOGtb$OUMfV9*>rU;9o9D`junArWSC! z{F=~i&|1I;H>>0?v50tAZ|nI1USlMZ@vNA8PN&LAXY~zd$ZeL*;5`hk@@h|=pl959 zbh|;v0e@S66)s(h1d(y`1TYDzbQSm8<&>w`XzNR6>;-GknhWBV0%*$HJ#!;~X7?TemL7Egs}TbF2t1;#YV{7^k}>8H>q$j#W&Ijz=E6TOW^$EKaOy(2QZQ-)vNIVrCC4g{kB2uaI+`-}n3gC5;p*m?Wj8D6^)f z3GK*CzE#z>h@UZR+%Z-b6Pw-m6iv_-sj_XGqe6HzlOMs|2MRS38@T=al5BEQU6-q2 zu?~`DW2YO$^|fEQ>bwKunJ!kbOyNVqe><3w&JnepYB+k#`{On-+m$$2#fm# z0-{e@rksm~-PG3;+skCsJ|&4$HsF+&+`V)L#nqU-RD~FNSNH5BLu@Z|@xOeb44Fw^LmbCyUxyfk^lYj z-&VpRV(`2Yvu6M{&HA_dSue1;*JE2Rdu2Nhd)9+ZPDWNqN=8XaPTpAVin6?tvW%>x ojEu633{Eqf=idli+#WkU@%uj$w2K2vSp;l%!FsofZaxh8U${^-X8-^I literal 0 HcmV?d00001 diff --git a/src/Application.java b/src/Application.java index 3f944a2..a7d59bf 100644 --- a/src/Application.java +++ b/src/Application.java @@ -9,7 +9,7 @@ public static void main(String[] args) { List inputFileLines; try { - inputFileLines = InputReader.getLinesFromFile("input.txt"); + inputFileLines = InputReader.getLinesFromFile(args[0]); } catch (FileNotFoundException e) { System.out.println("Could not find that file!"); return; diff --git a/src/parser/VoiceParser.java b/src/parser/VoiceParser.java index 120840f..878d278 100644 --- a/src/parser/VoiceParser.java +++ b/src/parser/VoiceParser.java @@ -10,14 +10,25 @@ public VoiceParser() { this.keyboard = new Keyboard(); } + /** + * Parses directions for an entire line + * @param line + * @return + */ public String parseDirectionsForPhrase(String line) { String outputCommand = ""; + + // Get directions for each character for(char c : line.toCharArray()) outputCommand += getDirectionsForCharacter(c) + ","; + + outputCommand = outputCommand.substring(0, outputCommand.length() - 1); + + // Reset cursor for future lines + keyboard.resetCursor(); return outputCommand; } - private String getDirectionsForCharacter(char c) { return keyboard.processCharacter(c); } diff --git a/src/parser/components/Keyboard.java b/src/parser/components/Keyboard.java index cc15f50..d27e637 100644 --- a/src/parser/components/Keyboard.java +++ b/src/parser/components/Keyboard.java @@ -10,8 +10,7 @@ public Keyboard() { } private void initializeKeyboard() { - this.cursorRow = 0; - this.cursorCol = 0; + this.resetCursor(); this.keyboard = new char[][] { {'A', 'B', 'C', 'D', 'E', 'F'}, {'G', 'H', 'I', 'J', 'K', 'L'}, @@ -26,6 +25,11 @@ private boolean isValidCharacter(char command) { return (65 <= command && command <= 101); } + /** + * Gets directions for a single character + * @param command + * @return + */ public String processCharacter(char command) { if(command == ' ') return "S"; @@ -61,7 +65,7 @@ public String processCharacter(char command) { } /** - * Determine whether to convert a letter to upper case or digit to map it after Z + * Determine whether to convert a letter to upper case or map a digit to our custom ascii * @param c * @return */ @@ -77,7 +81,7 @@ private char mapCommandToKeyboard(char c) { private char mapDigitToKeyboard(char c) { // 0 Needs to come after 9 if (c == '0') - c += 9; + c += 10; return (char) (c + 42); } @@ -102,4 +106,12 @@ private char getCurrentCharacter() { return mapDigitToKeyboard(c); return c; } + + /** + * Sets cursor to 0,0 + */ + public void resetCursor() { + this.cursorRow = 0; + this.cursorCol = 0; + } } From ef3e64651e5bc794e36058ee2608fac49abadad6 Mon Sep 17 00:00:00 2001 From: Reid Campolong Date: Tue, 24 Sep 2019 19:59:31 -0400 Subject: [PATCH 6/9] Improved documentation --- input.txt | 2 +- src/Application.java | 6 ++++++ src/parser/VoiceParser.java | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/input.txt b/input.txt index f7c69a8..ea7d8af 100644 --- a/input.txt +++ b/input.txt @@ -1,2 +1,2 @@ IT Crowd -Input Test \ No newline at end of file +SoftWriters \ No newline at end of file diff --git a/src/Application.java b/src/Application.java index a7d59bf..bf6e362 100644 --- a/src/Application.java +++ b/src/Application.java @@ -3,10 +3,14 @@ import java.io.FileNotFoundException; import java.util.List; +/** + * Combines input and parser module into one application + */ public class Application { public static void main(String[] args) { + // Get lines to translate List inputFileLines; try { inputFileLines = InputReader.getLinesFromFile(args[0]); @@ -16,6 +20,8 @@ public static void main(String[] args) { } VoiceParser parser = new VoiceParser(); + + // Translate every line for(String line : inputFileLines) { String output = parser.parseDirectionsForPhrase(line); System.out.println(line + ": " + output); diff --git a/src/parser/VoiceParser.java b/src/parser/VoiceParser.java index 878d278..426a6c3 100644 --- a/src/parser/VoiceParser.java +++ b/src/parser/VoiceParser.java @@ -2,6 +2,9 @@ import parser.components.Keyboard; +/** + * A module that can be used to translate phrases into DVR commands + */ public class VoiceParser { private Keyboard keyboard; From d178344d820117406609d60ff3ff90f88ec6f83d Mon Sep 17 00:00:00 2001 From: Reid Campolong Date: Tue, 24 Sep 2019 20:22:11 -0400 Subject: [PATCH 7/9] Updated documentation --- src/Application.java | 5 +++-- src/InputReader.java | 9 +++++++++ src/parser/components/Keyboard.java | 11 ++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Application.java b/src/Application.java index bf6e362..3ff7f81 100644 --- a/src/Application.java +++ b/src/Application.java @@ -4,7 +4,8 @@ import java.util.List; /** - * Combines input and parser module into one application + * Shows how to combine input and parser module into one application. + * Easily replacable with other parts of system. */ public class Application { @@ -21,7 +22,7 @@ public static void main(String[] args) { VoiceParser parser = new VoiceParser(); - // Translate every line + // Parse/Translate every line for(String line : inputFileLines) { String output = parser.parseDirectionsForPhrase(line); System.out.println(line + ": " + output); diff --git a/src/InputReader.java b/src/InputReader.java index 6eb9cf1..326c420 100644 --- a/src/InputReader.java +++ b/src/InputReader.java @@ -4,8 +4,17 @@ import java.util.List; import java.util.Scanner; +/** + * General utility module that allows for reading input from a file + */ public class InputReader { + /** + * Read in lines from a file name + * @param fileName + * @return + * @throws FileNotFoundException + */ public static List getLinesFromFile(String fileName) throws FileNotFoundException { File file = new File(fileName); Scanner scanner = new Scanner(file); diff --git a/src/parser/components/Keyboard.java b/src/parser/components/Keyboard.java index d27e637..548d59b 100644 --- a/src/parser/components/Keyboard.java +++ b/src/parser/components/Keyboard.java @@ -1,5 +1,9 @@ package parser.components; +/** + * Manages keyboard related information. Gives directions on how to + * move between characters via DVR commands. + */ public class Keyboard { private int cursorRow, cursorCol; @@ -21,6 +25,11 @@ private void initializeKeyboard() { }; } + /** + * Verify the command is A-Z or 0-9 in our custom ascii + * @param command + * @return + */ private boolean isValidCharacter(char command) { return (65 <= command && command <= 101); } @@ -79,7 +88,7 @@ private char mapCommandToKeyboard(char c) { * @return */ private char mapDigitToKeyboard(char c) { - // 0 Needs to come after 9 + // 0 Needs to be placed after 9 if (c == '0') c += 10; return (char) (c + 42); From fdf382641021117db8eba7ff00ef38fb5e302a15 Mon Sep 17 00:00:00 2001 From: Reid Campolong Date: Wed, 25 Sep 2019 01:05:20 -0400 Subject: [PATCH 8/9] Updated documentation for keyboard --- src/parser/VoiceParser.java | 25 ++++-- src/parser/components/Keyboard.java | 129 ++++++++++++++++------------ 2 files changed, 93 insertions(+), 61 deletions(-) diff --git a/src/parser/VoiceParser.java b/src/parser/VoiceParser.java index 426a6c3..5775d50 100644 --- a/src/parser/VoiceParser.java +++ b/src/parser/VoiceParser.java @@ -7,32 +7,41 @@ */ public class VoiceParser { + /** + * Keyboard to allow for translating text + */ private Keyboard keyboard; public VoiceParser() { this.keyboard = new Keyboard(); } + /** + * Parse directions for a single character + * @param c + * @return + */ + private String getDirectionsForCharacter(char c) { + return keyboard.processCharacter(c); + } + /** * Parses directions for an entire line - * @param line + * @param phrase * @return */ - public String parseDirectionsForPhrase(String line) { + public String parseDirectionsForPhrase(String phrase) { String outputCommand = ""; - // Get directions for each character - for(char c : line.toCharArray()) + // Get directions for each character in the phrase + for(char c : phrase.toCharArray()) outputCommand += getDirectionsForCharacter(c) + ","; outputCommand = outputCommand.substring(0, outputCommand.length() - 1); - // Reset cursor for future lines + // Reset cursor for future phrases keyboard.resetCursor(); return outputCommand; } - private String getDirectionsForCharacter(char c) { - return keyboard.processCharacter(c); - } } diff --git a/src/parser/components/Keyboard.java b/src/parser/components/Keyboard.java index 548d59b..aa34fd3 100644 --- a/src/parser/components/Keyboard.java +++ b/src/parser/components/Keyboard.java @@ -3,6 +3,10 @@ /** * Manages keyboard related information. Gives directions on how to * move between characters via DVR commands. + * + * The keyboard is a 2D Array of characters with a cursor pointed + * at the current character. + * */ public class Keyboard { @@ -11,10 +15,14 @@ public class Keyboard { public Keyboard() { initializeKeyboard(); + resetCursor(); } + /** + * Initializes keyboard's values + * + */ private void initializeKeyboard() { - this.resetCursor(); this.keyboard = new char[][] { {'A', 'B', 'C', 'D', 'E', 'F'}, {'G', 'H', 'I', 'J', 'K', 'L'}, @@ -26,7 +34,66 @@ private void initializeKeyboard() { } /** - * Verify the command is A-Z or 0-9 in our custom ascii + * Moves cursor for keyboard + * @param rowOffset + * @param colOffset + */ + private void moveCursor(int rowOffset, int colOffset) { + this.cursorRow += rowOffset; + this.cursorCol += colOffset; + } + + /** + * Used to place 0-9 into our keyboard after Z + * + * To search for a digit, we modify the digit's ASCII value to appear + * after the Z in our keyboard. + * + * @param c + * @return + */ + private char mapDigitToKeyboard(char c) { + if (c == '0') + // '0' Needs to be placed after '9' + c += 10; + + return (char) (c + 42); + } + + /** + * Convert the character to an ASCII format searchable by our keyboard + * @param c + * @return + */ + private char mapCommandToKeyboard(char c) { + return (Character.isDigit(c) ? mapDigitToKeyboard(c) : Character.toUpperCase(c)); + } + + /** + * Gets current character at the cursor. + * + * If it's a digit, map it to our ascii format above to allow + * for searching. + * + * @return + */ + private char getCurrentCharacter() { + char c = this.keyboard[cursorRow][cursorCol]; + if(Character.isDigit(c)) + return mapDigitToKeyboard(c); + return c; + } + + /** + * Sets cursor to row = 0 col = 0 + */ + public void resetCursor() { + this.cursorRow = 0; + this.cursorCol = 0; + } + + /** + * Verify the command is A-Z or 0-9 and in our keyboard * @param command * @return */ @@ -36,6 +103,11 @@ private boolean isValidCharacter(char command) { /** * Gets directions for a single character + * + * To search for a letter, we compare the ASCII value of the letter + * with the ASCII values in our keyboard to mathematically determine + * the path. + * * @param command * @return */ @@ -45,7 +117,7 @@ public String processCharacter(char command) { command = mapCommandToKeyboard(command); if(!isValidCharacter(command)) { - System.out.println("INVALID COMMAND ENTERED!"); + System.out.println("Invalid command received. Exiting..."); System.exit(0); } @@ -62,7 +134,7 @@ public String processCharacter(char command) { String rowCharacter = (rowDistance > 0) ? "D" : "U"; moveCursor(rowDistance, 0); - // Parse string + // Output directions string String outputCommand = ""; for (int i = 0; i < Math.abs(rowDistance); i++) outputCommand += rowCharacter + ","; @@ -73,54 +145,5 @@ public String processCharacter(char command) { return outputCommand; } - /** - * Determine whether to convert a letter to upper case or map a digit to our custom ascii - * @param c - * @return - */ - private char mapCommandToKeyboard(char c) { - return (Character.isDigit(c) ? mapDigitToKeyboard(c) : Character.toUpperCase(c)); - } - - /** - * Fits 0-9 into our array after Z by using our own ASCII - * @param c - * @return - */ - private char mapDigitToKeyboard(char c) { - // 0 Needs to be placed after 9 - if (c == '0') - c += 10; - return (char) (c + 42); - } - - /** - * Moves cursor for keyboard - * @param rowOffset - * @param colOffset - */ - private void moveCursor(int rowOffset, int colOffset) { - this.cursorRow += rowOffset; - this.cursorCol += colOffset; - } - - /** - * Gets current character at the cursor. - * If it's a digit, map it to our custom ascii - * @return - */ - private char getCurrentCharacter() { - char c = this.keyboard[cursorRow][cursorCol]; - if(Character.isDigit(c)) - return mapDigitToKeyboard(c); - return c; - } - /** - * Sets cursor to 0,0 - */ - public void resetCursor() { - this.cursorRow = 0; - this.cursorCol = 0; - } } From 416a6f4e8c4a8a7f6188965e9210c672acd1e174 Mon Sep 17 00:00:00 2001 From: Reid Campolong Date: Wed, 25 Sep 2019 01:07:13 -0400 Subject: [PATCH 9/9] Updated main function requirement --- src/Application.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Application.java b/src/Application.java index 3ff7f81..b9cedd4 100644 --- a/src/Application.java +++ b/src/Application.java @@ -9,6 +9,11 @@ */ public class Application { + /** + * Run example application for translation + * Supply one argument with the file name to translate + * @param args + */ public static void main(String[] args) { // Get lines to translate