Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Test2 {
- public static void main (String [] args){
- IntStruct ints = new IntStruct();
- ints.add(1);
- ints.add(5);
- ints.add(7);
- }
- }
- class IntStruct extends ArrayList <Integer>{
- private int total;
- boolean add (int i){
- setTotal();
- return super.add(i);
- }
- void setTotal(){
- total = 0;
- for (int i : this){
- System.out.println("Adding " + i + " to our total..");
- total = total + i;
- }
- System.out.println("The total is now " + total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement