148k views
4 votes
Using Java in Intellij

In the Person class implement the following method:
compareTo = compare a person to the other person. First, try to compare by last name --> if the last name has the same order compare the first name --> if the first name has the same order compare by ID
Example: 'anne teak' has a lower order than 'Trina Woods' because 'teak' comes before 'Woods' Example: 'Morgan Beck' (ID:100) and 'Morgan Beck' (ID:200) have the same last name and first name but the first person comes first because has ID 100 and the second 200
In the Assignment1Driver class (this is the driver because it contains the main method) implement the following methods:
isSet = isSet checks if the wordBag is a set (has duplicates or not) returns true if it is a set (does not have duplicates), it returns false if it is not a set (has duplicates)
--BUT-- very important, make sure the content of the wordBag remains the same after the execution of the method createListContainingChar = This method takes as a parameter a list (type ListInterface) of strings and a char, it returns a new list with only those entries from wordList that contain the char parameter
--BUT-- very important, make sure the content of the wordList remains the same after the execution of the method lastPosition = This method takes as a parameter a list (type List) of strings and a String target, it returns an int that corresponds to the last index position of the target if the target is not present in the list return -1
--BUT-- very important, make sure the content of the wordList remains the same after the execution of the method Example: mark, mark, luna, joel, blue, mark if we pass 'mark' as the target, the method should return 5 because the last 'mark' is at index 5 equivalentLists = This method takes two lists as parameters and checks for the equality of the two lists. Be careful, the two lists have a different declared type so use the appropriate methods for each type
--BUT-- very important, make sure the content of the lists remains the same after the execution of the method prioritizeMaximumValue This method takes a numberList (type List) as a parameter and changes the order of its elements moving to the front (first position) the greatest number among them. Only the greatest number gets moved, all the other elements are not changing the order. This is a void method, it doesn't return anything.

1 Answer

5 votes

Final answer:

To compare Persons in Java, implement a compareTo method in the Person class. The Assignment1Driver class should include methods to check if a collection is a set, create a list with a specific character, find the last position of a string, compare two lists, and prioritize the maximum value in a list without modifying the original content.

Step-by-step explanation:

To implement a compareTo method in the Person class that compares persons by last name, first name, and ID, you would create the method within the Person class that implements the Comparable interface. This method will use string comparison for names and numeric comparison for IDs.

The isSet method in the Assignment1Driver class will check if the wordBag is a set without duplicates. To do this without altering the contents of the wordBag, you'll need to iterate over the elements and use a data structure like HashSet to track uniqueness.

The createListContainingChar method will create a new list with the entries from the provided list that contain a specified character, ensuring that the original list is not modified.

The lastPosition method returns the last index of a target string in a list, or -1 if not present. Again, the method must ensure the original list remains unchanged.

In the equivalentLists method, you'll compare two lists of different types by their contents without changing them. This calls for iteration over both lists while maintaining their original state.

Finally, the prioritizeMaximumValue method will find the maximum value in a numberList and move it to the first position without changing the order of the other elements.

User Nomade
by
8.0k points

Related questions