Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java You have been hired by the company Find Me A House Fast. Your job is to pro

ID: 3824605 • Letter: J

Question

Java

You have been hired by the company Find Me A House Fast. Your job is to produce a list of real-estate listings that meet a client's criterion. You have a list of real-estate listings from the companies: Century 21, ReMax, Mc Enearney and Long & Foster. The home buyer first chooses the real-estate companies he wishes to use. The home buyer then can choose one of the following criteria: Style, Number of Bedrooms, Lot Size, Age, Price, Distance from Work, and Jurisdiction. Given a criterion and the list of real-estate companies, your job is to create a list of home listings from the chosen companies that satisfy the chosen criterion.You have a list of home listings from each real-estate company from which to choose.

what I have so far

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class CreateHomeListMain {
   public static void main(String[] args) {
       // *** these lines print to a file and shows where to put listing files
       PrintWriter outStream = TextFileIO.createTextWrite("out.txt");
       outStream.println("hi");
       System.out.println("hi");
       outStream.close();
       RealEstateAgent myAgent = new RealEstateAgent();
       Scanner scan = new Scanner(System.in);
       System.out.println("I make lists.");
       System.out.println("Would you like to create a list?");
       System.out.println("Enter yes or no.");
       String choice = scan.nextLine();
       while (choice.equalsIgnoreCase("yes")) {
           String theHomeList = myAgent.listingsChosen();
           System.out.println(theHomeList);
           System.out.println("Would you like to create a new list");
           System.out.println("Enter yes or no.");
           choice = scan.nextLine();
       } // while
       System.out.println("Thank you for creating lists.");

   }
}

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Scanner;

public class RealEstateAgent // *** this is the largest class
{
   // *** ArrayLists that I used.
   private ArrayList<Agency> agencyArray = new ArrayList<Agency>();
   private ArrayList<RealEstateListing> listingsFromOneAgency = new ArrayList<RealEstateListing>();
   private ArrayList<RealEstateListing> finalArrayListOfRealEstateListings = new ArrayList<RealEstateListing>();
   private String answerSoFar = "";
   private Agency century21 = null;
   private Agency reMax = null;
   private Agency mcEnearney = null;
   private Agency longAndFoster = null;

   public RealEstateAgent() {
       // Create real-estate companies here.
       // Give them a name and pass in their text file.
       // Here is the code.
       century21 = new Agency("Century 21", "century21.txt");
       reMax = new Agency("ReMax", "remax.txt");
       mcEnearney = new Agency("McEnearney", "mcenearney.txt");
       longAndFoster = new Agency("LongAndFoster", "longandfoster.txt");

   }

   public String listingsChosen()
   {
       getAgenciesForTheExhibition();//*** this is an ArrayList
       //*** I read a String and used a Scanner instance to scan a string
//*** for the integers integers. See handout for an example of this.
       homeCriterion = pickHomeCriterion();
       switch (homeCriterion)
       {
       case 1:// Style
           int style = getStyle();
           finalArrayListOfRealEstateListings = style(style, agencyArray);
           break;
      
       default:
           System.out.println("bad topic Selection choice " + homeCriterion);
           System.exit(0);
       }// switch
   // *** I have a method that creates a string of the agencies used.
   // *** I have a method that takes the final list of homes
   // *** and puts them in a string that is returned.

   public int getStyle() {
   }

   public ArrayList<RealEstateListing> style(int styleType, ArrayList<Agency> agencyArray) {
       // *** ask each agency to give a list that satisfies the requested
       // style.
   }

   // *** For each criteria there are similar pairs of methods.
   // *** Work on each pair one pair at a time and make them
   // *** work before you do the next pair.
}

import java.util.ArrayList;
import java.util.Scanner;

public class Agency {
   private String agency;
   private ArrayList<RealEstateListing> realEstateListingArray = new ArrayList<RealEstateListing>();

   public Agency(String agency, String agencyFile) {
       // *** Constructor reads its file into an ArrayList
       // *** don’t forget to close the Scanner
       // *** Here is the code to read a file
       this.agency = agency;
       Scanner scanAgencyFile = TextFileIO.createTextRead(agencyFile);
       readFile(scanAgencyFile);
       scanAgencyFile.close();
   }

   public void readFile(Scanner read) {
       // *** The first number in the file is the number of listings.
       // *** This sets the for loop
       // *** A RealEstateListing can read itself.
   }

   public ArrayList<RealEstateListing> style(String desiredStyle) {
       // *** Creates an ArrayList of for this criteria.
       // *** Each criteria creates a list.
   }
}

public class RealEstateListing {
   // *** instance variables go here.

