Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am almost done with this java, but i am unable to create the object array... I

ID: 3681418 • Letter: I

Question

I am almost done with this java, but i am unable to create the object array... I havecreated most of the methods as well. I have 3 classes . the main class complete, I need help with data holder class. the just look the classes and you will understand it.

A property management company manages personal rental properties and charges them a management fee as the percentages of the rent amount. 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 properties handled by the company is 5.

Write a Data Manager Class named ManagementCompany that holds a list of properties in an array structure.   This class will have methods to add a Property object to the company list, find property that has the highest rent amount, find the total rent of the properties and show the information of all the properties and the management fee earned by the management company. Follow the Javadoc file provided.

Write a Data Element Class named Property that has fields to hold the property name, the city where the property is located, the rent amount, and the owner's name, along with getters and setters to access and set these fields. Write a parameterized constructor (i.e., takes values for the fields as parameters) and a copy constructor (takes a Property object as the parameter). Follow the Javadoc file provided.

Operation

When application starts, a driver class (provided) creates rental properties, adds them to the property manager, and prints information about the properties using the property manager’s methods.

Specifications

Data Element -Property

The class Property will contain:

Instance variables for property name, city, rent amount and owner.

toString method to represent a Property object. Refer to JavaDoc for the data types.

Constructors (a copy constructor and parameterized constructor) and getter and setter methods.

Data Structure – An Array of Property objects to hold the properties that the management company handles.

Data Manager – ManagementCompany, this class should not have any output functionality (e.g., no GUI-related or printing related functionality), but should take input, operate on the data structure, and return values or set variables that may be accessed with getters.

The class ManagementCompany will contain the following methods in addition to get and set methods:

Instance variables of name, tax Id, management fee, MAX_PROPERTY (a constant set to 5) and an array of size MAX_PROPERTY of Property objects.

Method managementCompany Constructor – pass in arguments for the name of the management company, tax Id and management Fee to create a ManagementCompany object.

Method addProperty – Pass in a parameter of type Property object. It will add the Property object to the properties array. It will return the index of the array where the property is added or -1 if the array is full.

Method totalRent– Returns the total rent of the properties in the properties array.

Method maxPropertyIndex- returns the index of the property within the properties array that has the highest rent amount. For simplicity assume that each "Property" object's rent amount is different.

Method displayPropertyAtIndex– pass in the index of the Property object in the properties array and return the string representation of the property.   

--------------------------------------------------

public class ManagementCompany {
private String campanyName;
private String taxID;
private double mgmFee;
private final int MAX_PROPERT=5;
private Property [] p;
public ManagementCompany(String name, String Id, double fee )
{

   p = new Property[5];

     
   campanyName=name;
   taxID=Id;
   mgmFee=fee;

}
public int getMAX_PROPERTY(){
       return MAX_PROPERT;
  
}

public int addProperty(Property property) {
     
   return 0;
   }

     
  
  

public double totalRent() {
   int total=0;
   for(int i=0;i<p.length;i++){
     
  
   }
  
       return total;
}

   public int maxPropertyRentIndex() {
         
       return 5;
   }

   public String displayPropertyAtIndex(int i) {
         
       return "";
      
   }
   public String toString(){
       return "abebe";
   }
}

----------------------------------------------------------------------------------------------------------------------------------------

public class PropertyMgmDriverNoGui {

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: " + m.displayPropertyAtIndex(m.maxPropertyRentIndex()));

//Display the total rent of the properties within the management company
System.out.println(" Total Rent of the properties: "+m.totalRent()+ " ");

System.out.println(m); //List the information of all the properties and the total management fee
}

}

-------------------------------------------------------------------------------------------------


//Parameterized constructor

public class Property {
private String propertyName;
private String cityName;
private double rentAmount;
private String ownerName;

   public Property(Property p) {
      
   }


public Property( String property, String city, double rent, String owner) {
propertyName=property;
cityName=city;
rentAmount=rent;
ownerName=owner;

}
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 null;
     
}
}


  
  

Explanation / Answer

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()+" ";

       }

       s+="Total management fee collected is "+calculateTotalFee()+" ";

       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;

   }

}

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