Question
Prompt the user for a name and gender, and then display the names meaning and popularity as console text and as a graphical bar chart
Prompt the user for a name and gender, and then display the name’s meaning and popularity as console text and as a graphical bar chart on a DrawingPanel. The input data about names' popularity rankings and meanings comes from two input files provided. Your program should give an introduction and then prompt the user for a first name and gender. It should then read the name rank data file searching for that name/gender combination, caseinsensitively (that is, you should find the name regardless of the capitalization the user uses when typing it). If the name/gender combination is found in the file, your program should print a line of statistics about that combination’s popularity in each decade, the name’s meaning and display information about the name graphicallyYour program reads data from two files. 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" 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. Notice that the spacing between numbers and other tokens varies. This won’t be a problem if you use a Scanner to pull apart each line of input (versus, for example, searching for a string that has exactly one space between the name and the F/M gender notation). Once the user types a name/gender combination, search each line of names.txt to see if it contains data for that combination. If it is found, output its data line to the console, then construct a DrawingPanel to graph the data (see Graphical Output requirement). Your code should not assume that the file is sorted alphabetically. If the combination is not found, output a "not found" message. No DrawingPanel should appear. 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. You are given another file named names2.txt with 8 decades and the matching graphical output is also given under sample_output folder. As you can see the graphical output for names2.txt has the start year as 1863 (THIS IS DIFFERENT START YEAR THAN names.txt) and 50 pixels width and 20 pixels legend height. See Stylistic Guideline on page 5 for more detail on start year, width, and height. 2. meanings.txt: descriptions of the meanings of each name If the name/gender combination is found in names.txt, you should also read meanings.txt to find its meaning. The line containing the combination’s meaning should be printed to the console and also drawn on the DrawingPanel. Every combination in names.txt is also in meanings.txt, so you do not need to worry about a combination having rankings but no meaning data. Some combinations have long meanings that may stretch past the right edge of the DrawingPanel.Though the two input files contain different data, the task of searching for a name/gender combination in names.txt is very similar to the task of searching for a combination 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 green. 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 ycoordinate. 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
QUESTION Prompt the user for a name and gender and then display the names meaning and popularity as console text and as a graphical bar chart on a DrawingPanel The input data about names popularity ra...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started