// APS101, Winter 2009: Lecture 9 (Jan. 27) // // Review: last time we wrote our own class, from scratch. // We wrote BankAccount.java. BankAccount ba = new BankAccount("Yaroslav", "Riabinin", 100000000.0, true, 1234); ba.getBalance() ba.withdraw(100000000) ba.getBalance() ba.deposit(1) ba.getBalance() BankAccount ba2 = new BankAccount("Yaroslav", "Riabinin", 1235); ba.isEqual(ba2) ba2.isEqual(ba) BankAccount ba3 = new BankAccount("Yaroslav", "Riabinin", 1234); ba.isEqual(ba3) // Today we'll be talking about class interactions. // aggregation relation: // When one object contains another object. // For example, a Band has three members (Musicians). // We wrote Musician.java. // LOCAL VARIABLE: // - defined within a method // - not visible outside that method // we've also seen another type of variable: // INSTANCE or GLOBAL VARIABLE: // - these variables can be seen by any method // Testing the Musician class... Musician m = new Musician("LilWayne", 10); m.getName() m.getSalary() // Then, we wrote Band.java. Musician m1 = new Musician("LilWayne", 10); Musician m2 = new Musician("PDiddy", 50); Musician m3 = new Musician("JayZ", 1000); Band b = new Band(m1, m2, m3); b.getTotalSalary() (b.getMemberOne()).getSalary() b.getMemberOne().getSalary() // what is the toString() method? // if you don't provide the toString() method, the default toString() method is called // the default returns the reference to the object, in String format, like this: Object o = new Object() o.toString() o // We wrote a toString() method in Musician Musician m1 = new Musician("LilWayne", 10); m1.toString() // We wrote a isEqual(Musician) method in Musician Musician m1 = new Musician("LilWayne", 10); Musician m2 = new Musician("Gene Simmons", 10); m1.isEqual(m2) Musician m3 = new Musician("Gene Simmons", 10); m2.isEqual(m3) m2.equals(m3) m2 == m3