diff --git a/README.md b/README.md index 9ca0ee1..ded0861 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Some interview questions and solutions +# Some interview questions and solutions [![Maintainability](https://api.codeclimate.com/v1/badges/85cc07be5c6b99a815c6/maintainability)](https://codeclimate.com/github/gnomeria/interview-question-djava/maintainability) ->***These Java classes require Java 8*** +> **_These Java classes require Java 8_** The project uses Maven as its build and dependency tools, and jUnit as its unit testing framework. @@ -14,7 +14,7 @@ This will run all tests from `src/test/java/*` This project's questions classes solutions ( `Q2.java`, `Q3.java`, `Q3_Optimize.java` ) DOES NOT have main class, so that it's cleaner to see the solution, and running the test classes can be used instead. -******************************** +--- ## Question 1 @@ -22,16 +22,16 @@ cleaner to see the solution, and running the test classes can be used instead. - It should return True if the first character is an uppercase. - You cannot use `String` APIs. -******************************** +--- -******************************** +--- ## Question 2 - Write a solution that returns an `Integer` with the total number of files -in a given folder including any files in its’ sub-folders (if any exist) + in a given folder including any files in its’ sub-folders (if any exist) -******************************** +--- ## Question 3 @@ -45,7 +45,7 @@ in a given folder including any files in its’ sub-folders (if any exist) - The exit is represented by a `3`. - Each path can only have two end points; **entrance** and **exit**. You cannot use the entrance or exit more than once foreach path. - You have to step on every spot exactly once. - - You can only move like a King in chess(***horizontally*** or ***vertically*** but not diagonally) + - You can only move like a King in chess(**_horizontally_** or **_vertically_** but not diagonally) ### Example: @@ -60,6 +60,6 @@ in a given folder including any files in its’ sub-folders (if any exist) > The answer is 4 -Your program should read from standard input with a series of integers with whitespace as delimiter. The ***first two integer*** represents the `width` and `height` of the maze. It will then befollowed by width * height more integers.Your output should be an integer which shows the total number of possiblepath +Your program should read from standard input with a series of integers with whitespace as delimiter. The **_first two integer_** represents the `width` and `height` of the maze. It will then befollowed by width \* height more integers.Your output should be an integer which shows the total number of possiblepath -******************************** \ No newline at end of file +--- diff --git a/src/main/java/sami/interview/Q2.java b/src/main/java/sami/interview/Q2.java index 8836c6b..78f47a3 100644 --- a/src/main/java/sami/interview/Q2.java +++ b/src/main/java/sami/interview/Q2.java @@ -32,9 +32,13 @@ public class Q2 { * @return */ private int GetNumberOfFiles(File file, int count) { - if(!file.exists()) return 0; //the provided file path does not exist + if(!file.exists()) { + return 0; //the provided file path does not exist + } int current = 0; - if(file.isFile()) return 1; + if(file.isFile()) { + return 1; + } else { for (File f : file.listFiles()) { current = current + GetNumberOfFiles(f, ++count); diff --git a/src/test/java/sami/interview/Q1Test.java b/src/test/java/sami/interview/Q1Test.java index 1bb72af..3dc4171 100644 --- a/src/test/java/sami/interview/Q1Test.java +++ b/src/test/java/sami/interview/Q1Test.java @@ -22,6 +22,7 @@ public void shouldReturnTrueForUppercaseStrings() throws Exception { assertTrue(Q1.isFirstCharUppercase("Jvm")); assertTrue(Q1.isFirstCharUppercase("Github")); assertTrue(Q1.isFirstCharUppercase("Sami")); + assertTrue(Q1.isFirstCharUppercase("Sami")); } @Test diff --git a/src/test/java/sami/interview/SolutionsTestRunner.java b/src/test/java/sami/interview/SolutionsTestRunner.java index 3ebc9e1..3f90aa5 100644 --- a/src/test/java/sami/interview/SolutionsTestRunner.java +++ b/src/test/java/sami/interview/SolutionsTestRunner.java @@ -25,7 +25,7 @@ public static void main(String[] args) { Result result = JUnitCore.runClasses(classList.toArray(new Class[classList.size()])); if (result.wasSuccessful()) { logger.info("All tests passed successfully. Tests ran for: {}ms", result.getRunTime()); - return; + return 0; } result.getFailures().forEach(f -> logger.error("Error on: {}", f)); }