Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab04;
- import java.util.ArrayList;
- import java.util.Collections;
- public class InterfaceTester{
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.println("Account Balances sorted");
- BankAccount account1 = new BankAccount(3500);
- BankAccount account2 = new BankAccount(0);
- BankAccount account3 = new BankAccount(10000);
- BankAccount account4 = new BankAccount(100);
- BankAccount account5 = new BankAccount(168168);
- BankAccount account6 = new BankAccount(99988);
- ArrayList < BankAccount > list = new ArrayList < BankAccount >();
- list.add(account1);
- list.add(account2);
- list.add(account3);
- list.add(account4);
- list.add(account5);
- list.add(account6);
- Collections.sort(list);
- for (int i = 0; i < list.size(); i++)
- {
- BankAccount b = list.get(i);
- System.out.println(b.getBalance());
- }
- System.out.print("\nSorted Rectangles by Area\n");
- Rect rectangle1 = new Rect(20,20);
- Rect rectangle2 = new Rect(10,10);
- Rect rectangle3 = new Rect(60,150);
- Rect rectangle4 = new Rect (520,700);
- ArrayList < Rect > rList = new ArrayList < Rect >();
- rList.add(rectangle1);
- rList.add(rectangle2);
- rList.add(rectangle3);
- rList.add(rectangle4);
- Collections.sort(rList);
- for (int i = 0; i < rList.size(); i++)
- {
- Rect c = rList.get(i);
- System.out.println(c.toString());
- }
- public static double computeAverage(ArrayList rList)
- {
- double sum= 0;
- for (int i = 0; i < rList.size(); i++)
- {Sizeable s = (Sizeable)list.get( i );
- sum += s.getSizeOf();
- }
- return sum / rList.size();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement