Question
3. Create class LivingSpace base on the HousingOrderedListApplicationStart 4 .Use the provided Hosuing OrderedListApplication to create an ordered list of living spaces. In the provided
3. Create class LivingSpace base on the HousingOrderedListApplicationStart
4 .Use the provided HosuingOrderedListApplication to create an ordered list of living spaces. In the provided application complete methods to:
-create house and create apartament objects and store them in the list
-remove the first
-remove last
-display all living spaces in the list
package application
import collections.DoubleOrderedList; import exceptions.EmptyCollectionException; import exceptions.InvalidBathNumberException; import housing.Apartment; import housing.House; import housing.LivingSpace; import javafx.application.Application; import static javafx.application.Application.launch; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ScrollPane; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.layout.BorderPane; import javafx.scene.layout.GridPane; import javafx.stage.Stage; import javax.swing.JOptionPane;
public class HousingDoublyOrderedListApplicationStart extends Application {
private TextField addressTF = new TextField(); private TextField bedRTF = new TextField(); private TextField bathTF = new TextField(); private TextField sqftTF = new TextField(); private TextField priceTF = new TextField(); private TextField rentFeeTF = new TextField(); private Button apartmentBt = new Button("Add Apartment"); private Button houseBT = new Button("New House"); private Button removeFBT = new Button("Remove First"); private Button removeLBT = new Button("Remove Last"); private Button displayBT = new Button("Display Living Spaces");
private TextArea textArea = new TextArea();
/** * the LivingSpace list */ private final DoubleOrderedList housingList = new DoubleOrderedList(); @Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create the user interface GridPane infoPane = new GridPane(); infoPane.setHgap(5); infoPane.setVgap(5); infoPane.add(new Label("Address"), 0, 0); infoPane.add(addressTF, 1, 0); infoPane.add(new Label("# Bedrooms"), 0, 1); infoPane.add(bedRTF, 1, 1); infoPane.add(new Label("# Baths"), 0, 2); infoPane.add(bathTF, 1, 2); infoPane.add(new Label("Area"), 0, 3); infoPane.add(sqftTF, 1, 3); infoPane.add(new Label("Monthly Rent"), 0, 4); infoPane.add(rentFeeTF, 1, 4); infoPane.add(new Label("House Price"), 0, 5); infoPane.add(priceTF, 1, 5); GridPane buttonPane = new GridPane(); buttonPane.setHgap(15); buttonPane.setAlignment(Pos.CENTER); buttonPane.add(apartmentBt, 0, 0); buttonPane.add(houseBT, 1, 0); buttonPane.add(removeFBT, 2, 0); buttonPane.add(removeLBT, 3, 0); buttonPane.add(displayBT, 4, 0);
infoPane.setAlignment(Pos.CENTER); addressTF.setAlignment(Pos.BOTTOM_RIGHT); bedRTF.setAlignment(Pos.BOTTOM_RIGHT); bathTF.setAlignment(Pos.BOTTOM_RIGHT); sqftTF.setAlignment(Pos.BOTTOM_RIGHT); rentFeeTF.setAlignment(Pos.BOTTOM_RIGHT); priceTF.setAlignment(Pos.BOTTOM_RIGHT);
// Process events apartmentBt.setOnAction(e -> addApartment()); houseBT.setOnAction(e -> addHouse()); displayBT.setOnAction(e -> display()); removeFBT.setOnAction(e -> removeFirst()); removeLBT.setOnAction(e -> removeLast());
BorderPane pane = new BorderPane();
// Place nodes in the pane pane.setTop(infoPane); textArea.prefHeight(400); ScrollPane scrollPane = new ScrollPane(textArea); // scrollPane.setContent(textArea); scrollPane.setFitToWidth(true);
pane.setBottom(scrollPane); // pane.setLeft(new CustomPane("Left")); pane.setCenter(buttonPane); // Create a scene and place it in the stage Scene scene = new Scene(pane, 600, 400); primaryStage.setTitle("Housing Application"); // Set title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage
}
/** * creates an apartment object and adds to the list */ private void addApartment() { Apartment a = new Apartment(addressTF.getText(), Integer.parseInt(bedRTF.getText()), Double.parseDouble(bathTF.getText()), Integer.parseInt(sqftTF.getText()), Integer.parseInt(rentFeeTF.getText())); }
/** * creates a house object and adds to the list */ private void addHouse() { House h = new House(addressTF.getText(), Integer.parseInt(bedRTF.getText()), Double.parseDouble(bathTF.getText()), Integer.parseInt(sqftTF.getText()), Integer.parseInt(priceTF.getText())); }
/** * displays the living spaces stored in the list */ private void display() { textArea.setText("Available Housing "); textArea.setText("Animals "); textArea.appendText(housingList.toString()); textArea.appendText(" "); }
/** * Method remove removes a living space from the list */ private void removeFirst() { }
/** * Method remove removes a living space from the list */ private void removeLast() { }
private int getInteger(TextField t) { int num = 0;
try { String s = t.getText(); num = Integer.parseInt(s); } catch (NumberFormatException e) { System.out.println("enter proper integer"); } return num; }
/** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started