   public void readRealEstateListing(Scanner read) {
       // *** Read a listing.
       // *** Set the instance variables.
   }
   // *** I have a complete set of getters and setters created by Eclipse

   public String toString() {

   }
}

import java.util.Scanner;
import java.io.*;

public class TextFileIO {
   public static void main(String[] args)
    {
   String fileName = "textFile.txt";
    int x = 3;
   String line = null;
   int count;
   Scanner scan = new Scanner(System.in);
   PrintWriter textStream =TextFileIO.createTextWrite(fileName);
   System.out.println("Enter 4 lines of text:");
   for (count = 1; count <= 4; count++)
   {
       line = scan.nextLine();
       textStream.println(count + " " + line);
    }
   textStream.close( ); // did not require error handling
    System.out.println("Those lines were written to " + fileName);
    System.out.println();
    System.out.print("Now we will read them from " + fileName + " using the ");
    System.out.println("Scanner class." );
    Scanner scanFile = TextFileIO.createTextRead(fileName);// scan a file
    for (count = 1; count <= 4; count++)
   {
        count = scanFile.nextInt();
        line = scanFile.nextLine();
        System.out.println(count + line);
   }
    scanFile.close();

}

   public static PrintWriter createTextWrite(String S) {
       PrintWriter TStream = null;
       try {
           TStream = new PrintWriter(new FileOutputStream(S));
       } catch (FileNotFoundException e) {
           System.out.println("Error opening the file in createTextWrite");
           System.exit(0);
       }
       return TStream;
   }

   public static Scanner createTextRead(String S) {
       Scanner textFile = null;
       try {
           textFile = new Scanner(new File(S));
       } catch (FileNotFoundException e) {
           System.out.println("File not found");
           System.out.println("or could not be opened.");
       }
       return textFile;
   }

}

remax.txt

rest the text files are in this format

Output sample:

Explanation / Answer

I have gone through the code which you have provided in the question. the code needs many corrections and also the flow doesn't seem to be correct. So, I have created a code for your requirement after tallying from your code.

Refer the below code-


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
import ch03.houses.*;
import ch03.genericLists.*;

public class RealEstate
{
private static SortedList list = new SortedList();

private static JTextField lotText;
private static JTextField firstText;
private static JTextField lastText;   
private static JTextField priceText;
private static JTextField feetText;   
private static JTextField bedText;


private static JLabel statusLabel;

private static void showHouse(ListHouse house)
{
lotText.setText(Integer.toString(house.lotNumber()));
firstText.setText(house.firstName());
lastText.setText(house.lastName());
priceText.setText(Integer.toString(house.price()));
feetText.setText(Integer.toString(house.squareFeet()));
bedText.setText(Integer.toString(house.bedRooms()));
}

private static ListHouse getHouse()
{
String lastName;
String firstName;
int lotNumber;
int price;
int squareFeet;
int bedRooms;

lotNumber = Integer.parseInt(lotText.getText());
firstName = firstText.getText();
lastName = lastText.getText();
price = Integer.parseInt(priceText.getText());
squareFeet = Integer.parseInt(feetText.getText());
bedRooms = Integer.parseInt(bedText.getText());

ListHouse house = new ListHouse(lastName, firstName, lotNumber, price,
squareFeet, bedRooms);
return house;
}

private static void clearHouse()
{
lotText.setText("");
firstText.setText("");
lastText.setText("");
priceText.setText("");
feetText.setText("");
bedText.setText("");
}

private static class ActionHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
ListHouse house;

if (event.getActionCommand().equals("Reset"))
{
list.reset();
if (list.lengthIs() == 0)
clearHouse();
else
{
house = (ListHouse)list.getNextItem();
showHouse(house);
}
statusLabel.setText("List reset");
}
else
if (event.getActionCommand().equals("Next"))
{
if (list.lengthIs() == 0)
statusLabel.setText("list is empty!");
else
{
house = (ListHouse)list.getNextItem();
showHouse(house);
statusLabel.setText("Next house displayed");
}
}
else
if (event.getActionCommand().equals("Add"))
{
try
{
house = getHouse();
if (list.isThere(house))
statusLabel.setText("Lot number already in use");
else
{
list.insert(house);
statusLabel.setText("House added to list");
}
}
catch (NumberFormatException badHouseData)
{
statusLabel.setText("Number? " + badHouseData.getMessage());
}
}
else
if (event.getActionCommand().equals("Delete"))
{
try
{
house = getHouse();
if (list.isThere(house))
{
list.delete(house);
statusLabel.setText("House deleted");
}
else
statusLabel.setText("Lot number not on list");
}
catch (NumberFormatException badHouseData)
{
statusLabel.setText("Number? " + badHouseData.getMessage());
}
}
else
if (event.getActionCommand().equals("Clear"))
{
clearHouse();
statusLabel.setText(list.lengthIs() + " houses on list");
}
else
if (event.getActionCommand().equals("Find"))
{
int lotNumber;
try
{
lotNumber = Integer.parseInt(lotText.getText());
house = new ListHouse("", "", lotNumber, 0, 0, 0);
if (list.isThere(house))
{
house = (ListHouse)list.retrieve(house);
showHouse(house);
statusLabel.setText("House found");
}
else
statusLabel.setText("House not found");
}
catch (NumberFormatException badHouseData)
{
statusLabel.setText("Number? " + badHouseData.getMessage());
}
}
}
}

