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: 666503 • 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. Think of possible classes that would be appropriate for this project.

http://www.nvcc.edu/home/dfranssell/CSC201/CSC201%20Realestate%20project.htm

Everything needed is in the link. You do not need the temperature and fraction demos. This program reads the text files Let me know if more info is needed. Thanks.

What I have thus far,


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)
   {  
       for(int x =1; x<=20; x++)
       {
       x =   
       }
       //*** 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)
   {
  
       return realEstateListingArray;
       //*** Creates an ArrayList of for this criteria.   
       //**Each criteria creates a list.  
   }
}

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.
       int homeCriterion = pickHomeCriterion();
       switch (homeCriterion)
       {
       case 1:// Style
           int style = getStyle();
           finalArrayListOfRealEstateListings = style(style, agencyArray);
           break;
       case 2://bedrooms
           int bedrooms = getBedRooms();
           finalArrayListOfRealEstateListings = bedrooms(bedrooms, 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.
       return answerSoFar;
   }
  

   private void getAgenciesForTheExhibition() {
       // TODO Auto-generated method stub
      
   }
   private int pickHomeCriterion() {
       int answer;
       Scanner scan = new Scanner(System.in);
       System.out.println("For this list of homes which real-estate agencies");
       System.out.println("would you like the home listings drawn from?");
       System.out.println("Please enter their numbers on one line");
       System.out.println("1) Century 21");
       System.out.println("2) ReMax");
       System.out.println("3) McEnearney");
       System.out.println("4) Long & Foster");
   answer = scan.nextInt();
       return answer;
   }
   public int getStyle()
   {
      
       return style;
   }
   private int getBedRooms() {
       // TODO Auto-generated method stub
       return 0;
   }
   public ArrayList<RealEstateListing> style(int styleType, ArrayList<Agency> agencyArray)
   {
       return finalArrayListOfRealEstateListings;
       //*** ask each agency to give a list that satisfies the requested style.
   }
   public ArrayList<RealEstateListing> bedrooms(int bedroomType, ArrayList<Agency> agencyArray)
   {
       return finalArrayListOfRealEstateListings;
       //*** 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.Scanner;
public class RealEstateListing
{
       //*** instance variables go here.
   private int houseNum;
   private String style;
   private int bedroomNum;
   private int bathroomNum;
   private double acres;
   private int age;
   private double price;
   private double distance;
   private String jurisdiction;
  
   public void readRealEstateListing(Scanner read)
   {
       //*** Read a listing.
       //*** Set the instance variables.   
       setStyle (read.nextLine());
       setBedroomNum (read.nextInt());
       setBathroomNum (read.nextInt());
       setAcres (read.nextDouble());
       setAge (read.nextInt());
       setPrice (read.nextDouble());
       setDistance (read.nextDouble());
       setJurisdiction (read.nextLine());
   }
   //*** I have a complete set of getters and setters created by Eclipse
  
   public String toString()
   {
       return houseNum + ")";
      
   }

   public int getHouseNum() {
       return houseNum;
   }

   public void setHouseNum(int houseNum) {
       this.houseNum = houseNum;
   }

   public String getStyle() {
       return style;
   }

   public void setStyle(String style) {
       this.style = style;
   }

   public int getBedroomNum() {
       return bedroomNum;
   }

   public void setBedroomNum(int bedroomNum) {
       this.bedroomNum = bedroomNum;
   }

   public int getBathroomNum() {
       return bathroomNum;
   }

   public void setBathroomNum(int bathroomNum) {
       this.bathroomNum = bathroomNum;
   }

   public double getAcres() {
       return acres;
   }

   public void setAcres(double acres) {
       this.acres = acres;
   }

   public int getAge() {
       return age;
   }

   public void setAge(int age) {
       this.age = age;
   }

   public double getPrice() {
       return price;
   }

   public void setPrice(double price) {
       this.price = price;
   }

   public double getDistance() {
       return distance;
   }

   public void setDistance(double distance) {
       this.distance = distance;
   }

   public String getJurisdiction() {
       return jurisdiction;
   }

   public void setJurisdiction(String jurisdiction) {
       this.jurisdiction = jurisdiction;
   }
}

import java.util.Scanner;
import java.io.*;
public class TextFileIO
{
   public static void main(String[] args)
   {
       String fileName = "textFile2.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;
   }

}

Explanation / Answer

package createhomelistmain;
import java.io.PrintWriter;
//CreateHomeListMain

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

public class CreateHomeListMain {

public static void main(String[] args) {

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

//Agency

package createhomelistmain;

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;
try (Scanner scanAgencyFile = TextFileIO.createTextRead(agencyFile)) {
readFile(scanAgencyFile);
scanAgencyFile.close();
}
}
public void readFile(Scanner read)
{
int numberOfHouses=read.nextInt();
RealEstateListing r1[]=new RealEstateListing[numberOfHouses];
for(int x =1; x<=20; x++)
{
r1[x]=new RealEstateListing();
r1[x].readRealEstateListing(read);
realEstateListingArray.add( r1[x]);
}
//*** The first number in the file is the number of listings.
//*** This sets the for loop
//*** A RealEstateListing can read itself.
read.close();
}
public ArrayList<RealEstateListing> style(String desiredStyle)
{
  
return realEstateListingArray;
//*** Creates an ArrayList of for this criteria.   
//**Each criteria creates a list.
}
}
//TextfileIO

package createhomelistmain;

import java.util.Scanner;
import java.io.*;
public class TextFileIO
{
public static void main(String[] args)
{
String fileName = "ReMax.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;
}

}
//RealEstateListing

package createhomelistmain;


import java.util.Scanner;
public class RealEstateListing
{
//*** instance variables go here.
private int houseNum;
private String style;
private int bedroomNum;
private int bathroomNum;
private double acres;
private int age;
private double price;
private double distance;
private String jurisdiction;
public RealEstateListing(){}
public void readRealEstateListing(Scanner read)
{
//*** Read a listing.
//*** Set the instance variables.   
setStyle (read.nextLine());
setBedroomNum (read.nextInt());
setBathroomNum (read.nextInt());
setAcres (read.nextDouble());
setAge (read.nextInt());
setPrice (read.nextDouble());
setDistance (read.nextDouble());
setJurisdiction (read.nextLine());
}
//*** I have a complete set of getters and setters created by Eclipse
  
public String toString()
{
return (this.houseNum+" "+this.style+" "+this.bedroomNum+" "+this.bathroomNum+
" "+this.acres+" "+this.age+" "+this.distance+" "+this.jurisdiction);
  
}
public int getHouseNum() {
return houseNum;
}
public void setHouseNum(int houseNum) {
this.houseNum = houseNum;
}
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
public int getBedroomNum() {
return bedroomNum;
}
public void setBedroomNum(int bedroomNum) {
this.bedroomNum = bedroomNum;
}
public int getBathroomNum() {
return bathroomNum;
}
public void setBathroomNum(int bathroomNum) {
this.bathroomNum = bathroomNum;
}
public double getAcres() {
return acres;
}
public void setAcres(double acres) {
this.acres = acres;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double getDistance() {
return distance;
}
public void setDistance(double distance) {
this.distance = distance;
}
public String getJurisdiction() {
return jurisdiction;
}
public void setJurisdiction(String jurisdiction) {
this.jurisdiction = jurisdiction;
}
}

//RealEstateagent

package createhomelistmain;

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.
int homeCriterion = pickHomeCriterion();
switch (homeCriterion)
{
case 1:// Style
int style = getStyle();
finalArrayListOfRealEstateListings = style(style, agencyArray);
break;
case 2://bedrooms
int bedrooms = getBedRooms();
finalArrayListOfRealEstateListings = bedrooms(bedrooms, 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.
return answerSoFar;
}
  
private void getAgenciesForTheExhibition() {
// TODO Auto-generated method stub
  
}
private int pickHomeCriterion() {
int answer;
Scanner scan = new Scanner(System.in);
System.out.println("For this list of homes which real-estate agencies");
System.out.println("would you like the home listings drawn from?");
System.out.println("Please enter the number (1/2/3/4)");
System.out.println("1) Century 21");
System.out.println("2) ReMax");
System.out.println("3) McEnearney");
System.out.println("4) Long & Foster");
answer = scan.nextInt();
return answer;
}
  
public int getStyle()
{
int style;
Scanner scan = new Scanner(System.in);
System.out.println("Choose the Style");
System.out.println("Please enter the number (1/2/3/4)");
System.out.println("1) Split Level");
System.out.println("2) Condominium");
System.out.println("3) Colonial");
System.out.println("4) Georgian");
System.out.println("5) Townhouse");
System.out.println("6) Ramble");
System.out.println("7) Cape Cod");
style= scan.nextInt();
return style;
}
private int getBedRooms() {
// TODO Auto-generated method stub
int rooms;
Scanner scan = new Scanner(System.in);
System.out.println("Enter the Number of Bedrooms");
rooms= scan.nextInt();
return rooms;
}
public ArrayList<RealEstateListing> style(int styleType, ArrayList<Agency> agencyArray)
{
if(styleType==1)
{
for(Agency aa: agencyArray)
       {
           //code here
       }
}
return finalArrayListOfRealEstateListings;
//*** ask each agency to give a list that satisfies the requested style.
}
public ArrayList<RealEstateListing> bedrooms(int bedroomType, ArrayList<Agency> agencyArray)
{
return finalArrayListOfRealEstateListings;
//*** 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.
}