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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 19:20
How might the success of your campaign be affected if you haven’t carefully completed all field data or if you accidentally insert the wrong merge field in the document?
Answers: 2
question
Computers and Technology, 23.06.2019 07:30
What is the penalty for violating section 1201 of title 17 chapter 21 of the us code
Answers: 1
question
Computers and Technology, 23.06.2019 21:30
Enzo’s balance sheet for the month of july is shown. enzo’s balance sheet (july 2013) assets liabilities cash $600 credit card $4,000 investments $500 student loan $2,500 house $120,000 mortgage $80,000 car $6,000 car loan $2,000 total $127,100 total $88,500 which expression finds enzo’s net worth?
Answers: 1
question
Computers and Technology, 24.06.2019 13:00
Think of a spreadsheet as a giant calculator spread of paper chart data collector
Answers: 2
You know the right answer?
[Java] Using the comparable interface
The problem I'm doing is this:

Supply a clas...
Questions
question
Mathematics, 09.05.2021 21:40
question
Physics, 09.05.2021 21:40
question
History, 09.05.2021 21:40
question
Mathematics, 09.05.2021 21:40
Questions on the website: 13722363