Question: Using the Comparable Interface Write a class Compare3 that provides a static method largest. The method takes three parameters of Comparable type and returns the

 Using the Comparable Interface Write a class Compare3 that provides a

Using the Comparable Interface Write a class Compare3 that provides a static method largest. The method takes three parameters of Comparable type and returns the largest of the three (that is, the return type should be also Comparable). Use the compareTo method in the largest method to compare the passed values. Recall that the method compareTo is part of the Comparable interface, so largest can use the compareTo method of its parameters to compare them. Write a class Comparisons that has the main method for testing your largest method. . First prompt the user for and read in three strings, use your largest method to find the largest of the three strings, and print it out. (It's easiest to put the call to largest directly in the call to println, Add code to prompt the user for three integers and try to use your largest method to find the largest of the three integers. Does this work? If it does, it's thanks to autoboxing, which is automatic conversion of ints to Integers

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!