Question: X1038: Count J Names 7 public class Person private String name; public Person(String na) { this.name = na; 8 } 9 10 public String


X1038: Count "J" Names 7 public class Person private String name; public Person(String na) { this.name = na; 8 } 9 10 public String getName() 11 { return name; } 12 13 14 } The following method takes in a list of Person objects and should return the number of objects who's name starts with 'J'. However, some of the values in this list may be null. Write a loop to iterate over each Person to count if the first letter of the name (accessed by calling getName()) starts with the character '! But add in a check to make sure the object is not null, so that the method does not produce null pointer exceptions. Your Answer: 1 public int count]Names (List list) Feedback Your feedback will appear here when 3 int count = 0; 4 } return count; you check your answer. X1039: Find Last Negative Box The following question makes use of the generic Box class discussed in the reading assignment. 1 public static class Box { private T value; 4 5 public Box(T val) { 7 value = val; 8 } 9 10 11 { 12 13 14 } public T getValue() } return value; The method below takes in a list of Box objects, each containing an Integer value, and should return the index of the last box that contains a negative number. You can use a numeric for loop to iterate over the list in reverse order. The method should return -1 if the value is not found anywhere in the list. For example, consider this list. List arr = new List (); 5 3 arr.add(new Box ( 1)); arr.add(new Box (-2)); arr.add(new Box (-3)); arr.add(new Box ( 4)); // Box at index 0, contains 1 // Box at index 1, contains -2 // Box at index 2, // Box at index 3, A call to last NegativeBox() on this list should return 2. Your Answer: 1 public int last NegativeBox (List list) contains -3 contains 4 Feedback Your feedback will appear here when you check your answer. About Licence Privacy Contact
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
