Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import java.util.*;
  2. public class Test2 {
  3.  
  4. public static void main (String [] args){
  5. IntStruct ints = new IntStruct();
  6. ints.add(1);
  7. ints.add(5);
  8. ints.add(7);
  9. }
  10. }
  11.  
  12. class IntStruct extends ArrayList <Integer>{
  13. private int total;
  14.  
  15. boolean add (int i){
  16. setTotal();
  17. return super.add(i);
  18. }
  19.  
  20. void setTotal(){
  21. total = 0;
  22. for (int i : this){
  23. System.out.println("Adding " + i + " to our total..");
  24. total = total + i;
  25. }
  26. System.out.println("The total is now " + total);
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement