subject

[Java] Using the comparable interface
The problem I'm doing is this:

Supply a class Person that implements the Comparable interface. Compare persons by their names. Ask the user to input ten names and generate ten Person objects. Using the compareTo method, determine the first and last person among them and print them.

I have created an ArrayList of the person object that stores the 10 names, but now I'm confused how to use the compareTo() method in the person class. Maybe I'm just confused by the part where it says to determine the first and the last person among them, mainly because that doesn't seem like something you would need to compare. Unless I'm supposed to iterate through the arrayList and compare the elements of the arrayList?

I have the following code for the compareTo() method:

public int compareTo(Object temp)
{
Person other = (Person) temp;

if (this. getName().equals(other. getName()))
{
return this. getName().compareTo(other. getName());
}
return 0;
}

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 16:20, kimmmmmmy333
Octothorpe is another name for what common computer keyboard symbol?
Answers: 1
image
Computers and Technology, 22.06.2019 17:00, DRock4976
Which of the following is not contained on the slide show toolbar? a. next button b. slide button c. close button d. pen too
Answers: 2
image
Computers and Technology, 22.06.2019 19:30, 710jonathan
The following is an excerpt from a slide presentation. today we will inverse operations solving equations using inverse operations solving inequalities using inverse operations from which part of the presentation does the slide most likely come from? a. introduction b. outline c. body d. conclusion
Answers: 1
image
Computers and Technology, 23.06.2019 06:00, tchloe448
What makes myhexadecimalnumber a child of mynumber? which methods does myhexadecimalnumber inherit directly from the mynumber class? what can an instance of the mynumber class do? what can an instance of the myhexadecimalnumber class do? which methods are overridden? why are they overridden? how many examples of overloading are there? why was this done? where is the super keyword used? what is it doing? why isn’t the incoming value set immediately in the second myhexadecimalnumber constructor? how many examples can you find of an inherited method being called?
Answers: 1
You know the right answer?
[Java] Using the comparable interface
The problem I'm doing is this:

Supply a clas...

Questions in other subjects:

Konu
Physics, 10.09.2020 05:01
Konu
Mathematics, 10.09.2020 05:01
Konu
Mathematics, 10.09.2020 05:01
Konu
Mathematics, 10.09.2020 05:01
Konu
Mathematics, 10.09.2020 05:01
Konu
Mathematics, 10.09.2020 05:01
Konu
Mathematics, 10.09.2020 05:01
Konu
Mathematics, 10.09.2020 05:01
Konu
Mathematics, 10.09.2020 05:01
Konu
History, 10.09.2020 05:01