Programming Concepts using Java, Quiz 2
Consider the Java code given below that should print the names of students whose grades are between 70.0 and 90.0 (both inclusive).
import java.util.*;class Student { String name; double grade; public Student(String n, double g) { name = n; grade = g; }}public class TestGrades { public static void main(String[] args) { List<Student> students = new ArrayList<>(); students.add(new Student("Anu", 85.5)); students.add(new Student("Bindu", 92.0)); students.add(new Student("Hari", 78.0)); students.add(new Student("David", 70.0)); students.add(new Student("Hasan", 65.0)); //CODE BLOCK }}Choose the correct option(s) to fill in place of CODE BLOCK to obtain the right answer.
Consider the Java code given below that should print the names of students whose grades are between 70.0 and 90.0 (both inclusive). import java.util.*; class Student { String name; double grade; public Student(String n, double g) { name = n; grade = g; } } public class TestGrades { public static void main(String[] args) { List<Student> students = new ArrayList<>(); students.add(new Student("Anu", 85.5)); students.add(new Student("Bindu", 92.0)); students.add(new Student("Hari", 78.0)); students.add(new Student("David", 70.0)); students.add(new Student("Hasan", 65.0)); //CODE BLOCK } } Choose the correct option(s) to fill in place of `CODE BLOCK` to obtain the right answer. Consider the code given below.\ interface Vehicle \{\ public abstract double getFuelEfficiency();\ \}\ class Car implements Vehicle, Cloneable \{\ protected double fuelCapacity;\ protected double mileage;\ public Car(double fuel, double m) \{\ fuelCapacity = fuel;\ mileage = m;\ \}\ public double getFuelEfficiency() \{\ return fuelCapacity \* mileage;\ \}\ public Car clone() throws CloneNotSupportedException \{\ return (Car) super.clone();\ \}\ \}\ class ElectricCar extends Car \{\ public ElectricCar(double batteryCapacity, double mileage) \{\ super(batteryCapacity, mileage);\ \}\ public ElectricCar clone() throws CloneNotSupportedException \{\ return (ElectricCar) super.clone();\ \}\ \}\ public class VehicleTest \{\ public static void main(String\[\] args) \{\ try \{\ ElectricCar e1 = new ElectricCar(50, 2);\ ElectricCar e2 = e1.clone();\ e1.fuelCapacity = 100;\ System.out.print(e1.getFuelEfficiency() + e2.getFuelEfficiency());\ \} catch (CloneNotSupportedException e) \{\ System.out.println("Cloning not supported");\ \}\ \}\ \}\ What will the output be? Consider the Java code given below. import java.util.*; public class PalindromeChecker { public static boolean isPalindrome(String str) { Stack<Character> s = new Stack<>(); Deque<Character> d = new ArrayDeque<>(); for (char ch : str.toCharArray()) { s.push(ch); d.add(ch); } // CODE BLOCK return true; } public static void main(String[] args) { String word1 = "level"; String word2 = "hello"; System.out.println("Is word1 a palindrome? " + isPalindrome(word1)); System.out.println("Is word2 a palindrome? " + isPalindrome(word2)); } } Choose the correct option to fill in place of `CODE BLOCK` so that the output is: Is word1 a palindrome? true Is word2 a palindrome? false Please note the following methods from type `Stack` and `Deque`: `pop()`: Removes the object at the top of this stack and returns it. `poll()`: Retrieves and removes the head of this deque, or returns null if empty. `peek()`: Retrieves, but does not remove, the head of this deque, or returns null if empty.