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 22:10
Asequential circuit contains a register of four flip-flops. initially a binary number n (0000 ≤ n ≤ 1100) is stored in the flip-flops. after a single clock pulse is applied to the circuit, the register should contain n + 0011. in other words, the function of the sequential circuit is to add 3 to the contents of a 4-bit register. design and implement this circuit using j-k flip-flops.
Answers: 1
question
Computers and Technology, 23.06.2019 07:00
You need a quick answer from a coworker. the most effective way to reach your coworker is through a. cloud server b. instant message c. teleconference d. telepresence
Answers: 1
question
Computers and Technology, 23.06.2019 08:00
What is a scenario where records stored in a computer frequently need to be checked
Answers: 2
question
Computers and Technology, 24.06.2019 00:00
Which tool could be used to display only rows containing presidents who served two terms
Answers: 3
You know the right answer?
[Java] Using the comparable interface
The problem I'm doing is this:

Supply a clas...
Questions
question
Mathematics, 02.12.2020 20:20
question
English, 02.12.2020 20:20
question
Law, 02.12.2020 20:20