@@ -14,6 +14,68 @@ the right and left of the current position in the previous row.
1414# ... etc
1515```
1616
17+ # Java Tips
18+
19+ Since this exercise has difficulty 5 it doesn't come with any starter implementation.
20+ This is so that you get to practice creating classes and methods which is an important part of programming in Java.
21+ It does mean that when you first try to run the tests, they won't compile.
22+ They will give you an error similar to:
23+ ```
24+ path-to-exercism-dir\exercism\java\name-of-exercise\src\test\java\ExerciseClassNameTest.java:14: error: cannot find symbol
25+ ExerciseClassName exerciseClassName = new ExerciseClassName();
26+ ^
27+ symbol: class ExerciseClassName
28+ location: class ExerciseClassNameTest
29+ ```
30+ This error occurs because the test refers to a class that hasn't been created yet (` ExerciseClassName ` ).
31+ To resolve the error you need to add a file matching the class name in the error to the ` src/main/java ` directory.
32+ For example, for the error above you would add a file called ` ExerciseClassName.java ` .
33+
34+ When you try to run the tests again you will get slightly different errors.
35+ You might get an error similar to:
36+ ```
37+ constructor ExerciseClassName in class ExerciseClassName cannot be applied to given types;
38+ ExerciseClassName exerciseClassName = new ExerciseClassName("some argument");
39+ ^
40+ required: no arguments
41+ found: String
42+ reason: actual and formal argument lists differ in length
43+ ```
44+ This error means that you need to add a [ constructor] ( https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html ) to your new class.
45+ If you don't add a constructor, Java will add a default one for you.
46+ This default constructor takes no arguments.
47+ So if the tests expect your class to have a constructor which takes arguments, then you need to create this constructor yourself.
48+ In the example above you could add:
49+ ```
50+ ExerciseClassName(String input) {
51+
52+ }
53+ ```
54+ That should make the error go away, though you might need to add some more code to your constructor to make the test pass!
55+
56+ You might also get an error similar to:
57+ ```
58+ error: cannot find symbol
59+ assertEquals(expectedOutput, exerciseClassName.someMethod());
60+ ^
61+ symbol: method someMethod()
62+ location: variable exerciseClassName of type ExerciseClassName
63+ ```
64+ This error means that you need to add a method called ` someMethod ` to your new class.
65+ In the example above you would add:
66+ ```
67+ String someMethod() {
68+ return "";
69+ }
70+ ```
71+ Make sure the return type matches what the test is expecting.
72+ You can find out which return type it should have by looking at the type of object it's being compared to in the tests.
73+ Or you could set your method to return some random type (e.g. ` void ` ), and run the tests again.
74+ The new error should tell you which type it's expecting.
75+
76+ After having resolved these errors you should be ready to start making the tests pass!
77+
78+
1779# Running the tests
1880
1981You can run all the tests for an exercise by entering
0 commit comments