JMU
logoHomeBase.gif
HomeBase


While the HomeBase system will ultimately be very extensive, the current task is fairly modest. You must design and implement some of the classes needed by the system to track information about apartments and houses.

Existing Components:
Jurisdictions: Enhanced Realty has an enum that contains/provides information about political jurisdictions that they use in all of their systems.
Jurisdiction ( Byte Code )

The documentation for this enum is available on-line.

New Components:
Textual Descriptions: The product design team collected the following textual descriptions of the components you need to design and implement.
Some Requirements:
Overview: Some requirements have already been specified by Enhanced Realty. You must incorporate them into your design and implementation.
General: In general, numbers must be non-negative int values, and all jurisdictions must be Jurisdiction objects.

In addition, functionality that is provided by the existing Jurisdiction enum must not be provided by any new classes/enums. So, for example, the tax rate must be obtained from the getTaxRate() method in Jurisdiction.

Arrays/Collections: The system must be able to handle at most 10000 properties. It must use an array (or arrays) to manage the properties; it must not use an ArrayList or other collection.
Information about a Property: Before it is wrapped, when information about a property is provided/presented using a String it must be organized in a very specific way. Specifically, it must be organized as follows. (Note: The line breaks below are only included for clarity of exposition and must not be included in the String):

Description at
space
Street Number
space
Street
space
City
space
State
space
Zip Code
space
Bathrooms:NumberOfBathrooms
space
Bedrooms:NumberOfBedrooms
space
AirConditioning:Yes|No
space
SchoolDistrict:SchoolDistrict
space
Jurisdiction:Jurisdiction
space
PropertyTax:PropertyTaxValue

where:

The Description varies by property type.

Yes|No indicates that this value should be denoted by either "Yes" or "No " (note the space).

Before the text if wrapped, the property tax value must be left-justified in a field that is 6 characters wide, must include a grouping character (i.e., a comma every three digits), must not include cents, and must be proceeded by a dollar sign.

Before the text is wrapped, all other numbers must be left-justified in a field that is 2 characters wide. Any negative number must be denoted by "NA".

After the text is wrapped, extraneous spaces must be removed. In other words, multiple spaces between words must be treated as a single delimiter.

Newline Characters: When information about a property is provided/presented it must be followed by two '\n' characters. The first will effectively terminate the last line and the second will effectively add a blank line. (The blank line will be particularly useful when information about multiple properties is being provided/presented.)
Requirements of the Driver: The driver must be a command-line application named HBDriver. It must be executable in the following way:
java HBDriver Width Indent Bedrooms Bathrooms [SchoolDistrict]

where Width is the width of the text output (ignoring any indentation), Indent is the number of spaces to indent each line, Bedrooms is the minimum number of bedrooms to search for, Bathrooms is the minimum number of bathrooms to search for, and SchoolDistrict is the (optional) school district to search for. (Note: The SchoolDistrict may contain multiple words, delimited by spaces. Hence, it can actually comprise multiple command line arguments.)

The driver must output (to standard out) the results of the search, with each line first formatted/wrapped to fit in a field of the appropriate width and then indented the appropriate number of spaces. Note: Given a width of 40 and an indent of 10, each line of output will be (at most) 50 characters wide. Similarly, given a width of 40 and an indent of 0, each line of the the resulting output will be (at most) 40 characters wide.

The driver must have the following structure:

import java.util.*;

/**
 * A driver that can be used to test the classes for HomeBase
 */
public class HBDriver
{
    /**
     * The entry point of the application.
     *
     * args[0] is required and contains the width of the output in characters
     * args[1] is required and contains the number of characters to indent
     * args[2] is required and contains the minimum number of bedrooms
     * args[3] is required and contains the minimum number of bathrooms
     *
     * args[4]...args[args.length-1] are optional and contain the 
     * (perhaps multiple) words in the school district
     *
     * @param args  The command line arguments
     */
    public static void main(String[] args)
    {
       int                    baths, beds, indent, width;       
       String                 indented, info, school, wrapped;

       // Process the command line arguments
       
       
       // Construct a ListingService object
    
       // Construct a house with the following attributes and
       // add it to the ListingService.
       //
       // Street Number: "128a"
       // Street: "Old Bridgewater Rd."
       // City: "Mt. Crawford"
       // State: "VA"
       // Zip Code: "22841"
       // Jurisdiction: Jurisdiction.ROCKINGHAM
       // Bathrooms: 2
       // Bedrooms: 3
       // AirConditioning: true
       // SchoolDistrict: "Turner Ashby"
       // LotSize: 25000
       // AssessedValue: 140000


    
       // Construct a house with the following attributes and
       // add it to the ListingService.
       //
       // Street Number: 1521
       // Street: "Paul St."
       // City: "Harrisonburg"
       // State: "VA"
       // Zip Code: "22801"
       // Jurisdiction: Jurisdiction.HARRISONBURG
       // Bathrooms: 3
       // Bedrooms: 4
       // AirConditioning: true
       // SchoolDistrict: "Harrisonburg"
       // LotSize: 9600
       // AssessedValue: 279000


    
       // Construct an apartment with the following attributes and
       // add it to the ListingService.
       //
       // Street Number: "184C"
       // Street: "Chestnut Ridge Dr."
       // City: "Harrisonburg"
       // State: "VA"
       // Zip Code: "22807"
       // Jurisdiction: Jurisdiction.HARRISONBURG
       // Bathrooms: 1
       // Bedrooms: 2
       // AirConditioning: true
       // SchoolDistrict: "Harrisonburg"
       // Complex: "The Greens"
       // Floor: 2


    
       // Construct an apartment with the following attributes and
       // add it to the ListingService.
       //
       // Street Number: "3424"
       // Street: "Town Court South"
       // City: "Staunton"
       // State: "VA"
       // Zip Code: "24401"
       // Jurisdiction: Jurisdiction.STAUNTON
       // Bathrooms: 2
       // Bedrooms: 2
       // AirConditioning: true
       // SchoolDistrict: "R.E. Lee"
       // Complex: "Avalon Run"
       // Floor: 2


    
       // Construct a house with the following attributes and
       // add it to the ListingService.
       //
       // Street Number: "5200"
       // Street: "Rt. 613"
       // City: "Mount Sidney"
       // State: "VA"
       // Zip Code: "24467-0001"
       // Jurisdiction: Jurisdiction.AUGUSTA
       // Bathrooms: 3
       // Bedrooms: 5
       // AirConditioning: false
       // SchoolDistrict: "Fort Defiance"
       // LotSize: 120000
       // AssessedValue: 450000

       
       if (school == null) 
           // Search ths ListingService just based on beds and baths
           // and assign the returned value to result.
           // For example: result = listings.search(beds, baths);
       else
           // Search ths ListingService based on beds, baths, and
           // school district and assign the returned value to result.
           // For example: result = listings.search(beds, baths, school);

       for (int i=0; i<result.length; i++)
       {
          // Get the necessary attributes of result[i]

          // Create a String named info with the attributes of result[i]
	  info = ...;

          // Format the result
          wrapped   = TextFormatter.wrap(info, width);
          indented  = TextFormatter.indent(wrapped, indent);

          // Print the formatted result
          System.out.print(indented + "\n\n");          
       }
    }
}
  
Initial Testing:
One Test Case: When the driver above is executed as follows:
      java HBDriver 60 0 2 2 R.E. Lee
      

it must generate the following output:

Apartment (on floor 2 in Avalon Run) at 3424 Town Court
South Staunton VA 24401 Bathrooms:2 Bedrooms:2
AirConditioning:Yes SchoolDistrict:R.E. Lee
Jurisdiction:Staunton PropertyTax:$0

      

Note that, for example, "Bathrooms:2" is followed by a single space even though the "2" was left-justified in a field of width 2 and, hence, was followed by two spaces before being wrapped (one to fill the field and another between it and the next field). This is because the two spaces were treated as a single delimiter when the text was wrapped.

Similarly, note that the extraneous spaces at the end of the property tax value were also removed when the text was wrapped.

Finally, note that there is not a newline character before the line containing the word "Apartment". (The apparent space is due to the way some browsers render WWW pages.)

Another Test Case: When the driver above is executed as follows:
      java HBDriver 40 0 2 2 Harrisonburg
      

it must generate the following output:

House (on a lot of 9600 sq ft) at 1521
Paul St. Harrisonburg VA 22801
Bathrooms:3 Bedrooms:4
AirConditioning:Yes
SchoolDistrict:Harrisonburg
Jurisdiction:Harrisonburg
PropertyTax:$2,232

      
A Third Test Case: When the driver above is executed as follows:
      java HBDriver 40 10 2 2
      

it must generate the following output:

          House (on a lot of 25000 sq ft) at 128a
          Old Bridgewater Rd. Mt. Crawford VA
          22841 Bathrooms:2 Bedrooms:3
          AirConditioning:Yes
          SchoolDistrict:Turner Ashby
          Jurisdiction:Rockingham
          PropertyTax:$1,050

          House (on a lot of 9600 sq ft) at 1521
          Paul St. Harrisonburg VA 22801
          Bathrooms:3 Bedrooms:4
          AirConditioning:Yes
          SchoolDistrict:Harrisonburg
          Jurisdiction:Harrisonburg
          PropertyTax:$2,232

          Apartment (on floor 2 in Avalon Run) at
          3424 Town Court South Staunton VA 24401
          Bathrooms:2 Bedrooms:2
          AirConditioning:Yes SchoolDistrict:R.E.
          Lee Jurisdiction:Staunton PropertyTax:$0

          House (on a lot of 120000 sq ft) at 5200
          Rt. 613 Mount Sidney VA 24467-0001
          Bathrooms:3 Bedrooms:5
          AirConditioning:No SchoolDistrict:Fort
          Defiance Jurisdiction:Augusta
          PropertyTax:$3,825

      
Some Design Considerations:
Design Objectives: The classes you design and implement may need to be used in a variety of different ways. Hence, they must be adequate, rugged, easy to repair and enhance, easy to understand and use, and easy to re-use.
Making Classes Cohesive: Your classes should be cohesive. That is, the parts of each class should be closely related to each other. As a result, it would be a mistake to include logic in the ListingService class for determining whether a property has a particular number of bedrooms and bathrooms. Instead, this logic should be included in one or more matches() methods in the class/classes that encapsulate the properties.
Some Advice:
General Advice: This is the first assignment this semester that requires you to do any design. Since it takes much more time to design classes than it does to implement them you should start early.

Also, from a grading perspective, the design portion of this assignment is as important as the implementation portion. You could easily receive a very low grade for a bad design, even if "it works" (i.e., even if it satisfies the requirements and does not violate any of the constraints). Hence, get feedback on your design before you start implementing it.

Order of Implementation and Testing: Though it is entirely up to you, you may want to consider implementing and testing components in the following order:
  1. The class/classes that encapsulate properties.
  2. The ListingService class.
    1. The constructor.
    2. The method(s) needed to add properties.
    3. The method(s) needed to get information about all of the properties. (Hint: You will need to construct an appropriately sized array, fill it, and return it.)
    4. The method(s) needed to search for properties. (Hint: You will probably need two loops.)
    5. Any other methods.
  3. The HBDriver class.

Test each class individually before moving on to the next one. To the extent possible, test each method in each class individually as well.

Copyright 2011