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

Your program should give an introduction and then prompt the user for a first na

ID: 3677985 • Letter: Y

Question

Your program should give an introduction and then prompt the user for a first name. It should then read the name rank data file searching for that name, case-insensitively (that is, you should find the name regardless of the capitalization the user uses when typing it). If the name is found in the file, your program should print a line of statistics about that name's popularity in each decade, the name’s meaning and display information about the name graphically.  

This program allows you to search through the data from the Social Security Administration to see how popular a particular name has been since 1890.

Name: michelle Michelle f 0 0 0 0 0 728 174 39 4 10 22 52 125

MICHELLE f French, English French feminine form of MICHAEL

Input Data and Files:

Your program reads data from two files. Download them from our web site to the same folder as your program. 1.

names.txt: popularity rankings for each name 1890-2010 Each line of names.txt contains a name followed by that name's rank in 1890, 1900, 1910, etc. The default file has 13 numbers/line, so the last represents the ranking in 2010. Rank #1 was the most popular that year, while rank #999 was not popular. Rank 0 means the name did not appear in the top 1000.

For example:

Michelle f 0 0 0 0 0 728 174 39 4 10 22 52 125

Michelle m 0 0 0 0 0 0 0 0 736 897 0 0 0

Michial m 0 0 0 0 0 0 987 0 0 0 0 0 0   

"Michelle" as a female name first made the list in 1940 and peaked in 1970 at #4. It has been on a steady decline in popularity since. "Michial" only made the top-1000 in 1950. Once the user types a name, search each line of names.txt to see if it contains data for that name. If the name is found, output its data line to the console, then construct a DrawingPanel to graph the data (see next page). If the file includes two lines with the same name, your program should use the first. For example, the data above shows that "Michelle" can be both a male and female name but your program should only display information about the female name since it happens to come first in the file. Your code should not assume that the file is sorted alphabetically. If the name is not found, output a "not found" message and not show any data. No DrawingPanel should appear.

This program allows you to search through the

data from the Social Security Administration

to see how popular a particular name has been

since 1890.  

Name: zOIDberG

"zOIDberG" not found.

Though the data shown above has 13 decades' worth of rankings, your program should work properly with any number of decades of data (at least 1). Since there is a limit to the size of the DrawingPanel, you'd only be able to see data from 13 decades, but your code should process as many decades of data as it finds in the line. Do not assume that there will be exactly 13 decades when writing this program. On the course website is a file named names2.txt with 8 decades of data to help you test this behavior. 2. meanings.txt: descriptions of the meanings of each name If the name is found in names.txt, you should also read meanings.txt to find its meaning. The line containing the name's meaning should be printed to the console and also drawn on the DrawingPanel. Every name in names.txt is also in meanings.txt, so you do not need to worry about a name having rankings but no meaning data. Some names have long meanings that may stretch past the right edge of the DrawingPanel. Each line of meanings.txt contains a name in upper case, followed by the name's meaning.

For example:

MICHELLE f French, English French feminine form of MICHAEL

MICHELYNE f English (Modern) Pet form of MICHELLE

MICHI f Japanese Means "pathway" in Japanese.

MICHIAL m (no meaning found)

Though the two input files contain different data, the task of searching for a name in names.txt is very similar to the task of searching for a name in meanings.txt. Your code should take advantage of this fact and should avoid redundancy. You will be using several different Scanner objects for this program. You will have one Scanner that you use to read information from the console. You will use a different Scanner to read from each file. And because the input file is line-based, you should construct a different Scanner object for each line of the input file, as in section 6.3 of the book. You should write your code in such a way that you stop consuming lines of input once you find one that has the name you’re searching for.

Graphical Output:

