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
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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;

}

}

}

}

Add a comment
Know the answer?
Add Answer to:
Help with java . For this project, you will design and implement a program that analyzes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to...

    Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to easily plug-in new sort algorithms and compare them. Assume that input data is generated randomly and stored in a text file (have no less than 2000 items to sort). Do not restrict your program to only one data type, or to one ordering relationship. The data type, ordering relationship, and the sorting method must be input parameters for your program....

  • Design and implement a Java program (name it ArrayMethods ), that defines 4 methods as follows:...

    Design and implement a Java program (name it ArrayMethods ), that defines 4 methods as follows: int arrayMax (int [ ] arr) determines and returns the ma ximum value within an array int arrayMin (int [ ] arr) determines and returns the minimum value within an array void arraySquared (int [ ] arr) changes every value within the array to value

  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

  • Design and implement a Java program (name it ArrayMethods), that defines 4 methods as follows: int...

    Design and implement a Java program (name it ArrayMethods), that defines 4 methods as follows: int arrayMax (int [ ] arr) determines and returns the maximum value within an array int arrayMin (int [ ] arr) determines and returns the minimum value within an array void arraySquared (int [] arr) changes every value within the array to value2 void arrayReverse (int [ ] arr) reverses the array (for example: 7 8 12 becomes 2 18 7) Test your methods by...

  • Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses...

    Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses the following menu and can perform all menu items: Enter a payroll record for one person Display all paycheck stubs Display total gross payroll from all pay records. Quit program The program will reuse the DATE struct from the previous assignment.  You should also copy in the functions relating to a DATE. The program will create a PAYRECORD struct with the following fields: typedef struct...

  • Exercise 5: Design and implement a Java program (name it ArrayMethods), that defines 4 methods as...

    Exercise 5: Design and implement a Java program (name it ArrayMethods), that defines 4 methods as follows: int arrayMax(int[] arr) determines and returns the largest value within an array int arrayMin(int[] arr) determines and returns the smallest value within an array void arrayReverse(int[] arr) reverses the array (for example: 7 8 1 2 becomes 2 1 8 7) void arraySquared(int[] arr) changes every value within the array to value² Test your methods by creating an array of length 5 within...

  • Need help with java In this program you will use a Stack to implement backtracking to solve Sudok...

    need help with java In this program you will use a Stack to implement backtracking to solve Sudoku puzzles. Part I. Implement the stack class.  Created a generic, singly-linked implementation of a Stack with a topPtr as the only instance variable. Implement the following methods only: public MyStack() //the constructor should simply set the topPtr to null public void push(E e) public E pop()  Test your class thoroughly before using it within the soduku program Part II. Create...

  • Hello Guys. I need help with this its in java In this project you will implement...

    Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...

  • In this project, you are asked to design and implement a class for double link list...

    In this project, you are asked to design and implement a class for double link list to hold integers: – The class should be called DList, you also need a class called Node that contains an int as the data – Node needs the following data: int data; //the data held by the node Node* parent; //the parent of the Node Node* child; //the child of the Node – Node needs the following public functions: Node(int)// constructor to create a...

  • Question2 uses structured design implemented in C. Array of records (structs) with file I/O is needed....

    Question2 uses structured design implemented in C. Array of records (structs) with file I/O is needed. The program takes two inputs at a time. The name of a person, and, the coin value as an integer in the range 5 to 95. Input coin values should always be divisible by 5 (integer division). Names are one word strings. An example input is: Jane 30 This input line indicates that 30 cents change is to be given to Jane. Output change...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT