Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 drivers 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.

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 managers 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.

The JUnit test class also tests the same classes as the driver and the GUI.

Specifications

Data Element -Property

The class Property will contain:

Instance variables for property name, city, rent amount and owner. Refer to JavaDoc for the data types.

toString method to represent a Property object.

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.

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.

Expected output from running

PropertyMgmDriverNoGui.java

image text in transcribedimage text in transcribed

/** * A test driver class. * * @author Professor khandan Monshi * */ 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 } }

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

/** *MgmCompanyGui, Class representing the GUI for company information * @author khandan Monshi */ import java.text.NumberFormat; import javax.swing.JOptionPane; //import MvGuiFx.ButtonEventHandler; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.TitledPane; import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.stage.Stage; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; public class MgmCompanyGui extends Application { private TextField mgmNametxt, mgmIdtxt, mgmFeetxt, propNametxt, propCitytxt, propRenttxt, propOwnertxt; private Label mgmNamelbl, mgmIdlbl, mgmFeelbl, propNamelbl, propCitylbl, propRentlbl, propOwnerlbl; private NumberFormat numFormat = NumberFormat.getNumberInstance(); private Button newMgmBtn, addPropertyBtn, maxRentBtn, totalRentBtn, propListBtn, exitBtn; private Alert alert = new Alert(AlertType.INFORMATION); private ManagementCompany mgmCompany; /** * * @return true if any of the field related to the property is empty, false otherwise */ private boolean propertyFieldsEmpty() { if ( propNametxt.getText().equals("") || propCitytxt.getText().equals("") || propRenttxt.getText().equals("") || propOwnertxt.getText().equals("") ) return true; return false; } /** * * @return true if any of the field related to the management company is empty, false otherwise */ private boolean mgmFieldsEmpty() { if ( mgmNametxt.getText().equals("") || mgmIdtxt.getText().equals("") || mgmFeetxt.getText().equals("") ) return true; return false; } /** * Creates a ManagementCompany object using information from the GUI and * sets the text fields to */ private void createNewMgm() { if (!mgmFieldsEmpty()) { // check if fee is valid (0-100) if (Double.parseDouble(mgmFeetxt.getText())  100) { alert.setContentText("Fee is not valid, Correct value is between 0-100"); alert.showAndWait(); } else { // Create management company object mgmCompany = new ManagementCompany(mgmNametxt.getText(), mgmIdtxt.getText(), Double.parseDouble(mgmFeetxt .getText())); //Enable Property buttons newMgmBtn.setDisable(true); addPropertyBtn.setDisable(false); maxRentBtn.setDisable(false); totalRentBtn.setDisable(false); propListBtn.setDisable(false); //set Management text fields to read only mgmNametxt.setEditable(false); mgmIdtxt.setEditable(false); mgmFeetxt.setEditable(false); newMgmBtn.setDisable(true); //set property text fields to editable propNametxt.setEditable(true); propCitytxt.setEditable(true); propRenttxt.setEditable(true); propOwnertxt.setEditable(true); } } } /** * Create a property object and calls mgmCompany method to add it to the list of properties. * If the property can not be added an error message will be displayed. */ private void addProp() { if (!propertyFieldsEmpty()) { Property p = new Property(propNametxt.getText(), propCitytxt.getText(), Double.parseDouble(propRenttxt .getText()), propOwnertxt.getText()); if (mgmCompany.addProperty(p) == -1) { alert.setContentText( "This Property can not be managed by this company. " + " The maximum capacity to manage for this company is : " + mgmCompany.getMAX_PROPERTY()); alert.showAndWait(); } } } private void setBlank() { propNametxt.setText(""); propCitytxt.setText(""); propRenttxt.setText(""); propOwnertxt.setText(""); } // Handler class. private class ButtonEventHandler implements EventHandler { @Override public void handle(ActionEvent e) { if (e.getSource() == newMgmBtn) { createNewMgm(); } else if (e.getSource() == addPropertyBtn) { addProp(); setBlank(); } else if (e.getSource() == maxRentBtn) { /*JOptionPane.showMessageDialog(null, mgmCompany.displayPropertyAtIndex(mgmCompany.maxPropertyRentIndex()));*/ alert.setContentText( mgmCompany.displayPropertyAtIndex(mgmCompany.maxPropertyRentIndex())); alert.showAndWait(); } else if (e.getSource() == totalRentBtn) { //JOptionPane.showMessageDialog(null,"Total Rent of the properties: "+mgmCompany.totalRent()); alert.setContentText( "Total Rent of the properties: "+mgmCompany.totalRent()); alert.showAndWait(); } else if (e.getSource() == propListBtn) { //JOptionPane.showMessageDialog(null,mgmCompany.toString()); alert.setContentText( mgmCompany.toString()); alert.showAndWait(); } else if (e.getSource() == exitBtn) System.exit(0); } } @Override public void start(Stage stage) { alert.setTitle("Management Company"); alert.setHeaderText(null); // Create management company labels mgmNamelbl = new Label("Name: "); mgmIdlbl = new Label("Tax Id:"); mgmFeelbl = new Label("Fee %:"); // create management company text fields mgmNametxt = new TextField(); mgmNametxt.setMaxWidth(100); mgmIdtxt = new TextField(); mgmIdtxt.setMaxWidth(80); mgmFeetxt = new TextField(); mgmFeetxt.setMaxWidth(40); // Create property labels propNamelbl = new Label("Property Name"); propCitylbl = new Label("City"); propRentlbl = new Label("Rent"); propOwnerlbl = new Label("Owner"); // create property text fields and set them to read only at the begining propNametxt = new TextField(); propNametxt.setEditable(false); propNametxt.setMaxWidth(100); propCitytxt = new TextField(); propCitytxt.setEditable(false); propCitytxt.setMaxWidth(80); propRenttxt = new TextField(); propRenttxt.setEditable(false); propRenttxt.setMaxWidth(80); propOwnertxt = new TextField(); propOwnertxt.setEditable(false); propOwnertxt.setMaxWidth(100); // Create buttons newMgmBtn = new Button("New Management Company"); addPropertyBtn = new Button("Add Property"); maxRentBtn = new Button("Max Rent"); totalRentBtn = new Button("Total Rent"); propListBtn = new Button("List of Properties"); exitBtn = new Button("Exit"); newMgmBtn.setOnAction(new ButtonEventHandler()); addPropertyBtn.setOnAction(new ButtonEventHandler()); maxRentBtn.setOnAction(new ButtonEventHandler()); propListBtn.setOnAction(new ButtonEventHandler()); totalRentBtn.setOnAction(new ButtonEventHandler()); exitBtn.setOnAction(new ButtonEventHandler()); // Disable some buttons addPropertyBtn.setDisable(true); maxRentBtn.setDisable(true); totalRentBtn.setDisable(true); propListBtn.setDisable(true); // Main Pane VBox mainPane = new VBox(); // Management company pane HBox mgmInfoPane = new HBox(5); // Add management company info to the pane mgmInfoPane.getChildren().addAll(mgmNamelbl, mgmNametxt, mgmIdlbl, mgmIdtxt, mgmFeelbl, mgmFeetxt); TitledPane mgmTitlePane = new TitledPane("Management Company", mgmInfoPane); mgmTitlePane.setCollapsible(false); mgmTitlePane.setMaxWidth(450); mgmTitlePane.setPadding(new Insets(20, 10, 5, 10)); // Create property pane VBox propPane = new VBox(); propPane.getChildren().addAll(propNamelbl, propNametxt, propCitylbl, propCitytxt, propRentlbl, propRenttxt, propOwnerlbl, propOwnertxt); TitledPane propertyTitlePane = new TitledPane("Property Information", propPane); propertyTitlePane.setCollapsible(false); propertyTitlePane.setMaxWidth(350); propertyTitlePane.setPadding(new Insets(5, 100, 10, 150)); // Create button pane HBox buttonPane1 = new HBox(20); buttonPane1.setAlignment(Pos.CENTER); buttonPane1.getChildren().addAll(newMgmBtn, addPropertyBtn,maxRentBtn); HBox buttonPane2 = new HBox(20); buttonPane2.setPadding(new Insets(10, 0, 10, 0)); buttonPane2.setAlignment(Pos.CENTER); buttonPane2.getChildren().addAll(totalRentBtn, propListBtn, exitBtn); mainPane.getChildren().addAll(mgmTitlePane, propertyTitlePane, buttonPane1, buttonPane2); Scene scene = new Scene(mainPane, 450, 400); stage.setScene(scene); // Set stage title and show the stage. stage.setTitle("Rental Management "); stage.show(); } public static void main(String[] args) { launch(args); } }

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

import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; import org.junit.Test; 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); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data 29th British National Conference On Databases Bncod 2013 Oxford Uk July 2013 Proceedings Lncs 7968

Authors: Dan Olteanu ,Georg Gottlob ,Christian Schallhart

2013th Edition

3642394663, 978-3642394669

More Books

Students also viewed these Databases questions

Question

What is a verb?

Answered: 1 week ago

Question

c. What groups were least represented? Why do you think this is so?

Answered: 1 week ago