The panel's overall size is 780x560 pixels. Its background is white. It has light gray (Color.LIGHT_GRAY) filled rectangles along its top and bottom with a black line at their bottom and top, respectively. The two rectangles are each 30 pixels tall and span across the entire panel, leaving an open area of 780x500 pixels in the middle. The line of data about the name's meaning appears in the top gray rectangle at (0, 16). Each decade is represented by a width of 60 pixels. The bottom light gray rectangle contains black labels for each decade, 8px from the bottom of the DrawingPanel. For example, with default constant values (see style guidelines), the text "1890" is at (0, 552) and "1910" is at (120, 552). Starting at the same x-coordinate, a bar shows the name ranking data for each year. The bars are blue for male names and pink for female names. Bars are half as wide as each decade (30px). The table at right shows the mapping between rankings and y-values of the tops of bars. Y-values start at 30 (below the top gray rectangle), and there is a vertical scaling factor of 2 between pixels and rankings; divide a ranking by 2 to get its y-coordinate.   At the same coordinate as the top-left of each bar, black text shows the name's rank for that decade. For example, Michelle was #4 in 1970, so "4" appears at (480, 32). A 0 rank means the name was not in the top 1000. No bar should appear in such a case, and "0" should be drawn right above the bottom gray bar. For example, in the screenshot above, Michelle's 0 in 1920 is drawn at (180, 530).

Implementation Guidelines:

We suggest you begin with the text output and file processing, then any "fixed" graphical output, and then the bars. The 0-ranking case is particularly tricky to draw, so you may want to do this last. (Hint: Treat rank 0 as a rank of 1000.) Your program should work correctly regardless of the capitalization the user uses to type the name. If the user types "LiSa" or "lisa", you should find it even though the input files have it as "Lisa" and "LISA". Draw text labels on the DrawingPanel using the drawString method of the Graphics object. To draw an int as text, you can convert it into a String using the + operator with an empty string. For example, for an int variable named n with value 100, the expression   "" + n   yields the String "100". To draw this at (50, 120), you could write:     g.drawString("" + n, 50, 120);

Stylistic Guidelines:

You should have at least these three class constants. If the constant values are changed, your output should adapt. • The starting year of the input data, as an integer (default of 1890) e.g. If you change the start year to 1825, the program should assume the data comes from 1825, 1835, etc. • The width of each decade on the DrawingPanel, as an integer (default of 60) e.g. If you change the width to 50, each pink or blue decade bar is 50px apart and 25px thick.   • The height of the legend rectangles, as an integer (default of 30) e.g. If you change the legend height to 20, the gray rectangles at top and bottom are 20px tall. The panel is 540px tall so that the open area in the middle is 500px tall. The decade labels are at y=532. We will be especially picky about redundancy. For full credit, your methods should obey these constraints: • The main method should not draw on a DrawingPanel, nor read lines of input from a file (nextLine). • The method that asks the user for a name must not also read lines of input from a file. • Split the displaying of graphical data into at least two methods. For example, you could have one method to draw "fixed" graphics (gray legend rectangles, etc.) and another for graphics that come from the file (bars, ranks). Your methods should be well-structured and avoid redundancy, and your main method should be a concise summary of the overall program. Avoid "chaining," which is when many methods call each other without ever returning to main. For this assignment you are limited to the language features in Chapters 1 through 6 of the textbook. In particular, you are not allowed to use arrays on this assignment. Follow past stylistic guidelines about indentation, line lengths, identifier names, and localizing variables, and commenting at the beginning of your program, at the start of each method, and on complex sections of code. For reference, our solution occupies ~110 lines and has 6 methods other than main.

names.txt

Aaden m 0 0 0 0 0 0 0 0 0 0 0 0 556
Aaliyah f 0 0 0 0 0 0 0 0 0 0 0 211 56
Aarav m 0 0 0 0 0 0 0 0 0 0 0 0 570
Aaron f 0 0 0 0 0 0 0 0 0 883 0 0 0
Aaron m 147 193 187 199 250 237 230 178 52 34 34 41 55
Aarush m 0 0 0 0 0 0 0 0 0 0 0 0 896
Abagail f 0 0 0 0 0 0 0 0 0 0 0 954 923
Abb m 884 0 0 0 0 0 0 0 0 0 0 0 0
Abbey f 0 0 0 0 0 0 0 0 0 658 482 425 887
Abbie f 199 316 449 729 806 952 0 0 0 725 685 591 821
Abbigail f 0 0 0 0 0 0 0 0 0 0 0 553 505
Abby f 0 0 0 0 0 0 0 656 811 268 222 205 284
Abdiel m 0 0 0 0 0 0 0 0 0 0 0 0 806
Abdul m 0 0 0 0 0 0 0 0 0 870 933 0 0
Abdullah m 0 0 0 0 0 0 0 0 0 0 0 868 899
Abe m 237 274 282 412 679 856 0 984 0 0 0 0 0
Abel m 511 649 981 732 537 589 515 503 479 366 384 352 292
Abigail f 940 0 0 0 0 0 826 675 526 176 90 14 7
Abigale f 0 0 0 0 0 0 0 0 0 0 0 953 912
Abigayle f 0 0 0 0 0 0 0 0 0 0 0 716 0
Abner m 489 520 480 801 975 0 0 0 0 0 0 0 0
Abraham m 192 195 162 203 306 385 392 465 432 273 245 213 194
Abram m 415 578 556 948 0 0 0 0 0 715 919 793 531
Abril f 0 0 0 0 0 0 0 0 0 0 0 864 711
Ace m 0 968 0 0 0 0 0 0 0 0 0 0 619
Acie m 0 836 0 0 0 0 0 0 0 0 0 0 0
Ada f 51 72 94 136 185 246 369 514 665 909 0 0 552
Adah f 361 567 970 0 0 0 0 0 0 0 0 0 0
Adaline f 617 885 876 859 0 0 0 0 0 0 0 0 0
Adalyn f 0 0 0 0 0 0 0 0 0 0 0 0 256
Adalynn f 0 0 0 0 0 0 0 0 0 0 0 0 445
Adam m 180 187 182 223 337 381 385 249 71 22 32 45 81
Adan m 0 0 0 0 957 0 851 921 787 558 547 503 332
Add m 994 0 0 0 0 0 0 0 0 0 0 0 0
Adda f 578 0 0 0 0 0 0 0 0 0 0 0 0
Addie f 92 119 157 210 294 345 530 955 0 0 0 0 0
Addie m 885 837 0 0 0 0 0 0 0 0 0 0 0
Addilyn f 0 0 0 0 0 0 0 0 0 0 0 0 974
Addison f 0 0 0 0 0 0 0 0 0 0 0 322 11
Addison m 512 785 928 887 874 0 0 0 0 0 645 514 0
Addisyn f 0 0 0 0 0 0 0 0 0 0 0 0 403
Addyson f 0 0 0 0 0 0 0 0 0 0 0 0 190
Adela f 548 557 550 566 654 772 785 0 0 0 0 0 0
Adelaide f 242 233 270 300 466 660 0 0 0 0 0 0 434
Adelbert m 490 0 634 949 0 0 0 0 0 0 0 0 0
Adele f 208 230 224 206 265 365 391 607 0 0 0 0 908
Adelia f 475 478 663 745 0 0 0 0 0 0 0 0 0
Adelina f 728 861 794 819 892 962 0 0 0 0 0 0 915
Adeline f 195 202 172 176 269 473 823 0 0 0 0 805 322
Adell f 758 482 426 492 678 863 0 0 0 0 0 0 0
Adella f 483 611 737 600 879 0 0 0 0 0 0 0 0
Adelle f 729 886 795 739 0 0 0 0 0 0 0 0 0
Adelyn f 0 0 0 0 0 0 0 0 0 0 0 0 385
Adelynn f 0 0 0 0 0 0 0 0 0 0 0 0 633
Aden m 0 0 0 0 0 0 0 0 0 0 0 886 288
Aditya m 0 0 0 0 0 0 0 0 0 0 0 0 810
Adline f 825 941 914 0 0 0 0 0 0 0 0 0 0
Admiral m 0 579 0 0 0 0 0 0 0 0 0 0 0
Adolf m 0 969 982 0 0 0 0 0 0 0 0 0 0
Adolfo m 995 0 858 0 646 741 740 708 731 670 649 546 0
Adolph m 138 180 210 241 321 437 570 653 927 0 0

