Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Apartment {
- private String city;
- private String district;
- private String address;
- private double area;
- private double price;
- private double priceBySquareM;
- private boolean akt16;
- public Apartment(String city, String district, String address, double area, double price, boolean akt16) {
- this.city = city;
- this.district = district;
- this.address = address;
- this.area = area;
- this.price = price;
- this.akt16 = akt16;
- this.priceBySquareM = price / area;
- }
- public String getCity() {
- return city;
- }
- public void setCity(String city) {
- this.city = city;
- }
- public String getDistrict() {
- return district;
- }
- public void setDistrict(String district) {
- this.district = district;
- }
- public String getAddress() {
- return address;
- }
- public void setAddress(String address) {
- this.address = address;
- }
- public double getArea() {
- return area;
- }
- public void setArea(double area) {
- this.area = area;
- }
- public double getPrice() {
- return price;
- }
- public void setPrice(double price) {
- this.price = price;
- }
- public double getPriceBySquareM() {
- return priceBySquareM;
- }
- public void setPriceBySquareM(double priceBySquareM) {
- this.priceBySquareM = priceBySquareM;
- }
- public boolean isAkt16() {
- return akt16;
- }
- public void setAkt16(boolean akt16) {
- this.akt16 = akt16;
- }
- @Override
- public String toString() {
- return "Apartment{" +
- "city='" + city + '\'' +
- ", district='" + district + '\'' +
- ", address='" + address + '\'' +
- ", area=" + area +
- ", price=" + price +
- ", priceBySquareM=" + String.format("%.2f", priceBySquareM) +
- ", akt16=" + akt16 +
- '}';
- }
- }
- ////////////////////////////////////////////////////////////////
- import java.util.ArrayList;
- public class ApartmentMain {
- public static void main(String[] args) {
- Apartment apt1 = new Apartment("Sofia", "Lulin", "Zahari Stoqnov 16", 123, 200000, true);
- Apartment apt2 = new Apartment("Sofia", "Vitosha", "Sofronii Vrachanski 12", 212, 423197, true);
- Apartment apt3 = new Apartment("Varna", "Morski", "Hristo Botev 1", 78, 78000, false);
- Apartment apt4 = new Apartment("Burgas", "Morska gradina", "Hristofor Kolumb", 326, 303784, true);
- Apartment apt5 = new Apartment("Botevgrad", "Iztok", "Kolio Ficheto", 122, 70678, true);
- ArrayList<Apartment> apartments = new ArrayList<>();
- apartments.add(apt1);
- apartments.add(apt2);
- apartments.add(apt3);
- apartments.add(apt4);
- apartments.add(apt5);
- bubbleSort(apartments);
- for(Apartment apt: apartments){
- System.out.println(apt);
- }
- }
- public static void bubbleSort(ArrayList<Apartment> apartments) {
- for (int a = 1; a < apartments.size(); a++) {
- for (int b = 0; b < apartments.size() - a; b++) {
- if (((apartments.get(b).getPriceBySquareM())
- > ((apartments.get(b + 1).getPriceBySquareM())))) {
- Apartment temp = apartments.get(b);
- apartments.set(b, apartments.get(b + 1));
- apartments.set(b + 1, temp);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment