1

Help with java . For this project, you will design and implement a program that analyzes...

Question

Help with java . For this project, you will design and implement a program that analyzes...

Help with java .

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 here : https://owd.tcnj.edu/~papamicd/name_data.txt

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

Answers

ANSWER

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

Import java.util.Scanner;

/**

*

* @author paramesh

*/

Public class Social Data {

String name;

Into [] data = new into [11];

// constructor

Public Social Data (String line) {

// splitting array

String [] art = line. split (" ");

this.name = arr[0];

// parsing ranks

for (int i = 1; i < arr.length; i++) {

data[i - 1] = Integer.parseInt(arr[i]);

}

}

// get name

public String getName() {

return this.name;

}

// get decade

public int getRank(int decade) {

return data[decade];

}

// best year

public int bestYear() {

int best = data[0];

for (int i = 0; i < data.length; i++) {

if (data[i] < best) {

best = data[i];

}

}

return (1900 + best);

}

// main

public static void main(String args[]) {

ArrayList<SocialData> list = new ArrayList<SocialData>();

File file = new File("name_data.txt");

try {

Scanner sc = new Scanner(file);

while (sc.hasNextLine()) {

String line = sc.nextLine();

SocialData obj = new SocialData(line);

list.add(obj);

}

sc.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

}

while (true) {

System.out.println("1 – Find the best year for a name\n"

+ "2 – Find the best rank for a name\n"

+ "3 – Plot the popularity of a name\n"

+ "4 – Clear the plot\n"

+ "5 – Quit"

);

Scanner sc = new Scanner(System.in);

int choice = sc.nextInt();

if(choice == 5){

break;

}

}

}

}


Similar Solved Questions

