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;
}
Answers: 1
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
[Java] Using the comparable interface
The problem I'm doing is this:
Supply a clas...
The problem I'm doing is this:
Supply a clas...
Mathematics, 20.12.2019 14:31
History, 20.12.2019 14:31
Mathematics, 20.12.2019 14:31
English, 20.12.2019 14:31
History, 20.12.2019 14:31