public static void main(String args[]) throws IOException

{
ListHouse house;
char command;
int length;

JLabel blankLabel; // To use up one frame slot

JLabel lotLabel; // Labels for input fields
JLabel firstLabel;
JLabel lastLabel;
JLabel priceLabel;
JLabel feetLabel;
JLabel bedLabel;

JButton reset; // Reset button
JButton next;   // Next button
JButton add; // Add button
JButton delete; // Delete button
JButton clear; // Clear button
JButton find; // Find button
ActionHandler action; // Declare listener

JFrame displayFrame = new JFrame();
displayFrame.setTitle("Real Estate Program");
displayFrame.setSize(350,400);
displayFrame.addWindowListener(new WindowAdapter() // handle window closing
{
public void windowClosing(WindowEvent event)
{
ListHouse house;
try
{
HouseFile.rewrite();
list.reset();
int length = list.lengthIs();
for (int counter = 1; counter <= length; counter++)
{
house = (ListHouse)list.getNextItem();
HouseFile.putToFile(house);
}
HouseFile.close();
}
catch (IOException fileCloseProblem)
{
System.out.println("Exception raised concerning the house info file "
+ "upon program termination");
}
System.exit(0); // Quit the program
}
});

Container contentPane = displayFrame.getContentPane();
JPanel infoPanel = new JPanel();

statusLabel = new JLabel("", JLabel.CENTER);
statusLabel.setBorder(new LineBorder(Color.red));
blankLabel = new JLabel("");
lotLabel = new JLabel("Lot Number: ", JLabel.RIGHT);
lotText = new JTextField("", 15);
firstLabel = new JLabel("First Name: ", JLabel.RIGHT);
firstText = new JTextField("", 15);
lastLabel = new JLabel("Last Name: ", JLabel.RIGHT);
lastText = new JTextField("", 15);
priceLabel = new JLabel("Price: ", JLabel.RIGHT);
priceText = new JTextField("", 15);
feetLabel = new JLabel("Square Feet: ", JLabel.RIGHT);
feetText = new JTextField("", 15);
bedLabel = new JLabel("Number of Bedrooms: ", JLabel.RIGHT);
bedText = new JTextField("", 15);

reset = new JButton("Reset");
next = new JButton("Next");
add = new JButton("Add");
delete = new JButton("Delete");
clear = new JButton("Clear");
find = new JButton("Find");

action = new ActionHandler();
reset.addActionListener(action);
next.addActionListener(action);
add.addActionListener(action);
delete.addActionListener(action);
clear.addActionListener(action);
find.addActionListener(action);

HouseFile.reset();
while (HouseFile.moreHouses())
{
house = HouseFile.getNextHouse();
list.insert(house);
}

list.reset();
if (list.lengthIs() != 0)
{
house = (ListHouse)list.getNextItem();
showHouse(house);
}

statusLabel.setText(list.lengthIs() + " houses on list ");

infoPanel.setLayout(new GridLayout(10,2));
infoPanel.add(statusLabel);
infoPanel.add(blankLabel);
infoPanel.add(lotLabel);
infoPanel.add(lotText);
infoPanel.add(firstLabel);
infoPanel.add(firstText);
infoPanel.add(lastLabel);
infoPanel.add(lastText);
infoPanel.add(priceLabel);
infoPanel.add(priceText);
infoPanel.add(feetLabel);
infoPanel.add(feetText);
infoPanel.add(bedLabel);
infoPanel.add(bedText);
infoPanel.add(reset);
infoPanel.add(next);
infoPanel.add(add);
infoPanel.add(delete);
infoPanel.add(clear);
infoPanel.add(find);

contentPane.add(infoPanel);
displayFrame.show();

}
}

Hope this will be the required answer.Have a nice day!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote