In: Computer Science
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
Project Contents Provided:- https://openload.co/f/9kXYDsV3w6A/Assignment_%234.zip
Assignment Document:- https://openload.co/f/PojQcH-X7Zo/Asgnmt4-F2018.docx
ManagementCompany.java
public class ManagementCompany {
private String campanyName;
private String taxID;
private double mgmFee;
private final int MAX_PROPERT = 5;
private Property[] p;
// added a private variable to keep the count of number of properties added
private int numProperties;
public ManagementCompany(String name, String Id, double fee) {
p = new Property[5];
campanyName = name;
taxID = Id;
mgmFee = fee;
numProperties = 0;
}
public int getMAX_PROPERTY() {
return MAX_PROPERT;
}
public int addProperty(Property property) {
if (numProperties < MAX_PROPERT) {
p[numProperties] = property;
numProperties++;
return 1;
}
// returning -1 if Property array is full and we are unable to add the
// new property
return -1;
}
public double totalRent() {
int total = 0;
for (int i = 0; i < numProperties; i++) {
total += p[i].getRentAmount();
}
return total;
}
public int maxPropertyRentIndex() {
int maxIndex = 0;
for (int i = 0; i < numProperties; i++) {
if (p[i].getRentAmount() >= p[maxIndex].getRentAmount()) {
maxIndex = i;
}
}
return maxIndex;
}
public String displayPropertyAtIndex(int i) {
if(i>numProperties-1)
{
return "Invalid index";
}
return p[i].toString();
}
public String toString() {
String s="";
for(int i=0;i<numProperties;++i)
{
s+=p[i].toString()+"\n";
}
s+="Total management fee collected is "+calculateTotalFee()+"\n";
return s;
}
private double calculateTotalFee()
{
double fee=0;
for(int i=0;i<numProperties;++i)
{
fee+=mgmFee*p[i].getRentAmount()/100;
}
return fee;
}
}
Property.java
public class Property {
private String propertyName;
private String cityName;
private double rentAmount;
private String ownerName;
public Property(Property p) {
this.cityName=p.getCity();
this.ownerName=p.getOwner();
this.propertyName=p.getPropertyName();
this.rentAmount=p.getRentAmount();
}
public Property(String property, String city, double rent, String owner) {
propertyName = property;
cityName = city;
rentAmount = rent;
ownerName = owner;
}
public String getPropertyName() {
return propertyName;
}
public void setPropertyName(String property) {
propertyName = property;
}
public String getCity() {
return cityName;
}
public void setCityName(String city) {
cityName = city;
}
public double getRentAmount() {
return rentAmount;
}
public void setRentAmount(double rent) {
rentAmount = rent;
}
public String getOwner() {
return ownerName;
}
public void setOwner(String owner) {
ownerName = owner;
}
public String toString() {
return "Property Name :"+propertyName+" City :"+cityName+" Rent :"
+rentAmount+" Owner :"+ownerName;
}
}
public class PropMgrDriverClass{
public static void main(String[] args) {
//Create property objects
Property p1 = new Property ("Belmar", "Silver Spring", 1200, "John
Smith");
Property p2 = new Property ("Camden Lakeway", "Rockville", 5000,
"Ann Taylor");
Property p3 = new Property ("Hamptons", "Rockville", 1250, "Rick
Steves");
Property p4 = new Property ("Mallory Square", "Wheaton", 1000,
"Abbey McDonald");
Property p5 = new Property ("Lakewood", "Rockville", 3000, "Alex
Tan");
//Create management company object
ManagementCompany m = new ManagementCompany("Alliance",
"1235",6);
//Add the properties to the list of properties of the management
company
System.out.println(m.addProperty(p1)); //Should add the property
and display the index where the property is added to the
array
System.out.println(m.addProperty(p2));
System.out.println(m.addProperty(p3));
System.out.println(m.addProperty(p4));
System.out.println(m.addProperty(p5));
System.out.println(m.addProperty(p5)); //it should display -1 to
indicate the property is not added to the array
//Display the information of the property that has the maximum
rent amount
System.out.println("The property with the highest rent:\n" +
m.displayPropertyAtIndex(m.maxPropertyRentIndex()));
//Display the total rent of the properties within the management
company
System.out.println("\nTotal Rent of the properties:
"+m.totalRent()+ "\n");
System.out.println(m); //List the information of all the
properties and the total management fee
}
}
Output:
1
1
1
1
1
-1
The property with the highest rent:
Property Name :Camden Lakeway City :Rockville Rent :5000.0 Owner :Ann Taylor
Total Rent of the properties: 11450.0
Property Name :Belmar City :Silver Spring Rent :1200.0 Owner :John Smith
Property Name :Camden Lakeway City :Rockville Rent :5000.0 Owner :Ann Taylor
Property Name :Hamptons City :Rockville Rent :1250.0 Owner :Rick Steves
Property Name :Mallory Square City :Wheaton Rent :1000.0 Owner :Abbey McDonald
Property Name :Lakewood City :Rockville Rent :3000.0 Owner :Alex Tan
Total management fee collected is 687.0