Skip to content

Instantly share code, notes, and snippets.

View jasongorman's full-sized avatar

Jason Gorman jasongorman

View GitHub Profile
public class PropertyStats {
public float average(House[] house) {
float totalPrice = 0;
int count = 0;
for (int i = 0; i < house.length; i++) {
totalPrice += house[i].getPrice();
count++;
}
return totalPrice/count;
public class PropertyStats {
public float average(House[] house) {
float totalPrice = 0;
int count = 0;
if(house.length == 0)
count = 1;
for (int i = 0; i < house.length; i++) {
totalPrice += house[i].getPrice();
count++;
public float average(House[] house) {
if(house.length == 0){
throw new IllegalArgumentException();
}
float totalPrice = 0;
int count = 0;
for (int i = 0; i < house.length; i++) {
totalPrice += house[i].getPrice();
count++;
}
public class PropertyStats {
private float totalPrice;
private int count;
public float average(House[] house) {
initialiseTotal();
initialiseCount();
calculateTotal(house);
return calculateAverage();
public float average(House[] house) {
assert(house.length > 0);
int totalPrice = 0;
int count = 0;
for (int i = 0; i < house.length; i++) {
totalPrice += house[i].getPrice();
count++;
}
return totalPrice/count;
}
public class FibonacciGenerator {
public int[] generate(int sequenceLength){
int[] sequence = new int[sequenceLength];
for (int i = 0; i < sequence.length; i++) {
if(i < 2){
sequence[i] = i;
}
else {
sequence[i] = sequence[i - 1] + sequence[i - 2];
public void execute(Account a1, Account a2, float n){
a1.add(n);
a2.add(-n);
}
public void transferFunds(Account payee, Account payer, float amount){
payee.credit(amount);
payer.debit(amount);
}
public class DartsPlayerTests {
@Test
public void currentScoreIsInitialScoreMinusValueOfDartThrows() {
DartsPlayer player = new DartsPlayer(501);
player.throwDart(20, Multiplier.TREBLE);
player.throwDart(20, Multiplier.TREBLE);
player.throwDart(20, Multiplier.TREBLE);
assertEquals(501 - 180, player.getScore());
}
public int totalScore(){
List<Integer> scores = new ArrayList<Integer>();
// read scores
BufferedReader br = null;
try {
String currentLine;