1 answers
Brussels Enterprises issues bonds at par dated January 1, 2019, that have a $3,000,000 par value,...
Brussels Enterprises issues bonds at par dated January 1, 2019, that have a $3,000,000 par value, mature in four years, and pay 8% interest semiannually on June 30 and December 31. 1. Record the entry for the issuance of bonds for cash on January 1 2. Record the entry for the first semlannual intere...
1 answers
ARTB Mona Western University operates a Laundromat, solely for the purpose of providing ering services to...
ARTB Mona Western University operates a Laundromat, solely for the purpose of providing ering services to students in dance. You have been hired as an accounting ouder. wlyze the cost of the laundering services. The university administration has assembled me dats welve month period pertaining to the...
1 answers
1. What are industry examples in international trade where economics of scale are relevant? 2. what...
1. What are industry examples in international trade where economics of scale are relevant? 2. what are the arguments for and against requiring the U.S. federal budget to be balanced? 3. How well GPD measures tue well-being of society?...
1 answers
Problem #2 A company has the following transactions during June: June 2 Provide services to customers...
Problem #2 A company has the following transactions during June: June 2 Provide services to customers for cash, $4,300 June 8 Purchase office supplies on account, $1,000 June 11 Pay workers' salaries for the current period, $1,400 June 15 Issue additional shares of common stock, $6,000 June 28 P...
1 answers
11.   A) Name the membrane-bound enzyme that directly links the TCA cycle with the electron transport...
11.   A) Name the membrane-bound enzyme that directly links the TCA cycle with the electron transport chain. Give its name in the TCA cycle and the electron transport chain. B) Name at least two other starting points for substrates used in the electron transport chain. C) Approximately how...
1 answers
5. If demand is elastic, will shifts in supply have a larger effect on equilibrium quantity...
5. If demand is elastic, will shifts in supply have a larger effect on equilibrium quantity or 6. If supply is inelastic, will shifts in demand have a larger effect on equilibrium price or on Under which circumstances does the tax burden fall entirely on consumers? İpts on price? Ipts quantity?...
1 answers
A nonhomogeneous equation and a particular solution are given. Find a general solution for the equation....
A nonhomogeneous equation and a particular solution are given. Find a general solution for the equation. y" - y = 5t, yp(t) = -51 The general solution is y(t)= (Do not use d, D, e, E, I, or as arbitrary constants since these letters already have defined meanings.)...
1 answers
Consider the market for snow skiing illustrated in the graph to the right. Suppose that on...
Consider the market for snow skiing illustrated in the graph to the right. Suppose that on the weekend, demand is D. However, on weekdays, demand becomes D2 If a snow ski resort engages in peak-load pricing, then what prices should it charge? 1.) Using the point drawing tool, identify the profit-max...
1 answers
A nonconducting sphere has a radius R=9.5 cm and uniformly distributed charge q=5.5e-12 C. Take the...
A nonconducting sphere has a radius R=9.5 cm and uniformly distributed charge q=5.5e-12 C. Take the electric potential at the sphere's center to be zero. What is V at radial distance r=5.8 cm?...
1 answers
Emma drank 1/4 of a milk shake in 1/12 of a minute. How many minutes will it take her to drink a full milk shake?
Emma drank 1/4 of a milk shake in 1/12 of a minute. How many minutes will it take her to drink a full milk shake?...
1 answers
A grass field is inhabited by mice and coyotes. The mice eat the grass and serve as food for the coyotes. A disease of unknown origin kills all the coyotes. What will happen to the ecosystem?
A grass field is inhabited by mice and coyotes. The mice eat the grass and serve as food for the coyotes. A disease of unknown origin kills all the coyotes. What will happen to the ecosystem?...
1 answers
Packard Company engaged in the following transactions during Year 1, its first year of operations: (Assume...
Packard Company engaged in the following transactions during Year 1, its first year of operations: (Assume all transactions are cash transactions.) 1) Acquired $1,350 cash from the issue of common stock, 2) Borrowed $820 from a bank. 3) Earned $1,050 of revenues. 4) Paid expenses of $330. 5) Paid a ...
1 answers
On January 2, 2020, SF purchased 15% of LA's common stock for $50,000 and classified its...
On January 2, 2020, SF purchased 15% of LA's common stock for $50,000 and classified its investment in LA as trading securities. LA's net income for the year ended 12/31/2020 was $100,000. During 2020, LA declared and paid a total dividend of $30,000. On 12/31/2020, the fair value of the LA ...
1 answers
Ork 59 Summit Systems will pay a dividend of $1.55 this year. If you expect Summit's...
ork 59 Summit Systems will pay a dividend of $1.55 this year. If you expect Summit's dividend to grow by 5.2% per year, what is its price per share if the firm's equity cost of capital is 11.1%? ou The price per share is $1. (Round to the nearest cent.) eral...
1 answers
A bond portfolio is estimated to have a 12% probability of default per dollar invested. In...
A bond portfolio is estimated to have a 12% probability of default per dollar invested. In case a default occurs, the average recovery rate is estimated to be 0.31 on the dollar. What is the expected loss per dollar invested? Enter answer accurate to three decimal places. The answer has to be .083. ...
1 answers
For the concrete dam shown below, determine the minimum width in feet of the dam, b, so lb 3 that it does not tip about its toe, A. Take the unit weight of concrete as yconcrete- 142 ft lb and that o...
For the concrete dam shown below, determine the minimum width in feet of the dam, b, so lb 3 that it does not tip about its toe, A. Take the unit weight of concrete as yconcrete- 142 ft lb and that of water as Ywater - 62.4 3 ft 66 ft ft Determine the coefficient of friction required to prevent the ...
1 answers
Computerized System Manual System $1,740,000 $1,740,000 Sales 696,000 1,392,000 Variable costs 1,044,000 Contribution margin 348,000 804,000...
Computerized System Manual System $1,740,000 $1,740,000 Sales 696,000 1,392,000 Variable costs 1,044,000 Contribution margin 348,000 804,000 108,000 Fixed costs $240,000 $240,000 Net income Your answer is correct. Determine the degree of operating leverage for each alternative. (Round answers to 2 d...
1 answers
Ons to see the fowers, and this tourism has been increasing business activity for many businesses....
ons to see the fowers, and this tourism has been increasing business activity for many businesses. The local business leaders would ike you to convince Ms. Daisy to plant more flowers so that tourism connues to incroase...

-- 0.009898--