Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/** * Combiner whose <code>combine</code> method, given an Integer n and a strin

ID: 3709003 • Letter: #

Question

/**

* Combiner whose <code>combine</code> method, given an Integer n and a string,

* returns n if the string is a blank line or a line containing

* a single curly brace; otherwise returns n + 1. (A curly brace on a line whose

* only other text is an end-of-line comment is treated as just a curly brace.)

* Using a SlocCounter in the reduce method has the general effect of counting

* the number of "source lines of code" that are actual program statements,

* assuming that line comments and javadoc comments have already been

* filtered out.

*/

public class SlocCounter implements Combiner<Integer>

{

@Override

public Integer combine(Integer obj, String s)

{ return null;

}

// TODO

}

Explanation / Answer

/** * Combiner whose combine method, given an Integer n and a string, * returns n if the string is a blank line or a line containing * a single curly brace; otherwise returns n + 1. (A curly brace on a line whose * only other text is an end-of-line comment is treated as just a curly brace.) * Using a SlocCounter in the reduce method has the general effect of counting * the number of "source lines of code" that are actual program statements, * assuming that line comments and javadoc comments have already been * filtered out. */ public class SlocCounter implements Combiner { @Override public Integer combine(Integer obj, String s) { int count = 0; for(int i = 0; i