Question
Provided Files: ListADT OrderedListADT DoubleNode HousingOrderedListApplicationStart Lab Assignment: In this lab, you are going to store LivingSpace objects in the ordered list. The livinn space
Provided Files:
ListADT
OrderedListADT
DoubleNode
HousingOrderedListApplicationStart
Lab Assignment:
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.
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
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 void setNext(DoubleNode
/** * * 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
/** * * 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 jsjf;
/** * OrderedListADT defines the interface to an ordered list collection. Only * Comparable elements are stored, kept in the order determined by * the inherent relationship among the elements. * * @author Lewis and Chase * @version 4.0 */ public interface OrderedListADT
package jsjf;
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
/** * 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
/** * Returns a string representation of this list. * * @return a string representation of this list */ public String toString(); }
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