Astrum96

Untitled

Dec 6th, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. public class Apartment {
  2.     private int rooms;
  3.     private int squareMeters;
  4.     private int pricePerSquareMeters;
  5.    
  6.     public Apartment(int rooms, int squareMeters, int pricePerSquareMeters) {
  7.       this.rooms = rooms;
  8.       this.squareMeters = squareMeters;
  9.       this.pricePerSquareMeters = pricePerSquareMeters;
  10.     }
  11.    
  12.     public boolean larger(Apartment otherApartment) { //87.1
  13.       if (this.rooms > otherApartment.rooms) {
  14.         return true;
  15.       }
  16.       return false;
  17.     }
  18.    
  19.     public int priceDifference(Apartment otherApartment) { //87.2
  20.       int thisPrice = this.squareMeters * this.pricePerSquareMeters;
  21.       int thatPrice = otherApartment.squareMeters * otherApartment.pricePerSquareMeters;
  22.      
  23.       if (thisPrice>thatPrice) {
  24.         return thisPrice-thatPrice;
  25.       } else {
  26.         return thatPrice-thisPrice;
  27.       }
  28.     }
  29.    
  30.     public boolean moreExpensiveThan(Apartment otherApartment)  { //87.3
  31.     int thisPrice = this.squareMeters * this.pricePerSquareMeters;
  32.       int thatPrice = otherApartment.squareMeters * otherApartment.pricePerSquareMeters;
  33.      
  34.       if (thisPrice>thatPrice) {
  35.         return true;
  36.       }
  37.       return false;
  38.     }
  39.  
  40. }
Add Comment
Please, Sign In to add comment