Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.5 kB
10
Indexable
Never
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java,util.Scanner;

public class Subdivision {
   private ArrayList<House> houses;
   
   public Subdivision() {
       houses = new ArrayList<>();
   }
   
   public boolean add(House h) {
       return houses.add(h);
   }
   
   public int size() {
       return houses.size();
   }
   
   public House find(String style) {
       for (House house : houses) {
           if (house.getStyle().equalsIgnoreCase(style)) {
               return house;
           }
       }
       return null;
   }
   public House get(int index) {
       return houses.get(index);
   }
   public ArrayList<House> listByArea(double floor, double ceiling) {
       ArrayList<House> result = new ArrayList<>();
       for (House house : houses) {
           double totalArea = house.getTotalArea();
           if (totalArea >= floor && totalArea <= ceiling) {
               result.add(house);
           }
       }
       return result;
   }
   public ArrayList<House> sortByArea() {
       ArrayList<House> sortedHouses = new ArrayList<>(houses);
       for (int i = 0; i < sortedHouses.size() - 1; i++) {
           int minIndex = i;
           for (int j = i + 1; j < sortedHouses.size(); j++) {
               if (sortedHouses.get(j).compareArea(sortedHouses.get(minIndex)) < 0) {
                   minIndex = j;
               }
           }
           House temp = sortedHouses.get(minIndex);
           sortedHouses.set(minIndex, sortedHouses.get(i));
           sortedHouses.set(i, temp);
       }
       return sortedHouses;
   }
   
   public ArrayList<House> sortByPlot() {
       ArrayList<House> sortedHouses = new ArrayList<>(houses);
       for (int i = 0; i < sortedHouses.size() - 1; i++) {
           int minIndex = i;
           for (int j = i + 1; j < sortedHouses.size(); j++) {
               if (sortedHouses.get(j).getPlot() < sortedHouses.get(minIndex).getPlot()) {
                   minIndex = j;
               }
           }
           House temp = sortedHouses.get(minIndex);
           sortedHouses.set(minIndex, sortedHouses.get(i));
           sortedHouses.set(i, temp);
       }
       return sortedHouses;
   }
   
   public boolean toDisk() {
	   
   }
   
   public boolean fromDisk() {
	   
   }

   
   public void remove(int position) {
	   houses.remove(position);

	   }
   
   public void update(int position, House houseToUpdate) {
	   remove(position);
	   houses.add(position, houseToUpdate);

	   }
   
}
Leave a Comment