Testing Java Candidates - Part II

  • Posted on: 21 January 2016
  • By: rob

The second article on the topic of testing the Java capabilities of candidates who have applied for a software developers job at Certus Technology. Our process has been outlined in part I. Question 3 on our test aims to understand a bit about the candidates ability to go from a requirement of a method to the implementation. When the question was first written, we thought up what we considered to be a trivial maths problem with an indication of how much space might be needed for the answer. Lets start with the question.

Question 3. Write the following method.

/** Return the area of a rightangled triangle given the base angle and the base length.
 *  @param
 *  @param
 *  @return
 */




Once again, please take a moment to consider your own answer to this question.

.
.
.
.
.
.
.
.

Bear in mind that most candidates have just finished a Computer Science degree and have passed a Maths 'A' level or equivalent exam, we find the answers fall into 4 categories.

  • 50% Type A: Candidate fails to give any sort of meaningful answer and when questioned vaguely asks if it is something to do with Pythagoras. 0 marks.
  • 30% Type B: Candidate has a stab at an answer, with some notion that the solution requires trigonometry, but fails to provide a working answer. 0 marks.
  • 10% Type C: Candidate correctly identifies formula for solution but does not provide a working Java method. ½ marks.
  • 10% Type D: Candidate correctly identifies formula for solution and provides a working Java method. 1 mark.

The area of a rightangled triangle is base length*height/2. You are given the base length and base angle, so you need to calculate the height, for which you need some trigonometry, height = tan(angle)*base length, so the formula needed is baseLength*baseLength*tan(baseAngle)/2.

The model answer contains some working as above and code something like this:

/** Return the area of a rightangled triangle given the base angle and the base length.
 *  @param baseAngle The base angle of the rightangled triangle in radians.
 *  @param baseLength The base length of the rightangled triangle.
 *  @return The area of a rightangled triangle.
 */
public double triangleAreaFromBaseAngleInRadAndBaseLength(double baseAngle, double baseLength) {
  if (baseAngle = Math.PI/2.0) {
    throw new IllegalArgumentException("baseAngle of a rightangled triangle must be between 0 and π/2, got " + baseAngle);
  }
  return baseLength*baseLength*Math.tan(baseAngle)/2.0;
}

Things we observe are:

  • Does the method name reflect the methd function. It is considered poor if the method name is something like "area" or "calculate".
  • Is there any error checking? (We have yet to see anyone provide error checking in their solution.)
  • Has the JavaDoc been completed

The really surprising thing for us was just how many Type A and Type B answers we get, as our initial intention was to have a trivial maths problem to solve. I can only guess there is not much trig required in a Computer Science degree.