1 / 45

CMSC 150 more on objects, arrays

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 )

darci
Download Presentation

CMSC 150 more on objects, arrays

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CMSC 150more on objects, arrays CS 150: Wed 15 Feb 2012

  2. 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; } … }

  3. 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); }

  4. 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); }

  5. dylans 0x1123a8 0x33DB20 myName 0x112410 myID 0 myBalance 0x1124d9 myEndDate void setBalance(intbal) void setID(String id) String getID() boolean equals( DiningDollars other) …

  6. 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); }

  7. 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) …

  8. 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); }

  9. 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) …

  10. 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) …

  11. 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) …

  12. 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); }

  13. 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; } … }

  14. 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) …

  15. 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; } … }

  16. 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) …

  17. 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) …

  18. 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); }

  19. 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) …

  20. 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); }

  21. 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) …

  22. 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) …

  23. 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) …

  24. 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; } … }

  25. 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) …

  26. 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) …

  27. 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) …

  28. 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); }

  29. 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) …

  30. 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”

  31. 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) …

  32. 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) …

  33. 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) …

  34. 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; } … }

  35. 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); }

  36. 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) …

  37. 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) …

  38. 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; } … }

  39. 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); }

  40. 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) …

  41. 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) …

  42. 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; } … }

  43. 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) …

  44. 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”

  45. 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) …

More Related