Computers and Technology
Computers and Technology, 05.05.2020 14:59, Devan6264

[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;
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 12:00, kp2078
What type of slide show is a dynamic and eye-catching way to familiarize potential customers with what your company has to offer? a. ole b. photo album c. brochure d. office clipboard
Answers: 2
image
Computers and Technology, 24.06.2019 16:50, yedida
Ideally, the backrest is tilted back slightly, so when you turn the wheel your shoulders are the seat.
Answers: 2
image
Computers and Technology, 25.06.2019 00:30, kukisbae
How do i take a screenshot on a laptop?
Answers: 2
image
Computers and Technology, 25.06.2019 07:00, ChHal1958
Afile named data. txt contains an unknown number of lines, each consisting of a single integer. write some code that creates two files, dataplus. txt and dataminus. txt, and copies all the lines of data1.txt that have positive integers to dataplus. txt, and all the lines of data1.txt that have negative integers to dataminus. txt. zeros are not copied anywhere.
Answers: 2
Do you know the correct answer?
[Java] Using the comparable interface
The problem I'm doing is this:

Supply a clas...

Questions in other subjects:

Konu
Mathematics, 20.12.2019 14:31