ChartMaker
The ChartMaker
class is makes
histograms.
When you make a ChartMaker
object, you provide a list of cut scores
to use for making the bins.
public class ChartMaker {
// (a) Constructor
public ChartMaker(List<Integer> cutscores) {...}
// (b) ingest: put data in bins according to cutscores
public void ingest(int[] data) {...}
// (c) barChart: produce a list of bars "X" based
// maxwidth = 100% of data
public List<String> barChart(int maxwidth) { ... }
// (d) mergeAdjacent: update all of the counts and cutscores
// to join every two "bins" into one
public void mergeAdjacent() { ... }
}
Examples
{
List<Integer> cutscores = Arrays.asList(0,10,20,30);
ChartMaker cm = new ChartMaker(cutscores);
int[] data = {1,2,3,4,3,2,1,11,13,22,23,24,31,50,100};
cm.ingest(data);
ArrayList<String> chart = cm.barChart(80);
cm.mergeAdjacent(); // join cutscores to be {0,20}, counts also updated
}
Helper functions
In writing you may assume the existence of a String repeating method.
public static String rep (String x, int times) {
return x.repeat(times);
}