Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- House house = new House();
- house.sethouseNbr(1);
- house.setaddress("Main Street 2");
- house.setbuyingPrice(25500000);
- Apartment a1 = new Apartment(),
- a2 = new Apartment();
- a1.setNbr(1);
- a1.setRentPerMonth(6300);
- a1.setArea(40);
- a2.setNbr(2);
- a2.setRentPerMonth(8400);
- a2.setArea(65);
- house.addApartment(a1);
- house.addApartment(a2);
- house.updateRentPerMonth(1, 7000);
- }
- }
- import java.util.ArrayList;
- public class House {
- private int houseNbr;
- private String address;
- private double buyingPrice;
- private ArrayList<Apartment> myList = new ArrayList<Apartment>();
- public void updateRentPerMonth(int apartmenNbr, double newRent) {
- Apartment a = findApartment(apartmenNbr);
- if (a != null)
- a.setRentPerMonth(newRent);
- }
- public Apartment findApartment(int nbr) {
- for (int i = 0; i < myList.size(); i++) {
- Apartment temp = myList.get(i);
- if (nbr == temp.getNbr())
- return temp;
- }
- return null;
- }
- public double totalRentPerMonth() {
- double totalRent = 0;
- for (int i=0; i < myList.size(); i++)
- totalRent += myList.get(i).getRentPerMonth();
- return totalRent;
- }
- public int area() {
- int area = 0;
- for (int i=0; i < myList.size(); i++)
- area += myList.get(i).getArea();
- return area;
- }
- public void addApartment(Apartment a) {
- myList.add(a);
- }
- public int gethouseNbr() {
- return this.houseNbr;
- }
- public String getaddress() {
- return this.address;
- }
- public double getbuyingPrice() {
- return this.buyingPrice;
- }
- public void sethouseNbr(int hnr) {
- this.houseNbr = hnr;
- }
- public void setaddress(String adr) {
- this.address = adr;
- }
- public void setbuyingPrice(double bpr) {
- this.buyingPrice = bpr;
- }
- }
- public class Apartment {
- private int nbr;
- private double rentPerMonth = 0;
- private int area = 0;
- public double rentPerSqrm() {
- return this.rentPerMonth / area;
- }
- public double rentPerYear() {
- return this.rentPerMonth * 12;
- }
- public double getRentPerMonth() {
- return this.rentPerMonth;
- }
- public int getNbr() {
- return this.nbr;
- }
- public int getArea() {
- return this.area;
- }
- public void setNbr(int i) {
- this.nbr = i;
- }
- public void setRentPerMonth(double d) {
- this.rentPerMonth = d;
- }
- public void setArea(int a) {
- this.area = a;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement