Skip to content

Instantly share code, notes, and snippets.

@allisons
Created February 24, 2011 17:52
Show Gist options
  • Save allisons/842546 to your computer and use it in GitHub Desktop.
Save allisons/842546 to your computer and use it in GitHub Desktop.
//Provided Code
public class Account {
public boolean __processCalled;
public Account(Client c) {
__processCalled = false;
}
public boolean process(Transaction t) {
__processCalled = true;
return t.value() > -100 && t.value() < 1000000;
}
public class Client {}
public class Transaction {
private int value;
public Transaction(int v) {
value = v;
}
public int value() {
return value;
}
}
}
//My Code
public class FilteredAccount extends Account{
private boolean __processCalled;
private int filteredCount;
private int transactionCount;
public FilteredAccount(Client c) {
super(c);
__processCalled = false;
filteredCount = 0;
transactionCount = 0;
}
public boolean process(Transaction t){
transactionCount++;
__processCalled = true;
if(t.value == 0){
filteredCount++;
return true;
}
else{
return super.process(t);
}
}
public double percentFiltered(){
if(transactionCount == 0){
return 0.0;}
return filteredCount/transactionCount *100;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment