Samorokimetal

PropertiesBook 22.11.2020

Nov 22nd, 2020 (edited)
469
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2.  
  3. public class PropertiesBook {
  4.     private ArrayList<Property> properties = new ArrayList<>();
  5.  
  6.     public Property findCheapestProperty() {
  7.         Property cheapestProperty = properties.get(0);
  8.         for (int i = 0; i < properties.size(); i++) {
  9.             if (properties.get(i).getPrice() < cheapestProperty.getPrice()) {
  10.                 cheapestProperty = properties.get(i);
  11.             }
  12.         }
  13.         return cheapestProperty;
  14.     }
  15.  
  16.     public ArrayList getProperties() {
  17.         return properties;
  18.     }
  19.  
  20.     public void addProperty(Property property) {
  21.         this.properties.add(property);
  22.     }
  23. }
RAW Paste Data