Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Provided Files: ListADT OrderedListADT DoubleNode HousingOrderedListApplicationStart ( Livingspce calss is in HousingOrderedListApplicationStart so it need create the class base on the file) Lab Assignment (question

Provided Files:

ListADT

OrderedListADT

DoubleNode

HousingOrderedListApplicationStart ( Livingspce calss is in HousingOrderedListApplicationStart so it need create the class base on the file)

Lab Assignment (question Information):

In this lab, you are going to store LivingSpace objects in the ordered list. The livinn space objects will be sorted by the size.1. Write DoubleLinkedList class that implements the provided ListADT interface and java.lang.Iterable interface. Use the provided DoubleNode class to implement DoubleLinkedList class.

2. In the DoubleLinkedList class write a private inner class ListIterator that implements the Iterator interface. 2. Write OrderedDoubleLinkedList class that extends DoubleLinkedList class and implements the provided OrderedListADT.

3. Modify class LivingSpace so it implements interface Comparable. Add method compareTo to class LivingSpacel. Method compareTo compares two living spaces by their size in an increasing order. Method compareTo will be used in the add method in the OrderedDoubleLinkedList class. Method add in the OrderedDoubleLinkedList adds living spaces to the list in the order specified by the method compareTo in the LivingSpace class.

4.Use the provided OrderedListApplication 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....

import java.util.Iterator; import jsjf.exceptions.*; /** * ListADT defines the interface to a general list collection. Specific * types of lists will extend this interface to complete the * set of necessary operations. * @author Lewis and Chase * @version 4.0 */ public interface ListADT extends Iterable { /** * Removes and returns the first element from this list. * * @return the first element from this list */ public T removeFirst() throws EmptyCollectionException;

/** * Removes and returns the last element from this list. * * @return the last element from this list */ public T removeLast() throws EmptyCollectionException;

/** * Removes and returns the specified element from this list. * * @param element the element to be removed from the list */ public T remove(T element) throws EmptyCollectionException, ElementNotFoundException;

/** * Returns a reference to the first element in this list. * * @return a reference to the first element in this list */ public T first() throws EmptyCollectionException;

/** * Returns a reference to the last element in this list. * * @return a reference to the last element in this list */ public T last() throws EmptyCollectionException;

/** * Returns true if this list contains the specified target element. * * @param target the target that is being sought in the list * @return true if the list contains this element */ public boolean contains(T target) throws EmptyCollectionException;

/** * Returns true if this list contains no elements. * * @return true if this list contains no elements */ public boolean isEmpty();

/** * Returns the number of elements in this list. * * @return the integer representation of number of elements in this list */ public int size();

/** * Returns an iterator for the elements in this list. * * @return an iterator over the elements in this list */ public Iterator iterator();

/** * Returns a string representation of this list. * * @return a string representation of this list */ public String toString(); }

package collections;

class DoubleNode {

private DoubleNode next; private T element; private DoubleNode previous;

/** * * Creates an empty node. */ public DoubleNode() { next = null; element = null; previous = null; }

/** * * Creates a node storing the specified element. * * * @param elem the element to be stored into the new node */ public DoubleNode(T elem) { next = null; element = elem; previous = null; }

/** * * Returns the node that follows this one. * * * @return the node that follows the current one */ public DoubleNode getNext() { return next; }

/** * * Returns the node that precedes this one. * * * @return the node that precedes the current one */ public DoubleNode getPrevious() { return previous; }

/** * * Sets the node that follows this one. * * * @param dnode the node to be set as the one to follow the current one */ public void setNext(DoubleNode dnode) { next = dnode; }

/** * * Sets the node that precedes this one. * @param dnode the node to be set as the one to precede the current one */ public void setPrevious(DoubleNode dnode) { previous = dnode; }

/** * * Returns the element stored in this node. * @return the element stored in this node */ public T getElement() { return element; }

/** * * Sets the element stored in this node. * @param elem the element to be stored in this node */ public void setElement(T elem) { element = elem; } }

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

public interface OrderedListADT extends ListADT { /** * Adds the specified element to this list at the proper location * * @param element the element to be added to this list */ public void add(T element); }

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions