Advertisement
Guest User

Untitled

a guest
Jan 10th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1.  
  2. public class Main {
  3.  
  4.     public static void main(String[] args) {
  5.         House house = new House();
  6.        
  7.         house.sethouseNbr(1);
  8.         house.setaddress("Main Street 2");
  9.         house.setbuyingPrice(25500000);
  10.        
  11.         Apartment a1 = new Apartment(),
  12.                   a2 = new Apartment();
  13.        
  14.         a1.setNbr(1);
  15.         a1.setRentPerMonth(6300);
  16.         a1.setArea(40);
  17.         a2.setNbr(2);
  18.         a2.setRentPerMonth(8400);
  19.         a2.setArea(65);
  20.        
  21.         house.addApartment(a1);
  22.         house.addApartment(a2);
  23.        
  24.         house.updateRentPerMonth(1, 7000);
  25.     }
  26. }
  27.  
  28. import java.util.ArrayList;
  29.  
  30. public class House {
  31.  
  32.     private int houseNbr;
  33.     private String address;
  34.     private double buyingPrice;
  35.     private ArrayList<Apartment> myList = new ArrayList<Apartment>();
  36.    
  37.     public void updateRentPerMonth(int apartmenNbr, double newRent) {
  38.         Apartment a = findApartment(apartmenNbr);
  39.         if (a != null)
  40.             a.setRentPerMonth(newRent);
  41.     }
  42.  
  43.     public Apartment findApartment(int nbr) {
  44.         for (int i = 0; i < myList.size(); i++) {
  45.             Apartment temp = myList.get(i);
  46.             if (nbr == temp.getNbr())
  47.                 return temp;
  48.         }
  49.         return null;
  50.     }
  51.    
  52.     public double totalRentPerMonth() {
  53.         double totalRent = 0;
  54.         for (int i=0; i < myList.size(); i++)
  55.             totalRent += myList.get(i).getRentPerMonth();
  56.         return totalRent;
  57.     }
  58.    
  59.     public int area() {
  60.         int area = 0;
  61.         for (int i=0; i < myList.size(); i++)
  62.             area += myList.get(i).getArea();
  63.        
  64.         return area;
  65.     }
  66.  
  67.     public void addApartment(Apartment a) {
  68.         myList.add(a);
  69.     }
  70.  
  71.     public int gethouseNbr() {
  72.         return this.houseNbr;
  73.     }
  74.  
  75.     public String getaddress() {
  76.         return this.address;
  77.     }
  78.  
  79.     public double getbuyingPrice() {
  80.         return this.buyingPrice;
  81.     }
  82.  
  83.     public void sethouseNbr(int hnr) {
  84.         this.houseNbr = hnr;
  85.     }
  86.  
  87.     public void setaddress(String adr) {
  88.         this.address = adr;
  89.     }
  90.  
  91.     public void setbuyingPrice(double bpr) {
  92.         this.buyingPrice = bpr;
  93.     }
  94. }
  95.  
  96. public class Apartment {
  97.  
  98.     private int nbr;
  99.     private double rentPerMonth = 0;
  100.     private int area = 0;
  101.  
  102.     public double rentPerSqrm() {
  103.         return this.rentPerMonth / area;
  104.     }
  105.  
  106.     public double rentPerYear() {
  107.         return this.rentPerMonth * 12;
  108.     }
  109.  
  110.     public double getRentPerMonth() {
  111.         return this.rentPerMonth;
  112.     }
  113.  
  114.     public int getNbr() {
  115.         return this.nbr;
  116.     }
  117.  
  118.     public int getArea() {
  119.         return this.area;
  120.     }
  121.    
  122.     public void setNbr(int i) {
  123.         this.nbr = i;
  124.     }
  125.    
  126.     public void setRentPerMonth(double d) {
  127.         this.rentPerMonth = d;
  128.     }
  129.    
  130.     public void setArea(int a) {
  131.         this.area = a;
  132.     }
  133.  
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement