Objective
The Final Project aims to demonstrate your ability to analyze data
from a big database, exercise use of arrays of objects, external
classes, processing files and user interaction. For this project,
you will design and implement a program that analyzes baby name
popularities in data provided by the Social Security
Administration.
Every 10 years, the data gives the 1,000 most popular boy and girl
names for kids born in the United States. The data can be boiled
down to a single text file as shown below. On each line we have the
name, followed by the rank of that name in 1900, 1910, 1920, ...
2000 (11 numbers). A rank of 1 was the most popular name that year,
while a rank of 997 was not very popular. A 0 means the name did
not appear in the top 1,000 that year at all. The elements on each
line are separated from each other by a single space. The lines are
in alphabetical order, although we will not depend on
that.
…
Sam 58 69 99 131 168 236 278 380 467 408 466
Samantha 0 0 0 0 0 0 272 107 26 5 7
Samara 0 0 0 0 0 0 0 0 0 0 886
Samir 0 0 0 0 0 0 0 0 920 0 798
Sammie 537 545 351 325 333 396 565 772 930 0 0
Sammy 0 887 544 299 202 262 321 395 575 639 755
Samson 0 0 0 0 0 0 0 0 0 0 915
Samuel 31 41 46 60 61 71 83 61 52 35 28
Sandi 0 0 0 0 704 864 621 695 0 0 0
Sandra 0 942 606 50 6 12 11 39 94 168 257
...
The complete file is available through the name_data.txt
link.
Classes Required
NameRecord—encapsulates the data for one name: the name and its
rank over the years. This is essentially the data of one line from
the file shown above. Use an int array to store the int rank
numbers. The NameRecord constants START=1900 and DECADES=11 define
the start year and the number of decades in the data.
Methods:
Constructor—takes a String line as in the file above and sets up the NameRecord object.
String getName()—returns the name.
int getRank(int decade)—returns the rank of the name in the given decade. Use the convention that decade=0 is 1900, decade=1 is 1910, and so on.
int bestYear()—returns the year where the name was most popular, using the earliest year in the event of a tie. Looking at the data above Samir's best year is 2000, while Sandra's best year is 1940. Returns the actual year, for example 1920, so the caller does not need to adjust for START. It is safe to assume that no rank in the data is ever larger than 1100 and every name has at least one year with a non-zero rank.
void plot()—uses the StdDraw class to plot the popularity of the name over the 11 decades in a random color. Available colors are BLACK, BLUE, CYAN, DARK_GRAY, GRAY, GREEN, LIGHT_GRAY, MAGENTA, ORANGE, PINK, RED, WHITE, and YELLOW. You can scale the coordinate system appropriately, assuming that no rank is ever larger than 1100 and remembering that a rank of 1 should be on top of the image, while a rank of 1000 should be on the bottom. The StdDraw class can be downloaded. Documentation can be found online as well.
NameSurfer—the driver. The main method should read all of the data from the file and store it in an array of NameRecord objects. It should then offer the following menu to the user:
1 – Find the best year for a name
2 – Find the best rank for a name
3 – Plot the popularity of a name
4 – Clear the plot
5 – Quit
Enter your selection.
If 1, 2, or 3 is entered, the program should prompt the user for a name, search for that name in the array, print (or plot) the desired information, and display the menu again. If the name is not found in the array (search should ignore the case), print an error message and display the menu again.
If 4 is entered, clear the plot by calling StdDraw.clear();
The program quits only when the plot window is closed.
NOTE: Remember to keep your objects
encapsulated.
Formatting Requirements
Follow indentation rules as discussed in class.
Use descriptive variable names.
Comment your code: Your name, name of the class and assignment at the beginning of program, and description of program functionality at the beginning of program. Every method should have a comment with a short description on top. Every instance variable should be followed by a comment that describes it on the same line.
Assessment
Evaluation of project success will be determined by the following
criteria:
NameRecord class has the correct instance variables and constants
NameRecord constructor is implemented correctly
getName is implemented correctly
getRank is implemented correctly
bestYear is implemented correctly
plot is implemented correctly
driver correctly reads data from name_data.txt and stores it in array
driver prints user menu and reads user’s option
search for name is performed correctly
option 1 is handled correctly
option 2 is handled correctly
option 3 is handled correctly
option 4 is handled correctly
option 5 is handled correctly
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public category sound unit association guide = null;
public DB() catch (ClassNotFoundException e)
}
public ResultSet runSql(String sql) throws
SQLException {
Statement sta =
guide.createStatement();
return sta.executeQuery(sql);
}
public mathematician runSql2(String sql) throws
SQLException {
Statement sta =
guide.createStatement();
return sta.execute(sql);
}
@Override
protected void finalize() throws Throwable
!conn.isClosed()) {
conn.close();
}
}
4). produce a category with name "Main" which can be our
crawler.
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public category Main {
public static sound unit sound unit = new DB();
public static void main(String[] args) throws
SQLException, IOException URL is already in info
String sql = "select * from Record
wherever computer address = '"+URL+"'";
ResultSet rs = sound
unit.runSql(sql);
if(rs.next())else{
//store the
computer address to info to avoid parsing once more
sql = "INSERT
INTO `Crawler`.`Record` " + "(`URL`) VALUES " + "(?);";
PreparedStatement stmt = sound unit.conn.prepareStatement(sql,
Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, URL);
stmt.execute();
//get helpful
info
Document doc =
Jsoup.connect("http://www.mit.edu/").get();
if(doc.text().contains("research"))
//get all links
and recursively decision the processPage methodology
components queries = doc.select("a[href]");
for(Element
link: questions)
Get Answers For Free
Most questions answered within 1 hours.