In: Computer Science
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, the owner's name, and the Plot to be occupied by the property, 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.
Write a Data Element Class named Plot that has fields specifying the X and Y location of the upper left corner of each Plot and a depth and width of each Plot. Notice that the X,Y location is at the upper left, not as in normal Cartesian coordinates, due to the grid system adopted by computer monitors.
A driver class is provided that creates rental properties to test the property manager. A Graphical User Interface is provided 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. A directory of images is provided. Be sure to place the “images” directory (provided) inside the “src” directory in Eclipse. The images do not need to display in order for the GUI to continue running.
Upload the initial files from Blackboard and your final java files to GitHub in your repo from Lab 1, in a directory named CMSC203_Assignment4.
Program Files
filename: Property.java
public class Property {
private String city, owner, propertyName;
private double rentAmount;
private Plot plot;
/**
* No-arg Constructor, creates a new object with default values of
empty strings,
* 0 for rent amount, and default Plot (sets the x, y values to
zero, depth and width to 1)
*/
public Property()
{
this.city = "";
this.owner = "";
this.propertyName = "";
this.rentAmount = 0.0;
this.plot = new Plot();
}
/**
* Copy Constructor, creates a new object using the information of
the object passed to it.
* @param propertyName
* @param city
* @param rentAmount
* @param owner
*/
public Property(String propertyName, String city, double
rentAmount, String owner)
{
this.propertyName = propertyName;
this.city = city;
this.rentAmount = rentAmount;
this.owner = owner;
this.plot = new Plot();
}
/**
* Parameterized Constructor, no Plot information provided
* @param propertyName
* @param city
* @param rentAmount
* @param owner
* @param x
* @param y
* @param width
* @param depth
*/
public Property(String propertyName, String city, double
rentAmount, String owner, int x, int y, int width, int depth)
{
this.propertyName = propertyName;
this.city = city;
this.rentAmount = rentAmount;
this.owner = owner;
this.plot = new Plot(x, y, width, depth);
}
/**
* Constructor, Parameterized constructor
* @param p
*/
public Property(Property p)
{
this.city = p.city;
this.owner = p.owner;
this.rentAmount = p.rentAmount;
this.propertyName = p.propertyName;
this.plot = new Plot(p.plot);
}
public String getCity()
{
return city;
}
public String getOwner()
{
return owner;
}
public String getPropertyName()
{
return propertyName;
}
public double getRentAmount()
{
return rentAmount;
}
//html file of this class online miss this method
public Plot getPlot()
{
return plot;
}
public Plot setPlot(int x, int y, int width, int depth)
{
return new Plot(x, y, width, depth);
}
public void setCity(String city)
{
this.city = city;
}
public void setOwner(String owner)
{
this.owner = owner;
}
public void setPropertyName(String propertyName)
{
this.propertyName = propertyName;
}
public void setRentAmount(double rentAmount)
{
this.rentAmount = rentAmount;
}
/**
* Prints out the name, city, owner and rent amount for a
property
* Overrides: toString in class java.lang.Object
*/
public String toString()
{
String toReturn = "Property Name: " + propertyName + "\nLocation: "
+ city + "\nBelonging to: " + owner +
"\nRent Amount: " + rentAmount;
return toReturn;
}
}
filename: Plot.java
public class Plot {
private int x, y, width, depth;
/**
* No-arg Constructor, creates a default Plot with args x=0, y=0,
width=1, depth=1
*/
public Plot()
{
x = 0;
y = 0;
width = 1;
depth = 1;
}
/**
* Copy Constructor, creates a new object using the information of
the object passed to it.
* @param x
* @param y
* @param width
* @param depth
*/
public Plot(int x, int y, int width, int depth)
{
this.x = x;
this.y = y;
this.width = width;
this.depth = depth;
}
/**
* Parameterized Constructor
* @param p
*/
public Plot (Plot p)
{
this.x = p.x;
this.y = p.y;
this.width = p.width;
this.depth = p.depth;
}
/**
* Determines if this plot overlaps the parameter
* @param p
* @return true if this plot overlaps the parameter, false
otherwise
*/
public boolean overlaps(Plot p)
{
boolean oneOverlapsXYone, oneOverlapsXYtwo, twoOverlapsXYone,
twoOverlapsXYtwo,threeOverlapsXYone
, threeOverlapsXYTwo, fourOverlapsXYone, fourOverlapsXYtwo;
oneOverlapsXYone = (p.x >= x && p.x < (x+width))
&& (p.y >= y && p.y < (y+depth));
oneOverlapsXYtwo = (x >= p.x && x < (p.x + width))
&& (y >= p.y && y < (p.depth + p.y));
twoOverlapsXYone = (p.x + p.width) > x && (p.x +
p.width) < (x + width) && p.y >= y && p.y
<= (y + depth);
twoOverlapsXYtwo = (x + width) > p.x && (x + width) <
(p.x + p.width) && y>= p.y && y <= (p.y +
p.depth);
threeOverlapsXYone = p.x >= x && p.x < (x + width)
&& (p.y + p.depth) > y && (p.y + p.depth) <=
(y + depth);
threeOverlapsXYTwo = x >= p.x && x < (p.x + p.width)
&& (y + depth) > p.y && (y + depth) <= (p.y +
p.depth);
fourOverlapsXYone = (p.x + p.width) > x && (p.x
+p.width) <= (x + width) && (p.y + p.depth) > y
&& (p.y + p.depth) <= (y + depth);
fourOverlapsXYtwo = (x + width) > p.x && (x + width)
<= (p.x + p.width) && (y + depth) > p.y && (y
+ depth) <= (p.y + p.depth);
return oneOverlapsXYone || oneOverlapsXYtwo || twoOverlapsXYone
|| twoOverlapsXYtwo || threeOverlapsXYone
|| threeOverlapsXYTwo || fourOverlapsXYone ||
fourOverlapsXYtwo;
}
/**
* Determines if this plot encompasses the parameter
* @param p
* @return Returns true if this plot encompasses the parameter,
false otherwise
*/
public boolean encompasses(Plot p)
{
boolean inX, inY, inWidth, inDepth;
inX = p.x >= x;
inY = p.y >= y;
inWidth = (p.x + p.width) <= (x + width);
inDepth = (p.y + p.depth) <= (y + depth);
return inX && inY && inWidth &&
inDepth;
}
public void setX(int x)
{
this.x = x;
}
public int getX()
{
return x;
}
public void setY(int y)
{
this.y = y;
}
public int getY()
{
return y;
}
public void setWidth(int width)
{
this.width = width;
}
public int getWidth()
{
return width;
}
public void setDepth(int depth)
{
this.depth = depth;
}
public int getDepth()
{
return depth;
}
public String toString()
{
String toReturn = "Upper Left: (" + x + "," + y + ")" +
" Width: " + width + " Depth: " + depth;
return toReturn;
}
}
filename: PlotTest.java
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class PlotTest {
private Plot plot1, plot2, plot3, plot4, plot5, plot6, plot7,
plot8, plot9,
plot10, plot11, plot12, plot13;
@Before
public void setUp() throws Exception {
plot1 = new Plot(12,12,6,6);
plot2 = new Plot(10,10,2,2);
plot3 = new Plot(11,11,3,2);
plot4 = new Plot(16,11,4,2);
plot5 = new Plot(13,14,4,3);
plot6 = new Plot(16,15,3,1);
plot7 = new Plot(11,16,3,3);
plot8 = new Plot(16,17,4,2);
plot9 = new Plot(11,14,2,1);
plot10 = new Plot(19,12,2,2);
plot11 = new Plot(12,12,3,2);
plot12 = new Plot(15,17,3,1);
plot13 = new Plot(15,17,3,1);
}
@After
public void tearDown() throws Exception {
plot1=plot2=plot3=plot4=plot5=plot6=plot7=plot8=plot9=plot10=plot11=plot12=plot13=null;
}
@Test
public void testOverlaps1() {
assertTrue(plot1.overlaps(plot11)); //plot11 is entirely inside
plot1
assertTrue(plot11.overlaps(plot1));
}
@Test
public void testOverlaps2() {
assertTrue(plot1.overlaps(plot3)); //plot3 overlaps the lower left
corner of plot1
assertTrue(plot3.overlaps(plot1));
assertTrue(plot1.overlaps(plot4)); //plot4 overlaps the lower right
corner of plot1
assertTrue(plot4.overlaps(plot1));
}
@Test
public void testOverlaps3() {
assertTrue(plot1.overlaps(plot7)); //plot7 overlaps the upper left
corner of plot1
assertTrue(plot7.overlaps(plot1));
assertTrue(plot1.overlaps(plot8)); //plot8 overlaps the upper right
corner of plot1
assertTrue(plot8.overlaps(plot1));
}
@Test
public void testOverlaps4() {
assertTrue(plot1.overlaps(plot9)); //plot9 overlaps the left side
of plot1
assertTrue(plot9.overlaps(plot1));
assertTrue(plot1.overlaps(plot6)); //plot6 overlaps the right side
of plot1
assertTrue(plot6.overlaps(plot1));
}
@Test
public void testOverlaps5() {
assertFalse(plot3.overlaps(plot9)); //plot9 does not overlap
plot3
assertFalse(plot9.overlaps(plot3));
assertFalse(plot5.overlaps(plot8)); //plot5 does not overlap plot8,
but partly share a side
assertFalse(plot8.overlaps(plot5));
}
@Test
public void testOverlaps6() {
assertFalse(plot3.overlaps(plot4)); //plot4 does not overlap
plot3
assertFalse(plot4.overlaps(plot3));
assertFalse(plot1.overlaps(plot10)); //plot1 does not overlap
plot10
assertFalse(plot10.overlaps(plot1));
assertFalse(plot2.overlaps(plot1)); //plot2 does not overlap
plot1
assertTrue(plot12.overlaps(plot13)); //plot12 is exactly the same
dimensions as plot13
}
@Test
public void testEncompasses1() {
assertTrue(plot1.encompasses(plot5)); //plot5 is contained in
plot1
assertFalse(plot5.encompasses(plot1));
assertTrue(plot1.encompasses(plot11)); //plot11 is contained in
plot1
assertFalse(plot11.encompasses(plot1));
assertTrue(plot1.encompasses(plot12)); //plot12 is contained in
plot1
assertFalse(plot12.encompasses(plot1));
assertFalse(plot2.encompasses(plot1));
assertFalse(plot3.encompasses(plot1)); //plot3 overlaps plat1
assertFalse(plot1.encompasses(plot3));
assertFalse(plot7.encompasses(plot8)); //plot7 overlaps plat8
assertFalse(plot8.encompasses(plot7));
}
@Test
public void testToString() {
assertEquals("Upper left: (12,12); Width: 6 Depth: 6",
""+plot1);
}
@Test
public void testGetWidth() {
assertEquals(2, plot2.getWidth());
}
@Test
public void testSetX() {
plot3.setX(22);
assertEquals(22, plot3.getX());
}
}
filename: Plot_GFA_Test.java
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class Plot_GFA_Test {
private Plot plot1, plot2;
@Before
public void setUp() throws Exception {
plot1 = new Plot(1,1,2,2);
plot2 = new Plot(2,1,2,2);
}
@After
public void tearDown() throws Exception {
plot1=plot2=null;
}
@Test
public void testOverlaps1() {
assertTrue(plot1.overlaps(plot2)); //plot2 overlaps the right side
of plot1
}
}
filename: PropertyMgmDriverNoGui.java
public class PropertyMgmDriverNoGui {
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
//Create property objects
Property p1 = new Property ("Belmar", "Silver Spring", 1200, "John
Smith",0,0,1,1);
Property p2 = new Property ("Camden Lakeway", "Rockville", 5000,
"Ann Taylor",1,1,1,1);
Property p3 = new Property ("Hamptons", "Rockville", 1250, "Rick
Steves",2,2,1,1);
Property p4 = new Property ("Mallory Square", "Wheaton", 1000,
"Abbey McDonald",3,3,1,1);
Property p5 = new Property ("Lakewood", "Rockville", 3000, "Alex
Tan",4,4,11,11);
//Create management company object
ManagementCompany m = new ManagementCompany("Alliance",
"1235",6,0,0,10,10);
//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)); //should display -3 to
indicate property plot is not contained in the MgmtCo plot
p5 = new Property ("Lakewood", "Rockville", 3000, "Alex
Tan",4,4,1,1);
System.out.println(m.addProperty(p5));
System.out.println(m.addProperty(p5)); //it should display -4 to
indicate the property is not added to the array due to size
//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.maxRentPropertyIndex()));
//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
}
}