From 786a98a060b40259a4d7fc7341667e39f8544594 Mon Sep 17 00:00:00 2001 From: willokans Date: Thu, 7 Apr 2022 12:26:53 +0100 Subject: [PATCH 1/9] add .yml file --- .github/workflows/github-actions-demo.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/github-actions-demo.yml diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml new file mode 100644 index 0000000..51b2330 --- /dev/null +++ b/.github/workflows/github-actions-demo.yml @@ -0,0 +1,17 @@ +name: GitHub Actions Demo +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v3 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." \ No newline at end of file From 6ee902ae94a8f4f2d2ebe0733d55dc113cb9dace Mon Sep 17 00:00:00 2001 From: willokans Date: Thu, 7 Apr 2022 12:48:36 +0100 Subject: [PATCH 2/9] update .yml file --- .github/workflows/github-actions-demo.yml | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml index 51b2330..615691b 100644 --- a/.github/workflows/github-actions-demo.yml +++ b/.github/workflows/github-actions-demo.yml @@ -1,17 +1,17 @@ -name: GitHub Actions Demo +name: Java CI + on: [push] + jobs: - Explore-GitHub-Actions: + build: runs-on: ubuntu-latest + steps: - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - name: Check out repository code - uses: actions/checkout@v3 - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ github.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." \ No newline at end of file + - 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 \ No newline at end of file From a54f8bd96fc2311a987d0ce0f335824f66c2a5af Mon Sep 17 00:00:00 2001 From: willokans Date: Thu, 7 Apr 2022 12:55:12 +0100 Subject: [PATCH 3/9] add main.ylm file --- .github/workflows/main.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..12646c6 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,17 @@ +name: Deploy + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: akhileshns/heroku-deploy@v3.12.12 # This is the action + 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 From 45b2b48668d2618e6d8acb9d2e34350838f65252 Mon Sep 17 00:00:00 2001 From: willokans Date: Thu, 7 Apr 2022 13:04:27 +0100 Subject: [PATCH 4/9] changes --- .github/workflows/github-actions-demo.yml | 11 +++++++++-- .github/workflows/main.yml | 17 ----------------- 2 files changed, 9 insertions(+), 19 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml index 615691b..5e74b3c 100644 --- a/.github/workflows/github-actions-demo.yml +++ b/.github/workflows/github-actions-demo.yml @@ -1,6 +1,6 @@ name: Java CI -on: [push] +on: [ push ] jobs: build: @@ -14,4 +14,11 @@ jobs: java-version: '11' distribution: 'adopt' - name: Build with Maven - run: mvn --batch-mode --update-snapshots verify \ No newline at end of file + 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/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 12646c6..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Deploy - -on: - push: - branches: - - master - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: akhileshns/heroku-deploy@v3.12.12 # This is the action - 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 From 453d44e1be5182ef15c95f5dc56f587bc9f7a50f Mon Sep 17 00:00:00 2001 From: willokans Date: Thu, 7 Apr 2022 14:51:43 +0100 Subject: [PATCH 5/9] what is your name test --- src/main/java/com/develogical/QueryProcessor.java | 2 +- src/test/java/com/develogical/QueryProcessorTest.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/develogical/QueryProcessor.java b/src/main/java/com/develogical/QueryProcessor.java index 832670e..52b3a82 100644 --- a/src/main/java/com/develogical/QueryProcessor.java +++ b/src/main/java/com/develogical/QueryProcessor.java @@ -8,6 +8,6 @@ public String process(String query) { "English poet, playwright, and actor, widely regarded as the greatest " + "writer in the English language and the world's pre-eminent dramatist."; } - return ""; + return "Something!"; } } diff --git a/src/test/java/com/develogical/QueryProcessorTest.java b/src/test/java/com/develogical/QueryProcessorTest.java index 89467ca..e4f3aed 100644 --- a/src/test/java/com/develogical/QueryProcessorTest.java +++ b/src/test/java/com/develogical/QueryProcessorTest.java @@ -24,4 +24,9 @@ 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!")); + } } From 8552653dc34bdadbbca022dad5ad030186e40018 Mon Sep 17 00:00:00 2001 From: willokans Date: Thu, 7 Apr 2022 14:55:58 +0100 Subject: [PATCH 6/9] what is your name test2 --- src/main/java/com/develogical/QueryProcessor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/develogical/QueryProcessor.java b/src/main/java/com/develogical/QueryProcessor.java index 52b3a82..f1ea9e7 100644 --- a/src/main/java/com/develogical/QueryProcessor.java +++ b/src/main/java/com/develogical/QueryProcessor.java @@ -7,7 +7,9 @@ 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!"; } - return "Something!"; + return ""; } } From afe94ae178142c68848385588b7e1d5a722f2d01 Mon Sep 17 00:00:00 2001 From: willokans Date: Thu, 7 Apr 2022 15:18:55 +0100 Subject: [PATCH 7/9] hich of the numbers is the largest: 80, 444 --- src/main/java/com/develogical/QueryProcessor.java | 2 ++ src/test/java/com/develogical/QueryProcessorTest.java | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/com/develogical/QueryProcessor.java b/src/main/java/com/develogical/QueryProcessor.java index f1ea9e7..0796ca0 100644 --- a/src/main/java/com/develogical/QueryProcessor.java +++ b/src/main/java/com/develogical/QueryProcessor.java @@ -9,6 +9,8 @@ public String process(String query) { "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 numbers is the largest: 80, 444")){ + return "444"; } return ""; } diff --git a/src/test/java/com/develogical/QueryProcessorTest.java b/src/test/java/com/develogical/QueryProcessorTest.java index e4f3aed..365083a 100644 --- a/src/test/java/com/develogical/QueryProcessorTest.java +++ b/src/test/java/com/develogical/QueryProcessorTest.java @@ -29,4 +29,9 @@ public void isNotCaseSensitive() throws Exception { public void whatIsYourNameToReturnSomething() { assertThat(queryProcessor.process("what is your name"), containsString("Something!")); } + + @Test + public void whichOfTheNumberIsTheLargest(){ + assertThat(queryProcessor.process("which of the numbers is the largest: 80, 444"), containsString("444")); + } } From 6030d16a47e0bccd024fb6b3f3275d651d20152a Mon Sep 17 00:00:00 2001 From: willokans Date: Thu, 7 Apr 2022 15:53:40 +0100 Subject: [PATCH 8/9] hich of the numbers is the largest: 80, 4442 --- .../java/com/develogical/QueryProcessor.java | 34 +++++++++++++++++-- .../com/develogical/QueryProcessorTest.java | 2 +- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/develogical/QueryProcessor.java b/src/main/java/com/develogical/QueryProcessor.java index 0796ca0..b516a63 100644 --- a/src/main/java/com/develogical/QueryProcessor.java +++ b/src/main/java/com/develogical/QueryProcessor.java @@ -9,9 +9,39 @@ public String process(String query) { "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 numbers is the largest: 80, 444")){ - return "444"; + } else if (query.toLowerCase().contains("which of the following numbers is the largest:")){ + return findTheLargest(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); + } } diff --git a/src/test/java/com/develogical/QueryProcessorTest.java b/src/test/java/com/develogical/QueryProcessorTest.java index 365083a..a4b843c 100644 --- a/src/test/java/com/develogical/QueryProcessorTest.java +++ b/src/test/java/com/develogical/QueryProcessorTest.java @@ -32,6 +32,6 @@ public void whatIsYourNameToReturnSomething() { @Test public void whichOfTheNumberIsTheLargest(){ - assertThat(queryProcessor.process("which of the numbers is the largest: 80, 444"), containsString("444")); + assertThat(queryProcessor.process("cf764c60: which of the following numbers is the largest: 857, 23, 80, 1000"), containsString("1000")); } } From 70497d232fa7d040fc97be9a8c3fe71d724214aa Mon Sep 17 00:00:00 2001 From: willokans Date: Thu, 7 Apr 2022 16:01:18 +0100 Subject: [PATCH 9/9] what is the sum --- .../java/com/develogical/QueryProcessor.java | 29 +++++++++++++++++++ .../com/develogical/QueryProcessorTest.java | 7 +++++ 2 files changed, 36 insertions(+) diff --git a/src/main/java/com/develogical/QueryProcessor.java b/src/main/java/com/develogical/QueryProcessor.java index b516a63..a4c62d7 100644 --- a/src/main/java/com/develogical/QueryProcessor.java +++ b/src/main/java/com/develogical/QueryProcessor.java @@ -11,6 +11,8 @@ public String process(String query) { 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 ""; } @@ -44,4 +46,31 @@ public String findTheLargest(String line){ } 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 a4b843c..3214456 100644 --- a/src/test/java/com/develogical/QueryProcessorTest.java +++ b/src/test/java/com/develogical/QueryProcessorTest.java @@ -34,4 +34,11 @@ public void whatIsYourNameToReturnSomething() { 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")); + } + + }