diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml new file mode 100644 index 0000000..5e74b3c --- /dev/null +++ b/.github/workflows/github-actions-demo.yml @@ -0,0 +1,24 @@ +name: Java CI + +on: [ push ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'adopt' + - name: Build with Maven + run: mvn --batch-mode --update-snapshots verify + + - name: deploy + uses: akhileshns/heroku-deploy@v3.12.12 + with: + heroku_api_key: ${{secrets.HEROKU_API_KEY}} + heroku_app_name: "horse-battery-66db" + heroku_email: "willokans@outlook.com" \ No newline at end of file diff --git a/src/main/java/com/develogical/QueryProcessor.java b/src/main/java/com/develogical/QueryProcessor.java index 832670e..a4c62d7 100644 --- a/src/main/java/com/develogical/QueryProcessor.java +++ b/src/main/java/com/develogical/QueryProcessor.java @@ -7,7 +7,70 @@ public String process(String query) { return "William Shakespeare (26 April 1564 - 23 April 1616) was an " + "English poet, playwright, and actor, widely regarded as the greatest " + "writer in the English language and the world's pre-eminent dramatist."; + } else if (query.toLowerCase().contains("what is your name")) { + return "Something!"; + } else if (query.toLowerCase().contains("which of the following numbers is the largest:")){ + return findTheLargest(query); + } else if (query.toLowerCase().contains("plus")) { + return doSum(query); } return ""; } + + + public String findTheLargest(String line){ + //We split the line at each space, so we can separate each number + String[] array = line.split("\\s+"); + + //Integer.MIN_VALUE will give you the smallest number an integer can have, + //and you can use this to check against. + int largestInt = Integer.MIN_VALUE; + + //We iterate over each of the separated numbers (they are still Strings) + for (String numberAsString : array) { + + //Integer.parseInt will parse a number to integer from a String + //You will get a NumberFormatException if the String can not be parsed + int number = 0; + try { + number = Integer.parseInt(numberAsString); + }catch (NumberFormatException ex) { + + } + + //Check if the parsed number is greater than the largestInt variable + //If it is, set the largestInt variable to the number parsed + if (number > largestInt) { + largestInt = number; + } + } + return String.valueOf(largestInt); + } + + public String doSum(String line){ + //We split the line at each space, so we can separate each number + String[] array = line.split("\\s+"); + + //Integer.MIN_VALUE will give you the smallest number an integer can have, + //and you can use this to check against. + int total = 0; + + //We iterate over each of the separated numbers (they are still Strings) + for (String numberAsString : array) { + + //Integer.parseInt will parse a number to integer from a String + //You will get a NumberFormatException if the String can not be parsed + int number = 0; + try { + number = Integer.parseInt(numberAsString); + }catch (NumberFormatException ex) { + + } + + //Check if the parsed number is greater than the largestInt variable + //If it is, set the largestInt variable to the number parsed + total += number; + } + return String.valueOf(total); + } } diff --git a/src/test/java/com/develogical/QueryProcessorTest.java b/src/test/java/com/develogical/QueryProcessorTest.java index 89467ca..3214456 100644 --- a/src/test/java/com/develogical/QueryProcessorTest.java +++ b/src/test/java/com/develogical/QueryProcessorTest.java @@ -24,4 +24,21 @@ public void knowsAboutShakespeare() throws Exception { public void isNotCaseSensitive() throws Exception { assertThat(queryProcessor.process("shakespeare"), containsString("playwright")); } + + @Test + public void whatIsYourNameToReturnSomething() { + assertThat(queryProcessor.process("what is your name"), containsString("Something!")); + } + + @Test + public void whichOfTheNumberIsTheLargest(){ + assertThat(queryProcessor.process("cf764c60: which of the following numbers is the largest: 857, 23, 80, 1000"), containsString("1000")); + } + + @Test + public void whatIsTheSum(){ + assertThat(queryProcessor.process("e2cc7c00: What is 10 plus 8"), containsString("18")); + } + + }