meanings.txt

A mf (no meaning found)
AADEN m (no meaning found)
AALBJRG f Icelandic, Ancient Scandinavian Derived from the Old Norse elements aal "noble" and bjrg "protection, help".
AALI m Arabic Means "high, lofty, sublime" in Arabic.
AALIYAH f Arabic Feminine form of AALI
AALSTEINN m Icelandic, Ancient Scandinavian Derived from the Old Norse elements aal "noble" and steinn "stone".
AAMINA f Arabic Derived from Arabic amina meaning "safe".
AAMU f Finnish Means "morning" in Finnish.
AAPELI m Finnish Finnish form of ABEL
AAPO m Finnish Finnish form of ABRAHAM
AARAV m (no meaning found)
AAREN mf English Variant or feminine form of AARON
AARN m Spanish Spanish form of AARON
AARNE m Finnish Finnish form of ARNOLD
AARON m English, Biblical From the Hebrew name ??????? ('Aharon) which is most likely of unknown Egyptian origin.
AARUSH m (no meaning found)
AATAMI m Finnish Finnish form of ADAM
AATOS m Finnish Means "thought" in Finnish.
AATTO m Finnish Finnish form of ADOLF.
AATU m Finnish Finnish form of ADOLF
ABADDON m Biblical Means "ruin, destruction" in Hebrew.
ABAGAIL mf (no meaning found)
ABB m (no meaning found)
ABBEY f English Short form of ABIGAIL
ABBI f English Short form of ABIGAIL
ABBIE f English Short form of ABIGAIL
ABBIGAIL mf (no meaning found)
ABBN m Irish Means "little abbot", derived from Irish abb "abbot" combined with a diminutive suffix.
ABBY f English Short form of ABIGAIL
ABD-AL-AZIZ m Arabic Means "servant of the powerful" from Arabic ??? ?? ('abd al) "servant of the" combined with ???? ('aziz) "powerful".
ABD-AL-KADER m Arabic Variant transcription of ABD-AL-QADIR
ABD-AL-KARIM m Arabic Means "servant of the generous" from Arabic ??? ?? ('abd al) "servant of the" combined with ???? (karim) "generous".
ABD-AL-LATIF m Arabic Means "servant of the gentle" from Arabic ??? ?? ('abd al) "servant of the" combined with ???? (latif) "gentle".
ABD-AL-MALIK m Arabic Means "servant of the king" from Arabic ??? ?? ('abd al) "servant of the" combined with ??? (malik) "king".
ABD-AL-QADIR m Arabic Means "servant of the capable, powerful" from Arabic ??? ?? ('abd al) "servant of the" combined with ???? (qadir) "capable".
ABD-AL-RAHMAN m Arabic Means "servant of the merciful" from Arabic ??? ?? ('abd al) "servant of the" combined with ???? (rahman) "merciful".
ABD-ALLAH m Arabic Means "servant of God" from Arabic ??? ('abd) "servant of" combined with ???? (Allah) "God".
ABDIEL mf (no meaning found)
ABDUL m Arabic First part of compound Arabic beginning with ??? ?? ('Abd al) meaning "servant of the" (such as ??? ?????? ('Abd al-'Aziz) "servant of the powerful").
ABDUL-AZIZ m Arabic Variant transcription of ABD-AL-AZIZ
ABDUL-RAHMAN m Arabic Variant transcription of ABD-AL-RAHMAN
ABDULLAH m Arabic Variant transcription of ABD-ALLAH
ABE m English, Jewish Short form of ABRAHAM
ABEDNEGO m Biblical Means "servant of Nebo" in Babylonian, Nebo being the Babylonian god of wisdom.
ABEGAIL f Spanish Spanish form of ABIGAIL
ABEL m English, French, Spanish, Portuguese, Biblical From the Hebrew name ????? (Hevel) or ????? (Havel) which meant "breath".
ABELE m Italian Italian form of ABEL
ABELONE f Danish Danish form of APOLLONIA
ABENA f African Means "born on Tuesday" in Akan.
ABENI f Yoruba Means "we asked for her, and behold, we got her" in Yoruba.
ABHA f Indian Means "shine" in Sanskrit; f Irish Irish form of EVE
ABHAY m Indian Means "fearless" in Sanskrit.

These txt files are much longer than this but I cut them in order to look more clean.

Explanation / Answer

import java.util.*;
import java.io.*;
import java.awt.*;

public class PeopleNames{
public static final int STARTYEAR = 1890;
public static final int BREADTH = 60;
public static final int HGHT = 30;
private static String finalName;
public static void main(String[] args) throws FileNotFoundException{
Scanner console = new Scanner(System.in);
DrawingPanel pnl = new DrawingPanel(780,560);
Graphics g = pnl.getGraphics();
Scanner namesFile = new Scanner(new File("names.txt"));
Scanner meaningFile = new Scanner(new File("meanings.txt"));
Scanner namesFile2 = new Scanner(new File("names2.txt"));
introduction();
drawFixedGraph(g);
finalName = convertNameToLowerCase(console);
String meaning;
if(STARTYEAR == 1890){
findStats(console,namesFile);
}
else{
findStats(console, namesFile2);
}
meaning = findStats(console, meaningFile);
changeGraph(meaning,g);
}

public static void introduction(){
System.out.println("This tool allows you to find the data from the Social Security Administration");
System.out.println("to check how popular a particular name is popular since ");
System.out.println(STARTYEAR );
System.out.println();
System.out.print("Name:");
}

public static String convertNameToLowerCase(Scanner console){   
String origName = console.next();
String name = "" ;
int nameLength = origName.length();
String startOfName = origName.substring(0,1).toUpperCase();
String stopOfName = origName.substring(1,nameLength).toLowerCase();
name = startOfName + stopOfName;
return name;
}
public static String findStats(Scanner console, Scanner data){
boolean goThroughOnce = false; //
String stats = "";
String presentWord = "";
String presentLine = "";
while (data.hasNext() && goThroughOnce == false){
presentLine = data.nextLine();
Scanner lineRead = new Scanner(presentLine);
presentWord = lineRead.next(); //

if (presentWord.equals(finalName) || presentWord.equals(finalName.toUpperCase())){ //   
stats = presentLine;
goThroughOnce = true;
System.out.println(stats);
}
else{
}
}
return stats;
}
public static void drawFixedGraph(Graphics g){ //Draws gray blocks and black lines
g.setColor(Color.LIGHT_GRAY);
g.fillRect(0,0,780,HGHT);
g.fillRect(0,560-HGHT,780,HGHT);
g.setColor(Color.BLACK);
g.drawLine(0,HGHT,780,HGHT);
g.drawLine(0,560-HGHT,780,560-HGHT);
}

public static void changeGraph(String meaning, Graphics g){
g.drawString("" + meaning,0,16); //draw the meaning text
int STARTYEAR = STARTYEAR;
int decadeAmount = 0;
if(STARTYEAR == 1890){
decadeAmount = 13;
}
else{
decadeAmount = 8;
}
g.drawString("" + STARTYEAR,0,552);
for(int i=0; i<=decadeAmount;i++){
int year = STARTYEAR + (10 * i);
g.drawString("" + year,(BREADTH*i),552); //draws the decade number
}
}
}