Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am almost done with my project. however, the GUI won't display the wanted results. My program displays the following results below: When it should

I am almost done with my project. however, the GUI won't display the wanted results.

My program displays the following results below:

image text in transcribed

When it should be displaying this instead!!

image text in transcribed

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.

Management Company code:

public class ManagementCompany {

/** Attribute holds the total number of max properties. */

private final int MAX_PROPERTY = 5;

/** Attribute holds the management fee. */

private double mgmFee;

/** Attribute holds the name of the company */

private String companyName;

/** Attribute holds the total number of max properties allowed in the array. */

private Property[] properties = new Property[MAX_PROPERTY];

/** Attribute holds the taxID */

private String taxID;

/** Attribute creates a index variable to keep track of current index of properties array */

private int index = 0;

/**

* Constructor Creates a ManagementCompany object using the passed informations.

* @param companyName represents the name of the company.

* @param taxID represents the taxID.

* @param mgmFee represents the management fee.

*/

public ManagementCompany(String companyName, String taxID, double mgmFee) {

this.companyName = companyName;

this.taxID = taxID;

this.mgmFee = mgmFee;

}

/**

* Adds the property object to the "properties" array. It returns either -1 if the array is full or the index in the array where the property was added successfully.

* @param p is a property object.

* @return -1 if the array is full otherwise return index-1 of the array where the property was added.

*/

public int addProperty(Property p) {

//Check if index >= MAX_PROPERTY then the array is full, return -1

if (index >= MAX_PROPERTY) {

return -1;

}

else {

//store object to current index.

properties[index] = p;

//Increment index

index++;

//Return index-1 to return index where property was added.

return index-1;

}

}

/**

* Gets the total rent due

* @return the total amount of rent.

*/

public double totalRent() {

double totalRent = 0;

//Iterate through all the objects present in properties array and add all rents

for (int i = 0; i

totalRent += properties[i].getRentAmount();

}

return totalRent;

}

/**

* Displays information of the property at index i

* @param index The index of the property within the array "p"

* @return output which is the information of the property at index i.

*/

public String displayPropertyAtIndex(int i) {

//Create a string output and add values of properties array at given index

String output = properties[i].toString();

return output;

}

/**

* Gets the max number of properties.

* @return the max number of properties.

*/

public int getMAX_PROPERTY() {

return MAX_PROPERTY;

}

/**

* Method returns the index of the property with the maximum amount of rent.

* @return maxPropertyRentIndex which is the index of the property with the maximum rent amount.

*/

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

//If maxRent is

if (maxRent

maxRent = properties[i].getRentAmount();

maxRentIndex = i;

}

}

//return maxRentIndex;

return maxRentIndex;

}

/**

* Calculates and returns the management fee due.

* @return fee which is the calculated total management fee.

*/

public double calculateTotalFee()

{

double fee = 0;

for (int i = 0; i

{

fee += mgmFee * properties[i].getRentAmount() / 100;

}

return fee;

}

/**

* Displays all the information of all property in the output variable including the calculated fee.

* @return calculateTotalFee() and output.

*/

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

output += properties[i].toString() + " ";

}

return "List of the properties for, " + companyName +

", taxID: "+ taxID +

" -------------------------------------------------------- "+

output + " " + "------------------------------------------- total management Fee:" + calculateTotalFee();

}

}

Property code:

public class Property {

/** Attribute city holds the name of the city. */

private String city;

/** Attribute owner holds the name of the owner. */

private String owner;

/** Attribute propertyName holds the name of the property*/

private String propertyName;

/** Attribute rentAmount holds the total amount of rent. */

private double rentAmount;

/**

* Parametarized constructor class with default values such as propertyName, city, rentAmount, and owner.

* @param propertyName represents the name of the property.

* @param city represents the name of the city.

* @param owner represents the name of the owner.

* @param rentAmount represents the total amount of rent.

*/

public Property(String propertyName , String city, double rentAmount, String owner) {

this.propertyName = propertyName;

this.city = city;

this.owner = owner;

this.rentAmount = rentAmount;

}

/**

* copy constructor that creates a new object using the information of the object passed to it.

* @param p is used to create a new object and pass information to the object.

*/

public Property(Property p) {

this.propertyName = p.propertyName ;

this.city = p.city;

this.owner = p.owner;

this.rentAmount = p.rentAmount;

}

/**

* Setter method to set the name of the property.

* @param propertyName sets the name of the property.

*/

public void setPropertyName (String propertyName ) {

this.propertyName = propertyName ;

}

/**

* Gets the name of the property.

* @return the property's name.

*/

public String getPropertyName() {

return propertyName;

}

/**

* Gets the name of the city.

* @return the name of the city

*/

public String getCity() {

return city;

}

/**

* Setter method to set the name of the city.

* @param city holds the name of the city.

*/

public void setCity(String city) {

this.city = city;

}

/**

* Gets the owner's name.

* @return the name of the owner

*/

public String getOwner() {

return owner;

}

/**

* Setter method sets the name of the owner.

* @param owner holds the name of the owner.

*

*/

public void setOwner(String owner) {

this.owner = owner;

}

/**

* Gets the total amount of rent.

* @return the rentAmount

*/

public double getRentAmount() {

return rentAmount;

}

/**

* Setter method sets the total amount of rent.

* @param rentAmount holds the total amount of rent.

*/

public void setRentAmount(double rentAmount) {

this.rentAmount = rentAmount;

}

/**

* Returns all information of the property in a single string.

*@return propertyName, city, owner, and rentAmount.

*/

@Override

public String toString() {

return "Property name : " + getPropertyName() + " Located in " + getCity()+ " Belonging to : " + getOwner()

+ " Rent Amount : " + getRentAmount();

}

}

NO GUI code:

public class PropertyMgmDriverNoGui {

public static void main(String[] args) {

//Creates 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");

//Creates management company object

ManagementCompany m = new ManagementCompany("Alliance", "1235",6);

//Adds 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

//Displays the information of the property that has the maximum rent amount

System.out.println("The property with the highest rent: " + m.displayPropertyAtIndex(m.maxPropertyRentIndex()));

//Displays the total rent of the properties within the management company

System.out.println(" Total Rent of the properties: "+m.totalRent()+ " ");

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

}

}

GUI CODE:

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())

|| 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);

}

}

Management Company Total Rent of the properties: 2450.0 OK

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

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

Difference betweena hardware and software embedded system

Answered: 1 week ago