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

You are helping a friend, who is a real estate agent, maintain a list of houses

ID: 3625351 • Letter: Y

Question

You are helping a friend, who is a real estate agent, maintain a list of houses that are for sale in the Austin area. You have to define a class called House that has the following attributes and methods. The plus (+) sign indicates public and the (-) sign indicates private.
House
+address: Address
+area: int // area in square feet
+bedRooms: int // number of bedrooms
+bathRooms: int // number of bathrooms
+garage: int // number of cars in garage
+price: double // list (asking) price in dollars

+House() // default constructor
+House ( address: Address, area: int, bedRooms: int, bathRooms: int,
garage: int, price: double )
+toString(): String // string representation of a house object
+priceSqft(): double // price per square feet
You need a helper class called Address to represent the address of the houses. This class has the following structure:

Address
+street: String // house number and street name
+town: String // name of town or city
+state: String // two letter abbreviation of state
+zip: String // five digit zip code

+Address() // default constructor
+Address ( street: String, town: String, state: String, zip: String )
+toString(): String // string representation of address
You will need a class that maintains a list of houses. It also has methods to search for houses according to some criteria: by zip code, by price range, by range in square feet, and by the number of bedrooms. The structure for this class HouseList is as follows:

HouseList
-houseList: House[] // array of houses
-numHouses: int // number of houses on the list

+HouseList() // default constructor
+HouseList( n: int ) // creates an array of houses of size n
+getNumHouses (): int // get the number of houses on the list
+addHouse ( house: House ): void // adds a house to the list if
// it is not full
+searchByZip ( zip: String): void // prints the houses in that zip code
+searchByPrice ( lowPrice: double, highPrice: double ): void
// prints the houses in the price range
+searchByArea ( lowArea: int, highArea: int ): void
// prints the houses in that square feet
// range
+searchByRooms ( rooms: int ): void // prints the houses having that many
// bedrooms
Your main program will be called Realtor. You will be testing out the methods that you wrote for the classes Address, House, and HouseList. The structure for that class will be:

public class Realtor
{
public static void main ( String[] args )
{
// Create a HouseList object that can hold a hundred houses
...

// Populate the array with 10 houses. Makeup the data for these houses
...

// Write out the number of houses in your list
...

// Write out the houses in a certain zip code
...

// Write out the houses in a certain price range
...

// Write out the houses in a certain square foot range
...

// Write out the houses that have a certain number of bedrooms
...

}
}
The file that you will be turning in will be called Realtor.java. It should contain all the classes - Address, House, HouseList, and Realtor.

Explanation / Answer

import java.io.*;

class Address
{
    public String street;
    public String town;
    public String state;
    public String zip;
    public Address()
    {
         this.street="";
        this.state="";
        this.town="";
        this.zip="";
    }
    public Address(String street,String town,String state,String zip)
    {
        this.street=street;
        this.state=state;
        this.town=town;
        this.zip=zip;
    }
    public String toString()
    {
        return(street+" "+state+" "+town+" "+zip);
    }
}

class House
{
    public Address address;
    public int area;
    public int bedRooms;
    public int bathRooms;
    public int garage;
    public double price;
    public House()
    {
    }
    public House(Address address,int area,int bedRooms,int bathRooms,int garage,double price)
    {
        this.address.state=address.state;
        this.address.street=address.street;
        this.address.town=address.town;
        this.address.zip=address.zip;
        this.area=area;
        this.bathRooms=bathRooms;
        this.bedRooms=bedRooms;
        this.garage=garage;
        this.price=price;
    }
    public void setAddress(Address address)
    {
        this.address.state=address.state;
        this.address.street=address.street;
        this.address.town=address.town;
        this.address.zip=address.zip;

    }
    public String toString()
    {
        return(address.toString()+" "+area+" "+bedRooms+" "+bathRooms+" "+garage+" "+price);
    }

    public double priceSqft()
    {
        return(price);
    }
}

class HouseList
{
    House houseList[];
    int numHouses;
    public HouseList(){}
    public HouseList(int n)
    {
        numHouses=-1;
        houseList=new House[n];
    }
    public int getNumHouses()
    {
        return(numHouses);
    }
    public void addHouse(House h)
    {
        if(numHouses<houseList.length)
            houseList[++numHouses]=h;

    }
    public void searchByZip(String zip)
    {
        for(int i=0;i<numHouses;i++)
        {
            if(houseList[i].address.zip.equals(zip))
            System.out.println(houseList[i].toString());
        }
    }
    public void searchByPrice(double priceRange)
    {
        for(int i=0;i<numHouses;i++)
        {
            if(houseList[i].price<=priceRange)
            System.out.println(houseList[i].toString());
        }
    }

     public void searchByArea(int area)
    {
        for(int i=0;i<numHouses;i++)
        {
            if(houseList[i].area==area)
            System.out.println(houseList[i].toString());
        }
    }
     public void searchByRoom(int room)
     {
         for(int i=0;i<numHouses;i++)
        {
            if(houseList[i].bedRooms ==room)
            System.out.println(houseList[i].toString());
        }

     }
}

public class Realtor {
   
    public static void main(String[] args)throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        Address adr=new Address();
        HouseList hl=new HouseList(100);
        House h[]=new House[10];
        System.out.println("Enter House Details");
        for(int i=0;i<10;i++)
        {
           System.out.print("Enter Address Details for House"+(i+1));

           System.out.print("Street");
           adr.street=br.readLine();
           System.out.print("Town");
           adr.town=br.readLine();
           System.out.print("State");
           adr.state=br.readLine();
           System.out.print("Zip");
           adr.zip=br.readLine();
           h[i].setAddress(adr);
           System.out.print("Area:");
           h[i].area=Integer.parseInt(br.readLine());
           System.out.print("State:");
           h[i].bathRooms=Integer.parseInt(br.readLine());
           System.out.print("Bed ROoms:");
           h[i].bedRooms=Integer.parseInt(br.readLine());
           System.out.print("Garage:");
           h[i].garage=Integer.parseInt(br.readLine());
           System.out.print("Price");
           h[i].price=Double.parseDouble(br.readLine());
           hl.addHouse(h[i]);
        }
         //print number of houses
           for(int i=0;i<hl.getNumHouses();i++)
           {
              System.out.println( h[i].toString());
           }

        // Write out the houses in a certain zip code
            System.out.println("Enter Zip Code to search");
            hl.searchByZip(br.readLine());

        // Write out the houses in a certain price range
        System.out.println("Enter Price to search");
            hl.searchByPrice(Double.parseDouble(br.readLine()));

// Write out the houses in a certain square foot range
System.out.println("Enter Area to search");
            hl.searchByArea(Integer.parseInt(br.readLine()));

// Write out the houses that have a certain number of bedrooms
System.out.println("Enter bedrooms to search");
            hl.searchByRoom(Integer.parseInt(br.readLine()));

    }

}

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