In: Computer Science
This is the requirement:
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.
A driver class is provided that creates rental properties to test the property manager. You are also to write a Graphical User Interface using JavaFX which duplicates this driver’s functionality. You are not required to read in any data, but the GUI will allow you to enter the property management company and each property by hand. << I ask about this in a separate question>>
Operation
When driver-driven 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.
When the GUI-driven application starts, a window is created as in the following screen shots which allows the user to enter applicable data. The driver and the GUI will both use the same classes for their operation. << I have not looked at this part as yet>>
The JUnit test class also tests the same classes as the driver and the GUI.
Specifications
Data Element -Property
The class Property will contain:
1. Instance variables for property name, city, rent amount and owner.
2. toString method to represent a Property object. Refer to JavaDoc for the data types.
3. 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:
1. 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.
2. Method managementCompany Constructor – pass in arguments for the name of the management company, tax Id and management Fee to create a ManagementCompany object.
3. 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.
4. Method totalRent– Returns the total rent of the properties in the properties array.
5. 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.
6. Method displayPropertyAtIndex– pass in the index of the Property object in the properties array and return the string representation of the property.
You may need additional methods to include in this class. Follow the Javadoc files provided.
User Interface – Your graphical user interface or the provided PropertyMgmDriverNoGui.java are the only classes that interact with the user. The GUI will have the general structure of the below screen shots
--------the code--------
provide by instructor..
/*
* A test driver class.
*/
//provided by the instructor
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:\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
}
}
------------
provided by instructor import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
//provided by the instructor
public class ManagementCompanyTest {
Property p1 ,p2,p3,p4,p5;
ManagementCompany m ;
@Before
public void setUp() throws Exception {
p1 = new Property ("Belmar", "Silver Spring", 1200.45, "John Smith");
p2 = new Property ("Camden Lakeway", "Rockville", 2450, "Ann Taylor");
p3 = new Property ("Hamptons", "Rockville", 1250, "Rick Steves");
m= new ManagementCompany("Alliance", "1235",6);
m.addProperty(p1);
m.addProperty(p2);
m.addProperty(p3);
}
@After
public void tearDown() {
p1=p2=p3=null;
m=null;
}
@Test
public void testAddProperty() {
p4 = new Property ("Mallory Square", "Wheaton", 1000, "Abbey McDonald");
p5 = new Property ("Lakewood", "Rockville", 3000, "Alex Tan");
assertEquals(m.addProperty(p4),3,0);
assertEquals(m.addProperty(p5),4,0);
assertEquals(m.addProperty(p1),-1,0); //exceeds the size of the array and can not be added, add property should return -1
}
@Test
public void testMaxPropertyRentIndex() {
assertEquals(m.maxPropertyRentIndex(),1,0);
}
@Test
public void testTotalRent() {
assertEquals(m.totalRent(),4900.45,0);
}
}
----------------
I coded this class
import java.text.DecimalFormat;
public class Property {
private java.lang.String city;
private java.lang.String owner;
private java.lang.String propertyName;
private double rentAmount;
public Property ()
{
city = "";
owner = "";
propertyName = "";
rentAmount = 0.0;
}
public Property (Property p)
{
propertyName = p.propertyName;
city = p.city;
rentAmount = p.rentAmount;
owner = p.owner;
}
public Property(java.lang.String propertyName, java.lang.String city, double rentAmount, java.lang.String owner) {
this.propertyName = propertyName;
this.city = city;
this.rentAmount = rentAmount;
this.owner = owner;
}
public void setLoc(String city) {
this.city = city;
}
public java.lang.String getPropertyName() {
return propertyName;
}
public java.lang.String getCity() {
return city;
}
public double getRentAmount() {
return rentAmount;
}
public void setRentAmount(double rentAmount) {
this.rentAmount = rentAmount;
}
public java.lang.String getOwner() {
return owner;
}
public void setOwner(java.lang.String owner) {
this.owner = owner;
}
public String toString() {
//Property name belonging to rent amount
return (this.propertyName + " belonging to " + this.owner + " rents for " + this.rentAmount);
}
}
---------
this is where I'm having trouble, loading up the values and formatting the printing....
import java.text.DecimalFormat;
public class ManagementCompany extends java.lang.Object{
private int MAX_PROPERTY = 5;
private double mgmFeePer;
private java.lang.String name;
private Property[] properties;
private java.lang.String taxID;
public ManagementCompany(java.lang.String name, java.lang.String taxID, int mgmFee) {
// TODO Auto-generated constructor stub
}
public int addProperty(Property p1) {
return MAX_PROPERTY;
// how do I load the properties to the array?
// TODO Auto-generated method stub
}
public String displayPropertyAtIndex(String string) {
// TODO Auto-generated method stub
return null;
}
public int getMAX_PROPERTY() {
return MAX_PROPERTY;
}
public String maxPropertyRentIndex() {
// TODO Auto-generated method stub
return null;
}
public String totalRent() {
// TODO Auto-generated method stub
return null;
}
public String toString() {
return ("List of the properties for Mananagemen Company, Alliance, taxid, 1235" + "I need to print the list of properties managed by that company" );
/* + "\nTITLE: " + this.title+ "\nAUTHOR: "+this.author + "\nTOTAL # OF RATINGS:" + sumofrating + "\nAVERAGE RATING: " + df.format(avgrating) + "\nPRICE: " + " $" + dollar.format(this.price) + "\nHARDCOVER: " +
this.cover + "\nRECOMMENDATIONS BASED ON BOOK RATINGS IS " + ratingmsg); */
}
}
----------my output current looks like :(( this--
-1
-1
-1
-1
-1
-1
Total Rent of the properties: null
List of the property
This is how the output should look
0
1
2
3
4
-1
The property what the highest rent:
Property Name:
Located:
Belonging to:
Rent Amount:
Total Rent of the properties: $$$$.$$
List of the properties for Alliance, Taxid: 12345
-----------------------------------------------------------
Property Name: " "
Located in:" "
Belonging to:" "
Rent Amount: "$$$$$"
Property Name: " " etc...repeated for max
-----------------------------------------------------------
total management Fee: $$$$
Property.java
public class Property {
private String city;
private String owner;
private String propertyName;
private double rentAmount;
public Property () {
city = "";
owner = "";
propertyName = "";
rentAmount = 0.0;
}
public Property (Property p)
{
propertyName = p.propertyName;
city = p.city;
rentAmount = p.rentAmount;
owner = p.owner;
}
public Property(String propertyName, String city, double rentAmount,String owner) {
this.propertyName = propertyName;
this.city = city;
this.rentAmount = rentAmount;
this.owner = owner;
}
public void setLoc(String city) {
this.city = city;
}
public String getPropertyName() {
return propertyName;
}
public String getCity() {
return city;
}
public double getRentAmount() {
return rentAmount;
}
public void setRentAmount(double rentAmount) {
this.rentAmount = rentAmount;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public String toString() {
//Property name belonging to rent amount
return "Property Name: "+this.propertyName+"\n"+
"Located: "+this.city+"\n"+
"Belonging to: "+this.owner+"\n"+
"Rent Amount: "+this.rentAmount;
}
}
ManagementCompany.java
public class ManagementCompany {
private int MAX_PROPERTY = 5;
private double mgmFee;
private String name;
private Property[] properties=new Property[MAX_PROPERTY];
private String taxID;
//Create a index variable to keep track of current index of properties array.
int index=0;
public ManagementCompany(String name, String taxID, int mgmFee) {
this.name=name;
this.taxID=taxID;
this.mgmFee=mgmFee;
}
public int addProperty(Property p1) {
//Check if index >= MAX_PROPERTY means array is full, return -1
if(index>=MAX_PROPERTY){
return -1;
}else{
//Else, store object to current index.
properties[index]=p1;
//Increment index to point to next location
index++;
//Return index-1 to return index where property was added.
return index-1;
}
}
public String displayPropertyAtIndex(int index) {
//Create a string output and add values of properties array at given index
String output=properties[index].toString();
return output;
}
public int getMAX_PROPERTY() {
return MAX_PROPERTY;
}
public int maxPropertyRentIndex() {
//Create variable maxRent to represent maximum rent
double maxRent=0;
//Create variable maxRentIndex to represent maximum rent index
int maxRentIndex=0;
//Iterate through all the objects present in properties array
for(int i=0;i<properties.length;i++){
//If maxRent is < current property, change max rent to current's property rent and maxRentIndex to current index.
if(maxRent<properties[i].getRentAmount()){
maxRent=properties[i].getRentAmount();
maxRentIndex=i;
}
}
//return maxRentIndex;
return maxRentIndex;
}
public double totalRent() {
double totalRent = 0;
//Iterate through all the objects present in properties array and add all rents
for(int i=0;i<properties.length;i++){
totalRent+=properties[i].getRentAmount();
}
return totalRent;
}
public String toString() {
String output="";
//Iterate through all the objects present in properties array and add information of all property in output variable.
for(int i=0;i<properties.length;i++){
output+=properties[i].toString()+"\n\n";
}
return ("List of the properties for Mananagemen Company, "
+ "Alliance, taxid, 1235\n-------------------------------------------\n"+output+"-------------------------------------------\ntotal management Fee:"+this.mgmFee);
}
}
OUTPUT-