+1-415-670-9189
info@expertsmind.com
Create a new arraylist call peoplelist that contains people
Course:- JAVA Programming
Reference No.:- EM131599425




Assignment Help
Assignment Help >> JAVA Programming

Question1. Solving this question will help you understand Collections in java.

Copy the previous application to a new folder, open it in NetBeans and rename it to "CollectionsExample"

2.1 (20) Create a new ArrayList call "peopleList" that contains People objects.
ArrayList<People> peopleList = new ArrayList();
Then create one student Object, one Staff, and one Faculty object. Add all three objects to "peopleList"
Hint:
Student student1 = new Student("James", "Bond", new Date("01/01/1995"), 111222333);
peopleList.add(student1);
Then use a for-loop to call all objects' Display function to print out the contents of each objects.

2.2 (20) In order to compare different object, you need to implement a Comparator for class "People". Please create a FirstNameComparator which will implement the java "Comparator" Interface.
Hint declare a new class: public class FirstNameComparator implements Comparator<People>
And then override the "compare" method of that Interface in the method, you should compare the firstName String.
@Override
public int compare(People p1, People p2) {
return p1.getFirstName().compareTo(p2.getFirstName());
}

2.3 (20)refer to 2.2, write a new class "SSNComparator", and implement the java "Comparator" Interface. In that class, override the "compare" method to compare the SSN.

2.4 (20) Collection sorting method in your main function:

2.4.1 Please use Collections and FirstNameComparator to sort your "peopleList" by FirstName and print out your "peopleList".

2.4.2 Please use Collections and SSNComparator to sort your "peopleList" by SSN and print out your "peopleList".

2.5 (20)ArrayList other methods:

2.5.1 ArrayList AddAll method:
Create a new ArrayList<People> PeopleListClone object, use its AddAll method to Add "peopleList" to itself twice. You will have 6 elements for PeopleListClone. Display all six elements.

2.5.2 ArrayList Remove method.
Use remove method in "PeopleListClone" to remove the student objects in this ArrayList, two student elements will be removed. Display all four elements left.

2.5.3 ArrayList Reverse method. Use Collections.reverse method to reverse the PeopleListClone and then display all elements after reverse.

2.5.4 ArrayList Clear method. Use PeopleListClone.clear() method to empty the ArrayList, then display to user that now this array contains 0 element.

Attachment:- Assignment.zip




Put your comment
 
Minimize


Ask Question & Get Answers from Experts
Browse some more (JAVA Programming) Materials
Create a UML class diagram for your class. Your class should have at least 3 attributes (instance variables). Attributes should be appropriately typed and scoped to incorporat
Write a program to calculate the average of two values. Initialize the two values to be averaged in main. Pass these two values as parameters on the stack to the average pro
For this project, you will write a Java program that demonstrates exception handling. Your program will accept from the user ten values and place those numbers in an array
The class above is not a complete Java program that could execute. What would you do to make it execute? Change the program, or add a source code file, to make it into a Jav
Design a CD class where a CD object represents a single music CD. What kinds of information (artist, genre, total playing time, etc.) do you want to know about a CD?StateAlbum
You will write a Maze data type that can read in .maze files, and print their out in the same format. A graph can represent a maze and there are many different ways to repre
The application should have two classes; at least one class in addition to the application's controlling class. The source code must demonstrate the use of conditional and loo
implement/update specific methods for the DFS of a graph; for at least 2 graphs (1 being the provided one), show the DFS order of vertices in the graph, and for each node,