Question: JAVA Q1: Using Java LinkedList and Iterators 1. Implement a class that maintains a list of the top ten performers in a video game. An
JAVA Q1: Using Java LinkedList and Iterators
1. Implement a class that maintains a list of the top ten performers in a video game. An entry on the list consists of a name and score, and the list is kept sorted in descending order of scores. Here is an example of such a list when it has only four elements. Spike 120, Whiz 105, G-Man 99, JediMaster 95. Use a class based on linked lists. The class should have:
- a constructor that sets up an empty list, - a void insert(String name, int score) method that adds a name and a score pair to the list. The insert method puts the entry in the proper position so that the list stays sorted by score. The list should have a maximum size of 10. After the list has 10 elements, an attempt to add a name with a score that is less than or equal to the minimum score on the list is ignored, and adding a score that is greater than the minimum score causes an entry with the minimum score to be dropped from the list 2:
Q2: Using the Queue interface
In this lab you will demonstrate the use of Priority Queue in a real world example.
Patients waiting to be treated by a doctor are selected by checking if it is an emergency case or not.
1) First, you need to create a class named Patient with idNumber(int), name(String) and emergencyCase (Boolean) as the class attributes.
- Add a constructor with three parameters and three get Methods to return each attribute data.
2) Next, create another class named ComparePatient that implements the Comparator interface.
- Implement the compare() method to provide an order for two patients based on their emergencyCase data. In case both patients have the same value of emergencyCase, then compare their idNumber (you can use the compareTo() method of Integer class to compare the idNumbers).
3) Test your priority queue with the following patients.
PriorityQueue
patientQueue.add(new Patient(1, "Patient1", false)); patientQueue.add(new Patient(2, "Patient2", false)); patientQueue.add(new Patient(3, "Patient3", true)); patientQueue.add(new Patient(4, "Patient4", false)); patientQueue.add(new Patient(5, "Patient5", true));
PriorityQueue
patientQueue1.add(new Patient(1, "Patient1", false)); patientQueue1.add(new Patient(2, "Patient2", false)); patientQueue1.add(new Patient(5, "Patient5", true)); patientQueue1.add(new Patient(4, "Patient4", false)); patientQueue1.add(new Patient(3, "Patient3", true));
The order in your priority queue should be similar to the following output
Doctor's waiting for patients : Patient3 <-- Patient5 <-- Patient1 <-- Patient2 <-- Patient4
The order in your priority queue1 should be similar to the following output
Doctor's waiting for patients : Patient3 <-- Patient5 <-- Patient1 <-- Patient2 <-- Patient4
Q3 : Using the Set interface
1. Write the Instructor class that holds information about an instructor( LastName, FirstName, OfficeNo). Add the instance variables, a constructor, the toString() method then write a class that stores several Instructor objects in a HashSet. The class should be able to display all the instructors in the set, and allow the user to search for an instructor. Demonstrate the class in an application.
Q4: Using the Map interface
1. Write a class that keeps Stock objects (StockNumber, name and quantity) in a Map. The class should be able to retrieve a particular Stock object from the Map by searching on its stock number. Demonstrate the class in an application.
2. You have a list of student ID numbers followed by the course number that each student is enrolled in. The listing is in no particular order. For example, if student 1 is in CS100 and CS200 while student 2 is in CS105 and MATH210, then the list might look like this:
1 CS100 , 2 MATH210, 2 CS105, 1 CS200
The list could be an array of objects, each object is an instance of a class with two attributes, the studentId and the course number.
1. Write a program that uses the HashMap class to map from an Integer (the student ID number) to an ArrayList of type String that holds each course that the student is enrolled in. The declaration should look like this: HashMap
2. Display the students list sorted by Student IDNumber where the list of courses is also sorted. ( You have to sort the keys but the ArrayList should also be sorted)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
