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

Input Specification (for listings.txt) The first line of the file will contain a

ID: 3685734 • Letter: I

Question

Input Specification (for listings.txt) The first line of the file will contain a single positive integer n representing the number of properties listed. This will then be followed by n lines of data; each representing a single property. Each line of data will begin with an integer representing the listingID, a string representing the agent, an integer representing the cost of the property. This is followed by: the property size (an integer) Number of beds (an integer) Number of baths (a double) Year built (an integer) Address (a string, no longer than 30 characters long) The rest of the file is a series of lines each with a database operation to be executed. Each line begins with an integer from 1 – 6 inclusive, indicating the database operation to be executed. The numbers correspond to the list on the previous page. If the operation is (1), to add a property to the listings, then the line will contain the all of the listing information, in the order given above. If the operation is (2), to delete a listing, then the line will contain one other integer representing the listingID of the property to be deleted. If the operation is (3), to search for a listing by ID, then the line will contain one other integer representing the listingID of the property to be searched for. If the operation is (4), to search for a listing by price, then the line will contain an integer representing the maximum price of the properties to be searched for. If the operation is (5), to list all of properties under a given agent, then the line will contain the agent’s name after the operation number. If the operation is (6), to print all of the available properties, then that will be the only number on the line The input file ends with a 0. Implementation Restrictions a. #define ADD_LENGTH 30 (for address length) b. Each Listing must be implemented as a struct c. Each BST node should have a listing as its data d. Your program should be written using appropriate functions. e. Do not use global variables. Instead pass parameters to your functions. Remember that for functions that will be changing your BST, it (the BST), should be passed as a parameter by reference. f. Deletions of listings should be implemented using the successor algorithm. Sample Input File (library.txt) 6 121 Matt 205000 3000 3 2.0 2000 35 Blueberry Lane 163 Amy 450000 5000 5 5.5 2016 8885 Winter Garden Drive 116 Grant 375000 3000 3 2.0 2015 191 Oviedo Lakes 100 Linda 355000 4000 4 2.5 2014 79 Bradmore Lane 155 Amy 495000 3500 3 3.0 2012 52 Lenox Drive 280 Grant 950000 5000 5 6.5 2016 223 Willow Pines 6 1 119 Linda 985000 2950 2 2.0 2013 1200 Park Avenue 2 116 3 132 5 Amy 4 400000 6 0 Sample Output (corresponding to input file) LID Agent Price$K size Bd Bth Yr Address --------------------------------------------------------------------------------------- 100 Linda 355 4000 4 2.5 2014 79 Bradmore Lane 116 Grant 375 3000 3 2.0 2015 191 Oviedo Lakes 121 Matt 205 3000 3 2.0 2000 35 Blueberry Lane 155 Amy 495 3500 3 3.0 2012 52 Lenox Drive 163 Amy 450 5000 5 5.5 2016 8885 Winter Garden Drive 280 Grant 950 5000 5 6.5 2016 223 Willow Pines Listing 119 has been added to the database Listing 116 has been deleted from the database Listing 132 does not exist in the database LID Agent Price $K size Bd Bth Yr Address --------------------------------------------------------------------------------------- 155 Amy 495 3500 3 3.0 2012 52 Lenox Drive 163 Amy 450 5000 5 5.5 2016 8885 Winter GardenDrive LID Agent Price $K size Bd Bth Yr Address --------------------------------------------------------------------------------------- 100 Linda 355 4000 4 2.5 2014 79 Bradmore Lane 121 Matt 205 3000 3 2.0 2000 35 Blueberry Lane LID Agent Price $K size Bd Bth Yr Address ------------------------------------------------------------------------------------------- 100 Linda 355 4000 4 2.5 2014 79 Bradmore Lane 119 Linda 985 2950 2 2.0 2013 1200 Park Avenue 121 Matt 205 3000 3 2.0 2000 35 Blueberry Lane 155 Amy 495 3500 3 3.0 2012 52 Lenox Drive 163 Amy 450 5000 5 5.5 2016 8885 Winter GardenDrive 280 Grant 950 5000 5 6.5 2016 223 Willow Pines

Explanation / Answer

Input Specification (for listings.txt) package agentlisting; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.lang.Integer; import java.util.Iterator; import java.util.Scanner; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; import java.util.TreeSet; /** * * @author SuperMurray */ public class AgentListing { /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException { // Prompt for the input file name Scanner console = new Scanner(System.in); System.out.print("Input file: "); String inputFileName = console.next(); BufferedWriter pwfo = null; try { pwfo = new BufferedWriter(new FileWriter("C:\users\superman\desktop\agentReport.txt", true)); } catch (IOException e) { } PrintWriter pwo = new PrintWriter(pwfo); //Construct property type treeSet Set propertyTypes = pTypes(inputFileName); // Print property types from treeSet for (String type : propertyTypes) { System.out.println(type); pwo.println(type); } //pwo.flush(); //pwo.close(); //Construct agent ids and values treeSet Set agentRpt = agentValue(inputFileName); // Print agent Ids and values from key set for (String tail: agentRpt) { { System.out.println(tail); pwo.println(tail); } } pwo.flush(); pwo.close(); } /** Reads the input file. @param inputFileName @return the alphabetized property types in uppercase. */ public static Set pTypes(String inputFileName) throws FileNotFoundException //Construct a tree set to return property types { Set type = new TreeSet(); Scanner in = new Scanner(new File(inputFileName)); // Use delimiters to select specific chars for set in.useDelimiter("[1234567890. ]"); while (in.hasNext()) { type.add(in.next().toUpperCase()); } in.close(); return type; } /** Reads the input file. @param inputFileName @returns the Agent id's and corresponding property values. */ public static Set agentValue(String inputFileName) throws FileNotFoundException { TreeSet tail = new TreeSet(); SortedMap agentValues = new TreeMap(); Scanner in = new Scanner(new File(inputFileName)); String line = inputFileName; while (in.hasNextLine()) { try { line = in.nextLine(); String[] fields = line.split("[\s}]"); String agentId = (fields [3]); Double pValue = Double.parseDouble(fields [2]); if (agentValues.containsKey(agentId)) { pValue += agentValues.get(agentId).doubleValue(); } agentValues.put(agentId, pValue); }catch (Exception e) { } // Create keyMap with all keys and values Set keySet = agentValues.keySet(); for (String key : keySet) { Number value = agentValues.get(key); //System.out.println(key + ":" + value); tail.add(key + ":" + value); } } return tail; } }