![]() |
Coding issues in creating program that selectively outputs data from a tex
Hi all,
I would greatly appreciate any help I could get with this program (which is described below) , together with the code I’ve written, as I’m getting a lot of errors in the code which suggests I’m seriously off track. Thanks very much. __________________________________________________________________________________ Program: The city periodically goes through its records and schedules property inspections (e.g., for lead or rodents). You will complete a Java application that reads a list of property data from a file and determines what kinds of inspections should be scheduled (if any). When properties contain multiple units (e.g., apartments), an inspection is scheduled for the entire building; however, the types of inspections are determined based on data concerning each unit. Output of the completed program should look like (sample run, user input in bold): Owner Street Unit Built Bill Jannings 1 College Way 2000 Danielle Parsons 1200 Beacon St. 7 1998 Terry Hawkings 1200 Beacon St. B 1999 Greg Royal 1200 Beacon St. 17 1998 Dennis Howe 15 Boltoph St. 1 1885 Soi Fong 15 Boltoph St. 2 1885 William Burrows 15 Boltoph St. 5 1885 Ken Dahal 247 Harvard Ave. 1899 Inspections: 1 College Way: 1200 Beacon St.: rodents 15 Boltoph St.: lead rodents 247 Harvard Ave.: lead Outline 1. Reads all property data from file (properties.txt) into array. 2. Displays property data: owner name, street address, unit (if any), and year built. 3. Displays the inspections scheduled for each building. Property Class The Property class represents data for a single property within the city. Data Members The code provided includes the following data members: • owner: owner’s name. • streetAddress: street address without the unit number. •unit: unit information (may be in various formats: “Unit #B”, “Apt. B”, etc.). • builtYear: year unit was built (or when building was built, if there aren’t separate units). Methods The code provided includes a default constructor as well as some accessors and mutators. You must complete 3 methods within the class (headers below): 1. Method to set the address: public void setAddress(String newAddress) This method should break the address passed into its street address and unit. Assume the unit (if any) follows a comma (,). If there is no unit listed, store the empty string as the unit. Look up appropriate String class methods to find the comma in a string, etc. 2. Constructor to initialize the object using the values passed: public Property(String initOwner, String initAddress, int initBuiltYear) This constructor should initialize all data members using its parameters. As part of its definition, call method setAddress (see above) to set the address, thus initializing the street address and unit members. Currently, the default constructor and “set” methods are used in method loadProperties [Inspections.java] to initialize each property record stored in an array. Change the code to instead use this constructor. 3. Method to extract the number (or letter, etc.) of the unit: public String getUnitNum() This method should return a string containing only the unit number. For example, units are stored in various ways within the property data file: Apt. 7, Unit #2, simply #17, or even just B. This method should not change how the unit is stored within the Property class, it should only extract and return the unit number (here, 7, 2, 17, and B) and returns it. This will again require using String class methods. Examine the property data file properties.txt to see all the formats used. This method is called from method displayProperties [Inspections.java]. Main Program (Class Inspections) The main program (class Inspections) is divided into methods. Notably, method loadProperties returns an array. Recall that a Java array is stored using a reference. A couple methods list throws clauses (throws FileNotFoundException) since opening a file may cause an exception that the code does not catch. As stated in 2. under “Methods” above, in method loadProperties, instantiate each Property object using the constructor (with arguments) that you wrote [Property.java]. Complete method scheduleInspections to display scheduled inspections for buildings. The method will not list inspections for every unit, only for each building (unique street address). Call that method from main. For example, reviewing the sample run: Owner Street Unit Built Bill Jannings 1 College Way 2000 Danielle Parsons 1200 Beacon St. 7 1998 Terry Hawkings 1200 Beacon St. B 1999 Greg Royal 1200 Beacon St. 17 1998 Dennis Howe 15 Boltoph St. 1 1885 Soi Fong 15 Boltoph St. 2 1980 William Burrows 15 Boltoph St. 5 1885 Ken Dahal 247 Harvard Ave. 1899 Inspections: 1 College Way: 1200 Beacon St.: rodents 15 Boltoph St.: lead rodents 247 Harvard Ave.: lead The schedule does not show “1200 Beacon St.” multiple times; instead it appears only once for its 3 units. Below outlines how method scheduleInspections displays output for each building only once: • Declares a variable to keep track of the last street address seen. • Loops through each of the properties. • If a property’s street address is the same as the last street address seen, then we must be in the same building (assumes property records for a particular building are contiguous). Note how it correctly compares strings. • If the street address changes, outputs the address of the building (right now it doesn’t output any inspections). You must add code to determine and output inspections as follows: • If any unit in a building was built before 1970, schedule a “lead” inspection. Add an appropriate constant. • If there is more than one unit in a building, schedule a “rodent” inspection. • Eliminate the spurious output that appears for the first property record. To determine these inspections, you must track the earliest (minimum) “year built” for each building (among all its units). In addition, your must count the number of units in a building. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- My ( error-filled ) code is as follows. It contains a parent (main) class called Inspections & a child class called Property . (a) Inspections (main): Code:
/*(b) Property (child) class: Code:
/* |
See:- http://www.codingforums.com/showthread.php?t=17515.
You will not get any reply in this forum which is intended to be used only to post a completed (working) script for showcasing/benefit of others. Also, this is the (Post A) JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! |
Moved to appropriate forum.
|
This is clearly a homework assignment. While we can assist you on homework assignments, we cannot just write the code and give it to you.
Please start by posting the errors themselves. Are the compilation errors or logical errors? If they are logical errors, post the input provided, the output received, the expected output. |
| All times are GMT +1. The time now is 07:00 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.