Java Reference
In-Depth Information
private AtomicInteger bases;
private AtomicInteger baseOnBalls;
private AtomicInteger sacrifices;
and the initialization of those fields in the constructor to:
public BatterImpl() {
atBats = new AtomicInteger();
hits = new AtomicInteger();
bases = new AtomicInteger();
baseOnBalls = new AtomicInteger();
sacrifices = new AtomicInteger();
}
The body of the atBat() method could then be changed to:
public void atBat(AtBatResult what) {
switch (what) {
case strikeOut:
break;
case fieldOut:
break;
case base1:
hits.incrementAndGet();
bases.incrementAndGet();
break;
case base2:
hits.incrementAndGet();
bases.addAndGet(2);
break;
case base3:
hits.incrementAndGet();
bases.addAndGet(3);
case base4:
hits.incrementAndGet();
bases.addAndGet(4);
case sacrifice:
sacrifices.incrementAndGet();
return;
case walk:
baseOnBalls.incrementAndGet();
return;
}
Search WWH ::




Custom Search