Solution ----------- /20 public class BuildingList { private ----------- 1 Node head; public BuildingList() { null; ----------- 1 head = } ----------- /4 public void insertAtFront(Building b) { new ----------- 1 Node current = Node(); ----------- 1 current.setData(b); ----------- 1 current.setNext(head); ----------- 1 head = current; } ----------- /7 public int countBuildings(String o) { ----------- 1 Node current = head; int ----------- 1 nb = 0; while null) ----------- 1 (current != { if -------- 1 (current.getData().getOwnerName().equals(o)) ----------- 1 nb++; ----------- 1 current = current.getNext(); } return ----------- 1 nb; } ------- /7 public double BuildingList expensiveBuildings(int f, r) { new ----------- 1 BuildingList res = BuildingList(); ----------- 1 Node current = head; while null) ----------- 1 (current != { if ---- 1 (current.getData().mostExpensiveFlat(f).calculateRent()>r) 1 res.insertAtFront(current.getData());----------- ----------- 1 current = current.getNext(); } return ----------- 1 res; } }
Solution public class BuildingList { ----------- /20 private Node head; ----------- 1 public BuildingList() { head = null; ----------- 1 } public void insertAtFront(Building b) { ----------- /4 Node current = new Node(); ----------- 1 current.setData(b); ----------- 1 current.setNext(head); ----------- 1 head = current; ----------- 1 } public int countBuildings(String o) { ----------- /7 Node current = head; ----------- 1 int nb = 0; ----------- 1 while (current != null) { ----------- 1 if (current.getData().getOwnerName().equals(o)) -------- 1 nb++; ----------- 1 current = current.getNext(); ----------- 1 } return nb; ----------- 1 } public BuildingList expensiveBuildings(int f, double r) { ------- /7 BuildingList res = new BuildingList(); ----------- 1 Node current = head; ----------- 1 while (current != null) { ----------- 1 if (current.getData().mostExpensiveFlat(f).calculateRent()>r) ---- 1 res.insertAtFront(current.getData());----------- 1 current = current.getNext(); ----------- 1 } return res; ----------- 1 } }