Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Quiz; Class: OBJECT-ORIENTED PROG II; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;
Typology: Quizzes
1 / 2
The first quiz for the course will be on Wednesday, Sept 13 during your lab session. The following list provides more information about the quiz:
The following exercises cover the material to be included in this quiz. Solutions to these exercises will not be provided, but you are welcome to discuss your solutions with the TA or instructor during office hours.
Exercises
ArrayList
public class Student { private String name; private int id;
public Student(String name, int id) { this.name = name; this.id = id; }
public String toString() { return "Name: " + name + " Id: " + id; } }
Rewrite the following code fragment using generics and the new for loop construct.
ArrayList L = new ArrayList();
L.add(new Student("Mary", 10)); L.add(new Student("John", 5)); L.add(new Student("Kelly", 7));
for (int i=0; i<L.size(); i++) System. out .println(L.get(i));
public class WebSite { private String name; private int links;
public WebSite(String name, int links) { this.name = name; this.links = links; }
public String toString() { return "Name: " + name + " Links: " + links; } }
a. Modify the class so it implements the Comparable interface, allowing you to compare WebSite objects based on their name.
b. Implement a comparator class that allow us to compare WebSite objects based on the number of links.
public static boolean compareStrArrays(String[][] array1, String[][] array2);
The method will return true if the arrays have the same dimensions and the same