Programming Concepts using Java, Quiz 2
Consider the Java code given below that prints the maximum element of a set. From among the options, identify the appropriate function header for function findMax that takes as input a set of numbers and prints the maximum element of the set.
import java.util.*;class Test { // FUNCTION HEADER for function findMax { // Prints the maximum element of the set }
public static void main(String[] args) { Set<Integer> s = new HashSet<>(); s.add(12); s.add(23);
Set<Double> s1 = new HashSet<>(); s1.add(12.2); s1.add(23.4);
findMax(s); findMax(s1); }}Choose the correct option(s)
Consider the Java code given below that prints the maximum element of a set. From among the options, identify the appropriate function header for function `findMax` that takes as input a set of numbers and prints the maximum element of the set. import java.util.*; class Test { // FUNCTION HEADER for function findMax { // Prints the maximum element of the set } public static void main(String[] args) { Set<Integer> s = new HashSet<>(); s.add(12); s.add(23); Set<Double> s1 = new HashSet<>(); s1.add(12.2); s1.add(23.4); findMax(s); findMax(s1); } } Choose the correct option(s) Consider the Java code given below. interface Deliverable { public static void status() { System.out.println("Delivery status"); } public default void deliver() { System.out.println("Order delivered"); } } interface Trackable { public static void status() { System.out.println("Tracking status"); } public default void track() { System.out.println("Tracking order"); } } class FoodOrder implements Deliverable, Trackable { public void deliver() { System.out.println("Delivered successfully"); } } public class Test { public static void main(String[] args) { Deliverable o1 = new FoodOrder(); o1.deliver(); o1.track(); Deliverable.status(); //LINE-1 Trackable.status(); //LINE-2 } } Choose the correct option. The following code maps a set of patients to the number of visits they have made to a hospital and categorizes the patients based on whether they are regular visitors (more than 3 visits) or occasional visitors. import java.util.*; public class Hospital { TreeSet<String> rPatients = new TreeSet<String>(); TreeSet<String> oPatients = new TreeSet<String>(); public boolean check(int visits) { return visits > 3; } public void categorizePatients(HashMap<String, Integer> pMap) { for (Map.Entry<String, Integer> entry : pMap.entrySet()) { if (check(entry.getValue())) { rPatients.add(entry.getKey()); } else { oPatients.add(entry.getKey()); } } } public void displayPatients() { System.out.println("R Patients: " + rPatients); System.out.println("O Patients: " + oPatients); } public static void main(String[] args) { HashMap<String, Integer> pMap = new HashMap<String, Integer>(); pMap.put("James", 5); pMap.put("Ram", 2); pMap.put("Aisha", 4); pMap.put("Tanya", 1); pMap.put("Iva", 3); Hospital hospital = new Hospital(); hospital.categorizePatients(pMap); hospital.displayPatients(); } } Choose the correct option.