Question
1. Write a class Compare3 that provides a static method largest. Method largest should take three Comparable parametersand return the largest of the three (so
1. Write a class Compare3 that provides a static method largest. Method largest should take three Comparable parametersand return the largest of the three (so its return type will also be Comparable). Recall that method compareTo is part ofthe Comparable interface, so largest can use the compareTo method of its parameters to compare them. 2. Write a class Comparisons whose main method tests your largest method above. First prompt the user for and read in three strings, use your largest method to find the largest of the three strings, andprint it out. (Its easiest to put the call to largest directly in the call to println.) Note that since largest is a staticmethod, you will call it through its class name, e.g., Compare3.largest(val1, val2, val3). Add code to also prompt the user for three integers and try to use your largest method to find the largest of the threeintegers. Does this work? If it does, its thanks to autoboxing, which is Java 1.5s automatic conversion of ints toIntegers. You may have to use the -source 1.5 compiler option for this to work.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started