Created
February 24, 2011 17:52
-
-
Save allisons/842546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment