Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 5: Queries that use Select In FamilyRecordQuery.java uncomment the code required for Part 5 in the main method and the classes. As you noticed,

Part 5: Queries that use Select In FamilyRecordQuery.java uncomment the code required for Part 5 in the main method and the classes. As you noticed, the family has a lot of people named Robert and a lot of engineers. Use your selectIterative and selectRecursive to find these people in the family tree. To find all the Roberts, fix the SelectName class and search for the exact string Robert in the name field of the FamilyRecord. This must use selectIterative. To find all the Engineers, fix the SelectJob class and search for any text containing Engineer in the job field of the FamilyRecord. This must use selectRecursive. This query will output a list of many engineer types (people born in 1920 couldnt have been Software Engineers). Feel free to test our different names or jobs with these queries. To check your work, look at the displayed tree or the CVS file to see that the output is correct.

Reference Code:

FamilyRecordQuery.java

package queries;

import java.util.Iterator; import readers.LineFileReader; import iterators.Apply; import iterators.ApplyFunction; import binaryTree.BinaryTree; import iterators.Predicate; import iterators.ReduceFunction; import java.io.IOException; import java.util.List;

public class FamilyRecordQuery { public static void main(String[] args) throws IOException{ Iterator lines = new LineFileReader("familyrecord.csv"); Iterator recordsGeneric = new Apply<>(new ParseCSVLine(), lines); Iterator records = new Apply<>(new ConvertToRecord(), recordsGeneric); BinaryTree treeOfRecords = new BinaryTree(); BinaryTree treeOfNames = new BinaryTree(); while(records.hasNext()){ FamilyRecord record = records.next(); treeOfNames.insertNode(record.name); treeOfRecords.insertNode(record); } treeOfNames.displayTree();

//PART 3 int generationNumberB = 3; String ageGroupB = treeOfNames.reduceAtDepthRecursive(generationNumberB, new ConcatentateNames()); System.out.println("Generation " + generationNumberB + ": " + ageGroupB);

int generationNumberA = 4; String ageGroupA = treeOfRecords.reduceAtDepth(3, new ConcatenateNamesFromRecord()); System.out.println("Generation " + generationNumberA + ": " + ageGroupA);

//END PART 3 //PART 5 // List robertList = treeOfRecords.selectIterative(new SelectName("Robert")); // System.out.println(robertList); // List engineerList = treeOfRecords.selectRecursive(new SelectJob("Engineer")); // System.out.println(engineerList); //END PART 5

//Part 6 // List under50;

// //INSERT CODE HERE

// System.out.println(under50); }

private static class ConcatenateNamesFromRecord implements ReduceFunction{ //PART 3 }

private static class ConcatentateNames implements ReduceFunction{ //PART 3

} //PART 5 START // private static class SelectName implements Predicate{ // } // private static class SelectJob implements Predicate{ // }

//PART 5 END //PART 6 add new class here

//////////////// Dont edit after here ////////////////////// // Converts a CSV record from an Object[] to a FlightRecord private static class ConvertToRecord implements ApplyFunction { @Override public FamilyRecord apply(Object[] r) { return new FamilyRecord((String)r[0], (int)r[1], (String)r[2], (String)r[3], (String)r[4]); } } private static class ParseCSVLine implements ApplyFunction { @Override public Object[] apply(String x) { String[] fields = x.split(","); Object[] r = new Object[fields.length]; for (int i=0; i

private static class FamilyRecord { public final String name; public final int birthYear; public final String city; public final String state; public final String job; private FamilyRecord(String n, int y, String c, String s, String j) { name = n; birthYear = y; city = c; state = s; job = j; } @Override public String toString(){ return "Family record(Name=" + name + ", Birth Year=" + birthYear + ", City=" + city + ", State=" + state + ", Job=" + job + ")"; } }

}

familyRecord.cvs

Robert 2024 Seattle WA Student
Ryan 1994 Arlington Heights IL Software Engineer
Jisoon 1995 Dubuque IA Pharmacist
Robert 1963 Park Ridge IL Bio Medical Engineer
Angie 1964 Park Ridge IL Teacher
Boge 1963 East Dubque IL Computer Engineer
Jackie 1970 Bloomington IL Teacher
Robert 1930 Chicago IL Mechanical Engineer
Lee 1932 Chicago IL Homemaker
Mathew 1932 Chicago IL Dentist
Sandy 1936 Chicago IL Teacher
David 1938 Cedar Falls IA Farmer
Suki 1942 Orange CA Shop Owner
Michael 1939 Chicago IL Scientist
Amy 1942 Chicago IL Pharmacist
Carl 1915 New York NY Business
Betty 1920 Washington DC Homemaker
John 1921 Cedar Rapids IA Construction
Jane 1928 Chicago IL Homemaker
Peter 1916 Fargo ND Engineer
Stella 1917 Bismark ND Shop Owner
Nick 1917 Holmes OH Factory Worker
Ethal 1924 Ames IA Programmer
Joe 1922 Fort Wane IN Farmer
Mel 1920 Green Bay WI Chef
Mitch 1919 Chicago IL Inventor
Tara 1911 Desplaines IL Homemaker
Ted 1920 Vernon Hills IL Farmer
Tammy 1918 Springfield IL Seamstress
Chris 1926 Normal IL Farmer
Anna 1925 Traverse City MI Unknown

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

More Books

Students also viewed these Databases questions

Question

Explain Luther's view of vocation

Answered: 1 week ago