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