class Counter { void up() {v++;} void down() {v--;} public String toString() {return v + "";} private int v = 0; }write an app class that illustrates the use of this class. At least two objects should be created and every method must be called at some point.
class Name { Name(String first, String last) { this.first = first; this.last = last; } String getFirst() {return first;} String getFirst() {return first;} String getInitials() {return first.charAt(0) + "." + last.charAt(0) + ".";} boolean equals(Name otherName) {return last.equals(otherName.last) && first.equals(otherName.first);} public String toString() {return last + ", " + first;} private String first, last; }
Name name1 = new Name("Gerald", "Weiss"), name2 = new Name("David Arnow"), name3 = name1, name4 = new Name("Gerald", "Weiss");; System.out.println(name1.getInitials()); System.out.println(name1.equals(name2)); System.out.println(name1.equals(name3)); System.out.println(name1.equals(name4));
equals
method
class C { C(int v) { this.v = v; } private int v = 0; }