Question: Implement toString() 1. Implement the toString() method for the provided Account Class. public class Account { private String account Number; public String getAccountNumber() { return

 Implement toString() 1. Implement the toString() method for the provided AccountClass. public class Account { private String account Number; public String getAccountNumber()

Implement toString() 1. Implement the toString() method for the provided Account Class. public class Account { private String account Number; public String getAccountNumber() { return account Number; } public void setAccountNumber(String accountNumber) { this.accountNumber = account Number; } } Implement equals() 2. Implement the equals() method for the provided Account Class. Implement hashCode() 3. Implement the hashCode() method for the provided Account Class. Implement the Comparable Interface and compare To() method 4. We already implemented the overrides of the toString, equals and hashCode methods. The equals method would tell us whether two Objects are equal or not. But in some cases we need to determine the order of an object with respect to another. For example if we are comparing two strings "AA" and "AB" the string AA precedes, or comes before the string "AB", because lexicographically the orders of characters in the first string precede the ones in the second String. In some situations, for example when objects need to be ordered (sorted), two objects need to be compared so they need to support a comparison method that determines whether two given objects are either: Equal if they have equal predefined data One object precedes (comes before) the other object Or One object comes after the other object You can try the example: String s = "AA"; System.out.println(s.compareTo("BB")); And check the compare to method definition. In Java in order to compare two objects the object's class must implement the comparable Interface and use the compare to method for comparison. The compareTo method returns: Zero if the two objects are equal Negative if the first object precedes the second object (parameter to compareTo) in order Positive if the first object comes after the second object (parameter to compareTo) in order Moreover, the definition of compare To for String: public int compare To(String anotherString) Parameters: anotherString - the String to be compared. Returns: the value 0 if the argument string is equal to this string; a value less than 0 if this string is lexicographically less than the string argument; and a value greater than 0 if this string is lexicographically greater than the string argument

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!