ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

A property management company manages individual properties they will build to rent

2022-04-05 07:00:06  阅读:258  来源: 互联网

标签:count management return int company param individual property properties


A property management company manages individual properties they will build to rent, and charges them a management fee as the percentages of the monthly rental amount. The properties cannot overlap each other, and each property must be within the limits of the management company's plot. Write an application that lets the user create a management company and add the properties managed by the company to its list. Assume the maximum number of properties handled by the company is 5

(由留学作业帮www.homeworkhelp.cc整理编辑)

Given:

A property management company manages individual properties they will build to rent, and charges them a management fee as the percentages of the monthly rental amount. The properties cannot overlap each other, and each property must be within the limits of the management company's plot. Write an application that lets the user create a management company and add the properties managed by the company to its list. Assume the maximum number of properties handled by the company is 5

Source Code:

import java.util.Arrays;

public class ManagementCompany {
private final int MAX_PROPERTY = 5;
private double mgmFeePer;
private String name;
private Property[] properties;
private String taxID;
private int MAX_WIDTH = 10, count = 0;
private int MAX_DEPTH = 10;
private Plot plot;

/**
* A No-Arg Constructor that creates a Management Company object.
*/
public ManagementCompany() {
properties = new Property[MAX_PROPERTY];
this.name = "";
this.taxID = "";
this.plot = new Plot(0, 0, MAX_WIDTH, MAX_DEPTH);
}

/**
* A management company parameterized constructor with a default company plot.
* @param name name of the company
* @param taxID taxID of the property
* @param mgmFeePer management fee
*/
public ManagementCompany(String name, String taxID, double mgmFeePer) {
properties = new Property[MAX_PROPERTY];
this.name = name;
this.taxID = taxID;
this.mgmFeePer = mgmFeePer;
this.plot = new Plot(0, 0, MAX_WIDTH, MAX_DEPTH);
}

/**
* Copy constructor creates a ManagementCompany object using another ManagementComapany object..
* @param otherCompany otherCompany is an object that is a copy
*/
public ManagementCompany(ManagementCompany otherCompany) {
properties = new Property[MAX_PROPERTY];
name = otherCompany.name;
taxID = otherCompany.taxID;
mgmFeePer = otherCompany.mgmFeePer;
plot = otherCompany.plot;
}

/**
* A management company parameterized constructor that sets the plot for the company.
* @param name
* @param taxID
* @param mgmFeePer
* @param x
* @param y
* @param width
* @param depth
*/
public ManagementCompany(
String name,
String taxID,
double mgmFeePer,
int x,
int y,
int width,
int depth
) {
properties = new Property[MAX_PROPERTY];
this.name = name;
this.taxID = taxID;
this.mgmFeePer = mgmFeePer;
this.plot = new Plot(x, y, width, depth);
}

/**
* A get method that returns the size of properties array.
* @return MAX_PROPERTY size of the array.
*/
public int getMAX_PROPERTY() {
return MAX_PROPERTY;
}

/**
* Adds a an already created property to the array.
* @param property
* @return
*/
public int addProperty(Property property) {
int i;

for (i = 0; i < count; i++) {
if (properties[i].getPlot().overlaps(property.getPlot())) return -4;
}
// if(property!=null)
// {
// properties[count]=property;
// count++;
// return count;
// }

if (count == MAX_PROPERTY) {
return -1;
}
if (property == null) {
return -2;
}
if (this.plot.encompasses(property.getPlot())) {
return -3;
} else {
properties[count] = property;
count++;
return count;
}
}

/**
* A method that adds the property with four arguments and a default plot to the array.
* @param name
* @param city
* @param rent
* @param owner
* @return
*/
public int addProperty(String name, String city, double rent, String owner) {
//create a property object.
Property property = new Property(name, city, rent, owner, 0, 0, 1, 1);
//adds the property object to properties array.
properties[count] = property;
count++;
int i;
for (i = 0; i < count; i++) {
if (properties[i].getPlot().overlaps(property.getPlot())) return -4;
}

if (count == MAX_PROPERTY) {
return -1;
}
if (this.plot.encompasses(property.getPlot())) {
//else if()
return -3;
} else {
properties[count] = property;
count++;
return count;
}
}

/**
* An add property that has all the parameters for the property and the plot.
* @param name
* @param city
* @param rent
* @param owner
* @param x
* @param y
* @param width
* @param depth
* @return
*/

public int addProperty(
String name,
String city,
double rent,
String owner,
int x,
int y,
int width,
int depth
) {
int i;
//Creates a property object that calls the constructor of Plot.
Property property = new Property(
name,
city,
rent,
owner,
x,
y,
width,
depth
);
//Adds the property object to the properties array.
properties[count] = property;

// create a plot
//Plot plot = new Plot(x,y, width, depth);

// Question is this the correct way of checking if the plot overlaps with the other property plots?????
for (i = 0; i < count; i++) {
if (properties[i].getPlot().overlaps(property.getPlot())) return -4;
}
if (count == MAX_PROPERTY) {
return -1;
} else if (this.plot.encompasses(property.getPlot())) {
return -3;
} else {
properties[count] = property;
count++;
return count;
}
}

/**
* A method that adds up all the amounts of rent.
* not finished yet.
*/
public double totalRent() {
double totalRent = 0.0;

for (int i = 0; i < count; i++) {
if (properties[i] != null) {
totalRent += properties[i].getRentAmount();
}
}
return totalRent;
}

public double maxPropertyRent() {
double maxRentAmount = 0.0;

maxRentAmount = properties[maxPropertyRentIndex()].getRentAmount();

return maxRentAmount;
}

public int maxPropertyRentIndex() {
int indexOFMaxRent = 0;

for (int i = 0; i < count; i++) {
if (properties[i] != null) {
if (
properties[indexOFMaxRent].getRentAmount() <
properties[i].getRentAmount()
) {
indexOFMaxRent = i;
}
}
}

return indexOFMaxRent;
}

public String displayPropertyAtIndex(int i) {
String str = "";
if (properties[i] != null) {
str =
(
"Owner: " +
properties[i].getOwner() +
"City: " +
properties[i].getCity() +
"Property Name: " +
properties[i].getPropertyName() +
"Rent Amount: " +
properties[i].getRentAmount() +
"Plot: " +
properties[i].getPlot()
);
}

return str;
}

public String toString() {
String printContent = "";
System.out.println("List of the properties for Alliance, taxID: " + taxID);

System.out.println("__________________");

for (int i = 0; i < count; i++) {
if (properties[i] != null) printContent =
(
" Property Name: " +
properties[i].getPropertyName() +
"\n" +
" Located in: " +
properties[i].getCity() +
"\n" +
" Belonging to: " +
properties[i].getOwner() +
"\n" +
" Rent Amount: " +
properties[i].getRentAmount()
);
}

System.out.println("__________________");
System.out.println("Total management Fee: " + mgmFeePer);

return printContent;
}
}

Rate this solution
thumb_down
thumb_up

标签:count,management,return,int,company,param,individual,property,properties
来源: https://www.cnblogs.com/coursehero/p/16101382.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有