Given1. public class Certification{2. private String name;3. private double price;4. 5. public Certification(String s,double d){6. name = s;7. price = d;8. }9. 10. public double getPrice(){11. return price;12. }13. 14. public String getName(){15. return name;16. }17. }18. 19. //Assume necessary imports have done20. 21. public class CertifyTest {22. 23. public static void main(String[] args) {24. 25. List<Certification> certs = new ArrayList<Certification>();26. 27. certs.add(new Certification("1Z0-803",120));28. certs.add(new Certification("1Z0-804",250));29. certs.add(new Certification("1Z0-805",175));30. certs.add(new Certification("1Z0-808",150));31. certs.add(new Certification("1Z0-810",225));32. 33. //insert here34. 35. for(Certification c : certs){36. if(filter.test(c)){37. System.out.println(c.getName());38. }39. }40. }41. 42. }Suppose we have to print only the certifications where price are higher than 180, which of the following insert at line 33 will achieve that?*Predicate<Certification> filter = (c) -> return c.getPrice() > 180;Predicate <Certification> filter = (c) -> {return c.getPrice() > 180;};Consumer <Certification> filter = () -> {return c.getPrice() > 180;};Consumer <Certification> filter = (c) -> {return c.getPrice() > 180;};Supplier <Certification> filter = (c) -> {return c.getPrice() > 180;};
Question
Given1. public class Certification{2. private String name;3. private double price;4. 5. public Certification(String s,double d){6. name = s;7. price = d;8. }9. 10. public double getPrice(){11. return price;12. }13. 14. public String getName(){15. return name;16. }17. }18. 19. //Assume necessary imports have done20. 21. public class CertifyTest {22. 23. public static void main(String[] args) {24. 25. List<Certification> certs = new ArrayList<Certification>();26. 27. certs.add(new Certification("1Z0-803",120));28. certs.add(new Certification("1Z0-804",250));29. certs.add(new Certification("1Z0-805",175));30. certs.add(new Certification("1Z0-808",150));31. certs.add(new Certification("1Z0-810",225));32. 33. //insert here34. 35. for(Certification c : certs){36. if(filter.test(c)){37. System.out.println(c.getName());38. }39. }40. }41. 42. }Suppose we have to print only the certifications where price are higher than 180, which of the following insert at line 33 will achieve that?*Predicate<Certification> filter = (c) -> return c.getPrice() > 180;Predicate <Certification> filter = (c) -> {return c.getPrice() > 180;};Consumer <Certification> filter = () -> {return c.getPrice() > 180;};Consumer <Certification> filter = (c) -> {return c.getPrice() > 180;};Supplier <Certification> filter = (c) -> {return c.getPrice() > 180;};
Solution
The correct answer is:
Predicate <Certification> filter = (c) -> {return c.getPrice() > 180;};
This is because we are using a Predicate, which is a functional interface that represents a boolean-valued function of one argument. In this case, the argument is a Certification object, and the function checks if the price of the Certification is greater than 180. The other options are incorrect because they use Consumer and Supplier, which are not suitable for this use case.
Similar Questions
Analyze the below program, and fill the correct code so that it produces the below output: 0 101class Book { private int bookId; private double bookPrice; public int getBookId() { return bookId; } public void setBookId(int bookId) { this.bookId = bookId; } public double getBookPrice() { return bookPrice; } public void setBookPrice(double bookPrice) { this.bookPrice = bookPrice; }}public class Test { public static void main(String a[]) { Book bobj=new Book(); blank blank blank }}Note : Same drag option can be used multiple times. Analyse and use the correct optionSystem.out.println(bobj.getBookPrice()); bobj.setBookId(101); System.out.println(bobj.getBookId());
Check the following Java program carefully. What should be written in the blank? Choose from the given options. public class Test { public static void main(String[] args) { System.out.print("The grade is " + getGrade(78.5)); System.out.print("\nThe grade is " + getGrade(59.5)); } public static ________ getGrade(double score) { if (score >= 90.0) return 'A'; else if (score >= 80.0) return 'B'; else if (score >= 70.0) return 'C'; else if (score >= 60.0) return 'D'; else return 'F'; }}Group of answer choicesvoidStringintchar
write a java program to define a class Item having item namepricequantityfind the total cost of the itemuse accept method to get the data from the user and toString method to display the detailscreate two objects and display the name of the item which is ordered more quantitydisplay total amount of items purchased.edited 10:37 AM
Given1. class Test{2. public static void main(String args[]){3. try{4. new Test().meth();5. }catch(ArithmeticException e){6. System.out.print("Arithmetic");7. }finally{8. System.out.print("final 1");9. }catch(Exception e){10. System.out.print("Exception");11. }finally{12. System.out.print("final 2");13. }14. }15. 16. public void meth()throws ArithmeticException{17. for(int x=0;x<5;x++){18. int y = (int)5/x;19. System.out.print(x);20. }21. }22. }What is the output?*Arithmetic final 2Arithmetic final 1ArithmeticCompilation fails.Exception final 2
Observe the below code. You have a class InsurancePolicy and another class VehicleInsurancePolicy that inherits InsurancePolicy.InsurancePolicy.javapublic class InsurancePolicy { private int policyNumber; private String holderName; private double amount; double calculateBonusAmount(){ //some logic return 0; } }VehicleInsurancePolicy.javaclass VehicleInsurancePolicy extends InsurancePolicy { private String vehicleNumber; private int noOfMonths; double calculateBonusAmount(){ //some logic return 0; }}Which access specifier can be given to the overridden method calculateBonusAmount.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.