Adding a Custom Contact Class 1. In your Binary Search Tree project from lab, cr
ID: 3696406 • Letter: A
Question
Adding a Custom Contact Class 1. In your Binary Search Tree project from lab, create a class called Contact that represents the contact information for a particular person. We'll keep it simple and only store a first name, last name, and phone number. Store all three fields as strings 2. The Contact class should implement the generic version of the Comparable interface so that it can compare itself to other contacts. Compare contacts alphabetically by last name. If last names are identical, then compare by first name. If both last and first names are identical, then compare (alphabetically) by phone number. Two contacts should compare as equal only if all three fields are equal 3. Here is the method definition of the compareTo method 1 3 Compares two contacts and returns how they relate to each other 4A It first compares the lastName field, then the firstName, and finally the phoneNumber. If you get a positive number, the value of "this" is "greater than" or "later" in the alphabet and should be placed after the node. "Alice". compareTo ("Juan") will return negative "Juan". compareTo ("Juan") ill compare phoneNumber * for example same last name, but comparing first names: * "Ieron". compareTo ("Juan") vill return positive 12 13 14 eOverride 4. Write a basic test class for your Contact class, to make sure that comparisons work correctly. Note that you do not have to write separate test cases for getters, setters, or the constructor, if you are also using those methods to set up the conditions for other tests (say, for testing compareTo0), or if you are using those methods in assertion checks in other test cases 5. For your tests, your tree should be a Lab14BinarySearchTree 6. Using the Contact class, you can write additional unit tests for inserting, finding, and removing values from a binary search tree of contacts. This will exercise the use of your custom compareTo0 method for ordering in the tree 7. Run your tests and fix any problems discoveredExplanation / Answer
Java's assert condition... or it's more advanced Groovy cousin, Guava's Preconditions.checkXXXX(condition...) and Verify.verify(condition...), or a library likeAssertJ, if all you need is just to do simple checks in your 'main' or 'test' code
you'll get more features with a tool like OVal; it can check both objects as well as method arguments and results, you can also fire checks manually (eg to show validation errors on UI before a method is called). It can understand existing annotations eg from JPA or javax.validation (like @NotNull, @Pattern, @Column), or you can write inline constraints like @Pre(expr="x >= 0 && x <= y"). If the annotation is @Documented, the checks will be also visible in Javadocs (you don't have to describe them there as well).
OVal uses reflection, which can make performance issues and other problems in some environments like Android; then you should consider tool like Google's Cofoja, which has less functionality, but depends on compile-time Annotation Processing Tool instead of reflection
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.