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

java PROGRAM- Write a program that reads a file (e17.98_name_data.txt in the Stu

ID: 3682399 • Letter: J

Question

java PROGRAM- Write a program that reads a file (e17.98_name_data.txt in the Student Files folder copied to your project's folder) containing data about the changing popularity of various baby names over time and displays the data about a user selected name. Use JFileChooser (Figure 17.20 in the textbook) to prompt for the name of the input file. Each line of the file contains a name followed by integers representing the name's popularity in each decade: 1900, 1910, 1920, and so on. 1900 is first decade. Other decades must not be "hard coded". The rankings range from 1 (most popular) to 1000 (least popular). Two parallel arrays are recommended. A string array to hold the names and a 2-dimensional integer array to hold the popularity values.

Your program should list the names in the name string array, prompt the user to enter a name, search the name string array for the name, provide an error message if an invalid name is selected, determine the decade of the greatest popularity of the selected name, and output the following to a JTextArea window (Figure 17.20 in the textbook):

Statistics on name "Sam":

1900: 58

1910: 69

1920: 145

1930: 88

. . .

Average Popularity: 89.75

Decade of Greatest Popularity: 1900

Set the Font of the output to 12 point Courier. See Figure 15.11 for an example.

Your program(s) must include the following:

1. Tell the user how to terminate prompted input of unspecified length.

2. Include description of what user is being prompted for each input.

3. Include description of units when appropriate, i.e., .05 or 5 for 5%.

4. Provide appropriate try/catch/throw exception processing where appropriate.

Book is :Java How to program ninth edition paul deitel and harvey deitel chapter 17 text file is :name_data.txt

Sam 409 228 149 169 977 779 87 479 449 630 744

Sally 780 790 955 132 852 214 359 901 73 631 932

Sean 67 894 125 475 955 214 662 475 693 186 340

Greg 79 621 979 622 891 88 710 748 794 433 384

Steve 743 909 930 551 974 965 692 808 252 725 261

Jerri 229 777 261 840 419 672 43 148 867 659 513

Ned 42 469 861 427 799 420 334 203 369 134 508

Viper 721 722 537 991 718 794 362 584 760 979 92

Goofy 942 601 691 52 243 215 151 90 414 543 512

Hazel 661 921 383 226 565 26 930 84 237 834 34

Janet 682 634 979 696 227 766 964 406 329 378 307

Explanation / Answer

File: NameSurferEntry.java * -------------------------- * This class represents a single entry in the database.

Each * NameSurferEntry contains a name and a list giving the popularity * of that name for each decade stretching back to 1900.

*/ import acm.util.*;

import java.util.*;

public class NameSurferEntry implements NameSurferConstants {

/* Constructor: NameSurferEntry(line) */ /** * Creates a new NameSurferEntry from a data line as it appears * in the data file. Each line begins with the name, which is * followed by integers giving the rank of that name for each * decade.

*/ public NameSurferEntry(String line) { // You fill this in // } /* Method: getName() */ /** * Returns the name associated with this entry.

*/ public String getName() { // You need to turn this stub into a real implementation // return null;

} /* Method: getRank(decade) */ /** *

Returns the rank associated with an entry for a particular * decade. The decade value is an integer indicating how many * decades have passed since the first year in the database, * which is given by the constant START_DECADE.

If a name does * not appear in a decade, the rank value is 0.

*/ public int getRank(int decade) { // You need to turn this stub into a real implementation //

return 0; } /* Method: toString() */ /** *

Returns a string that makes it easy to see the value of a * NameSurferEntry.

*/ public String toString() { // You need to turn this stub into a real implementation //

return ""; } }

* File: NameSurferGraph.java * --------------------------- * This class represents the canvas on which the graph of * names is drawn.

This class is responsible for updating * (redrawing) the graphs whenever the list of entries changes * or the window is resized.

*/ import acm.graphics.*;

import java.awt.event.*;

import java.util.*;

import java.awt.*;

public class NameSurferGraph extends GCanvas implements NameSurferConstants, ComponentListener {

/** * Creates a new NameSurferGraph object that displays the data.

*/ public NameSurferGraph() { addComponentListener(this); // You fill in the rest // } /** *

Clears the list of name surfer entries stored inside this class.

*/ public void clear() { // You fill this in // }

/* Method: addEntry(entry)

*/ /** * Adds a new NameSurferEntry to the list of entries on the display.

* Note that this method does not actually draw the graph, but * simply stores the entry; the graph is drawn by calling update.

*/ public void addEntry(NameSurferEntry entry)

{ // You fill this in // } /** * Updates the display image by deleting all the graphical objects * from the canvas and then reassembling the display according to * the list of entries.

Your application must call update after * calling either clear or addEntry; update is also called whenever * the size of the canvas changes.

*/ public void update() { // You fill this in // }

/* Implementation of the ComponentListener interface */

public void componentHidden(ComponentEvent e) { }

public void componentMoved(ComponentEvent e) { }

public void componentResized(ComponentEvent e) {

update(); } public void componentShown(ComponentEvent e) { } }