Write a class Compare3 that provides a static method largest. Method largest should
take three Comparable parameters and return the largest of the three (so its return type will
also be Comparable). Recall that method compareTo is part of the Comparable interface,
so largest can use the compareTo method of its parameters to compare them.
(4) Write a class Comparisons whose main method tests your largest method above.
(a) 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.) Note that since largest is a static method, you will call it
through its class name, e.g.,
compare3.largest(val1, val2, val3) and
(b) Add code to also 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 Java's automatic conversion of ints to Integers.(10 Points)
how do i call this two classes in one program? i am having a had time calling in on program. any help will be great
It looks like like you have an assignment to do an someone else's solution and you can't run it.
Am I right?
And please UseCodeTags (click it).
posted 5 years ago
nope, the was a similar one in class concerning comparable interface, but my problem is from the lab exercise i dont know how to call it differently. I know there's a code but i cannot figureit out. everything looks fine to me so far, just having error with regards to class.
Piet Souris wrote:So that's not the problem. Problem is that there are two public classes. If these are in the same file,
then you get an error.
And, assuming it is the problem, then well spotted. We (and by that I mean, I) often spend too much time on issues other than the question.
@atem: Has that answered your question? If so, then your problem is solved. If not, then read the whole thread, because there is other useful information.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
posted 5 years ago
Winston Gutkowski wrote:And, assuming it is the problem, then well spotted. (...)
Thanks, but too much credit! I happened to drop the code into NetBeans to test it, and it
gave me that error before I had time to take a breath. It looked to me that that method
was allright (if a is not the largest, then that largest must be either b or c, and so on).
That method does not scale very well, though, so I bet the next question in that course
will be to make a general version of the question