450 likes | 558 Views
CMSC 150 more on objects, arrays. CS 150: Wed 15 Feb 2012. public class DiningDollars { private String myName ; private String myID ; private int myBalance ; private Calendar myEndDate ; public DiningDollars (String name, String id, int bal , int mo , int day, int yr )
E N D
CMSC 150more on objects, arrays CS 150: Wed 15 Feb 2012
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intbal, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getID()) ) { return true; } return false; } … }
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getId) ) { return true; } return false; } … } public class Tester { public static void main(String[] args) { DiningDollarsdylans = new DiningDollars( “Bob”, “123456789”, 0, 5, 1, 2012); DiningDollarstweedys = new DiningDollars( “Jeff”, “214365879”, 1000, 5, 1, 2012); dylans.setBalance(500); String tweedysID = tweedys.getID(); booleanareEqual = dylans.equals(tweedys); tweedys.setID(“123456789”); areEqual = tweedys.equals(dylans); }
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getId) ) { return true; } return false; } … } public class Tester { public static void main(String[] args) { DiningDollarsdylans = new DiningDollars( “Bob”, “123456789”, 0, 5, 1, 2012); DiningDollarstweedys = new DiningDollars( “Jeff”, “214365879”, 1000, 5, 1, 2012); dylans.setBalance(500); String tweedysID = tweedys.getID(); booleanareEqual = dylans.equals(tweedys); tweedys.setID(“123456789”); areEqual = tweedys.equals(dylans); }
dylans 0x1123a8 0x33DB20 myName 0x112410 myID 0 myBalance 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getId) ) { return true; } return false; } … } public class Tester { public static void main(String[] args) { DiningDollarsdylans = new DiningDollars( “Bob”, “123456789”, 0, 5, 1, 2012); DiningDollarstweedys = new DiningDollars( “Jeff”, “214365879”, 1000, 5, 1, 2012); dylans.setBalance(500); String tweedysID = tweedys.getID(); booleanareEqual = dylans.equals(tweedys); tweedys.setID(“123456789”); areEqual = tweedys.equals(dylans); }
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 0 myBalance 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getId) ) { return true; } return false; } … } public class Tester { public static void main(String[] args) { DiningDollarsdylans = new DiningDollars( “Bob”, “123456789”, 0, 5, 1, 2012); DiningDollarstweedys = new DiningDollars( “Jeff”, “214365879”, 1000, 5, 1, 2012); dylans.setBalance(500); String tweedysID = tweedys.getID(); booleanareEqual = dylans.equals(tweedys); tweedys.setID(“123456789”); areEqual = tweedys.equals(dylans); }
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 0 myBalance 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 0 myBalance 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 0 myBalance 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getId) ) { return true; } return false; } … } public class Tester { public static void main(String[] args) { DiningDollarsdylans = new DiningDollars( “Bob”, “123456789”, 0, 5, 1, 2012); DiningDollarstweedys = new DiningDollars( “Jeff”, “214365879”, 1000, 5, 1, 2012); dylans.setBalance(500); String tweedysID = tweedys.getID(); booleanareEqual = dylans.equals(tweedys); tweedys.setID(“123456789”); areEqual = tweedys.equals(dylans); }
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intbal, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getID()) ) { return true; } return false; } … }
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 0 myBalance 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … balance 500 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intbal, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getID()) ) { return true; } return false; } … }
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 0 500 myBalance 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … balance 500 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getId) ) { return true; } return false; } … } public class Tester { public static void main(String[] args) { DiningDollarsdylans = new DiningDollars( “Bob”, “123456789”, 0, 5, 1, 2012); DiningDollarstweedys = new DiningDollars( “Jeff”, “214365879”, 1000, 5, 1, 2012); dylans.setBalance(500); String tweedysID = tweedys.getID(); booleanareEqual = dylans.equals(tweedys); tweedys.setID(“123456789”); areEqual = tweedys.equals(dylans); }
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getId) ) { return true; } return false; } … } public class Tester { public static void main(String[] args) { DiningDollarsdylans = new DiningDollars( “Bob”, “123456789”, 0, 5, 1, 2012); DiningDollarstweedys = new DiningDollars( “Jeff”, “214365879”, 1000, 5, 1, 2012); dylans.setBalance(500); String tweedysID = tweedys.getID(); booleanareEqual = dylans.equals(tweedys); tweedys.setID(“123456789”); areEqual = tweedys.equals(dylans); }
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intbal, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getID()) ) { return true; } return false; } … }
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x124610 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x124610 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getId) ) { return true; } return false; } … } public class Tester { public static void main(String[] args) { DiningDollarsdylans = new DiningDollars( “Bob”, “123456789”, 0, 5, 1, 2012); DiningDollarstweedys = new DiningDollars( “Jeff”, “214365879”, 1000, 5, 1, 2012); dylans.setBalance(500); String tweedysID = tweedys.getID(); booleanareEqual = dylans.equals(tweedys); tweedys.setID(“123456789”); areEqual = tweedys.equals(dylans); }
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x124610 0x1124d9 myEndDate areEqual void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getId) ) { return true; } return false; } … } public class Tester { public static void main(String[] args) { DiningDollarsdylans = new DiningDollars( “Bob”, “123456789”, 0, 5, 1, 2012); DiningDollarstweedys = new DiningDollars( “Jeff”, “214365879”, 1000, 5, 1, 2012); dylans.setBalance(500); String tweedysID = tweedys.getID(); booleanareEqual = dylans.equals(tweedys); tweedys.setID(“123456789”); areEqual = tweedys.equals(dylans); } object calling equals() argument to “other”
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x124610 0x1124d9 myEndDate areEqual void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x124610 0x1124d9 myEndDate areEqual void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x124610 0x1124d9 myEndDate areEqual void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intbal, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getID()) ) { return true; } return false; } … }
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intbal, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getId) ) { return true; } return false; } … } public class Tester { public static void main(String[] args) { DiningDollarsdylans = new DiningDollars( “Bob”, “123456789”, 0, 5, 1, 2012); DiningDollarstweedys = new DiningDollars( “Jeff”, “214365879”, 1000, 5, 1, 2012); dylans.setBalance(500); String tweedysID = tweedys.getID(); booleanareEqual = dylans.equals(tweedys); tweedys.setID(“123456789”); areEqual = tweedys.equals(dylans); }
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x124610 0x1124d9 myEndDate areEqual void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x33DB31 other 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x124610 0x1124d9 myEndDate areEqual void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x33DB31 other 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intbal, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getID()) ) { return true; } return false; } … }
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intbal, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getId) ) { return true; } return false; } … } public class Tester { public static void main(String[] args) { DiningDollarsdylans = new DiningDollars( “Bob”, “123456789”, 0, 5, 1, 2012); DiningDollarstweedys = new DiningDollars( “Jeff”, “214365879”, 1000, 5, 1, 2012); dylans.setBalance(500); String tweedysID = tweedys.getID(); booleanareEqual = dylans.equals(tweedys); tweedys.setID(“123456789”); areEqual = tweedys.equals(dylans); }
dylans 0x1123a8 0x33DB20 myName 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x124610 0x1124d9 myEndDate areEqual void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x33DB31 other 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
dylans 0x1123a8 0x33DB20 myName 0x112410 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x124610 0x1124d9 myEndDate areEqual void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x33DB31 other 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intbal, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getID()) ) { return true; } return false; } … }
dylans 0x1123a8 0x33DB20 myName 0x112410 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x124610 0x1124d9 myEndDate areEqual void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x33DB31 other 0x1245b8 myName 0x124610 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …
public class DiningDollars { private String myName; private String myID; private intmyBalance; private Calendar myEndDate; public DiningDollars(String name, String id, intbal, intmo, int day, intyr) { … } public void setBalance(int balance) { myBalance = balance; } public String getID() { return myID; } public boolean equals(DiningDollars other) { if ( myID.equals(other.getId) ) { return true; } return false; } … } public class Tester { public static void main(String[] args) { DiningDollarsdylans = new DiningDollars( “Bob”, “123456789”, 0, 5, 1, 2012); DiningDollarstweedys = new DiningDollars( “Jeff”, “214365879”, 1000, 5, 1, 2012); dylans.setBalance(500); String tweedysID = tweedys.getID(); booleanareEqual = dylans.equals(tweedys); tweedys.setID(“123456789”); areEqual = tweedys.equals(dylans); } object calling equals() argument to “other”
dylans 0x1123a8 0x33DB20 myName 0x112410 0x112410 myID tweedys 0x33DB31 500 myBalance tweedysID 0x124610 0x1124d9 myEndDate areEqual void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) … 0x33DB20 other 0x1245b8 myName 0x124731 myID 1000 myBalance 0x1246d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …