Reads an input record and prints the name

Assignment Help JAVA Programming
Reference no: EM13939996

The file named babynames80s.txt contains the data for names in the 80s, pasted directly from the Social Security Administration web site. The numbers in the files have comma separators:

1 Michael 663,087 3.4512 Jessica 469,271 2.5448

2 Christopher 555,660 2.8920 Jennifer 440,697 2.3899

3 Matthew 458,596 2.3869 Amanda 369,589 2.0042

4 Joshua 396,328 2.0628 Ashley 352,033 1.9090

5 David 383,258 1.9947 Sarah 272,376 1.4771
...

MODIFY the BabyNames.java program to handle them. Also modify the program so that it prompts the user for a file name.

Here is a sample program run:

Filename: babynames80s.txt

1  Michael Jessica

2  Christopher Jennifer

3  Matthew Amanda

4  Joshua Ashley

5  David Sarah

6  James Stephanie

7  Daniel Melissa

8  Robert Nicole

9  John Elizabeth

10  Joseph Heather

11  Jason Tiffany

12  Justin Michelle

13  Andrew Amber

14  Ryan Megan

15  William Amy

16  Brian Rachel

17  Brandon Kimberly

18  Jonathan Christina

19  Nicholas Lauren

20  Anthony Crystal

21  Eric Brittany

22  Adam Rebecca

23  Kevin Laura

24  Thomas Danielle

25  Steven Emily

26  Timothy Samantha

27  Richard Angela

28  Jeremy Erin

29  Jeffrey Kelly

30  Kyle Sara

31  Benjamin Lisa

32  Aaron Katherine

33  Charles Andrea

34  Mark Jamie

35  Jacob Mary

36  Stephen Erica

37  Patrick Courtney

38  Scott Kristen

39  Nathan Shannon

40  Paul April

41  Sean Katie

42  Lindsey

43  Kristin

44  Lindsay

45  Christine

46  Alicia

47  Vanessa

48  Maria

49  Kathryn

50  Allison

51  Julie

52  Anna

53  Tara

54  Kayla

55  Natalie

56  Victoria

57  Monica

58  Jacqueline

59  Holly

60  Kristina

61  Patricia

62  Cassandra

63  Brandy

64  Whitney

65  Chelsea

66  Brandi

67  Catherine

68  Cynthia

69  Kathleen

70  Veronica

71  Leslie

72  Natasha

73  Krystal

74  Stacy

75  Diana

76  Erika

77  Dana

78  Jenna

79  Meghan

80  Carrie

81  Leah

82  Melanie

83  Brooke

84  Karen

85  Alexandra

86  Valerie

87  Caitlin

88  Julia

89  Alyssa

90  Jasmine

91  Hannah

92  Stacey

93  Brittney

94  Susan

95  Margaret

96  Sandra

97  Candice

98  Latoya

99  Bethany

100  Misty

BELOW is the BabyNames.java code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class BabyNames
{
public static final double LIMIT = 50;

public static void main(String[] args) throws FileNotFoundException
{
Scanner in = new Scanner(new File("babynames.txt"));

RecordReader boys = new RecordReader(LIMIT);
RecordReader girls = new RecordReader(LIMIT);

while (boys.hasMore() || girls.hasMore())
{
int rank = in.nextInt();
System.out.print(rank + " ");
boys.process(in);
girls.process(in);
System.out.println();
}

in.close();
}
}

BELOW is the BabyNames.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class BabyNames
{
public static final double LIMIT = 50;

public static void main(String[] args) throws FileNotFoundException
{
Scanner in = new Scanner(new File("babynames.txt"));

RecordReader boys = new RecordReader(LIMIT);
RecordReader girls = new RecordReader(LIMIT);

while (boys.hasMore() || girls.hasMore())
{
int rank = in.nextInt();
System.out.print(rank + " ");
boys.process(in);
girls.process(in);
System.out.println();
}

in.close();
}
}

BELOW IS THE RecordReader.java
import java.util.Scanner;

/**
This class processes baby name records.
*/
public class RecordReader
{
private double total;
private double limit;

/**
Constructs a RecordReader with a zero total.
*/
public RecordReader(double aLimit)
{
total = 0;
limit = aLimit;
}

/**
Reads an input record and prints the name if the current total is less
than the limit.
@param in the input stream
*/
public void process(Scanner in)
{
String name = in.next();
int count = in.nextInt();
double percent = in.nextDouble();

if (total < limit) { System.out.print(name + " "); }
total = total + percent;
}

/**
Checks whether there are more inputs to process
@return true if the limit has not yet been reached
*/
public boolean hasMore()
{
return total < limit;
}
}

YOUR main class should be called BabyNames.

Reference no: EM13939996

Questions Cloud

Subsidiary of barclays bank plc : Small Bank PLC is a poorly capitalized, wholly-owned retail banking subsidiary of Barclays Bank PLC, a London Stock Exchange-listed bank.
Differences and fundamental operations of a stack : Describe the difference, with examples, between static and dynamic data structures. Draw a visual representation of a linked-list data structure showing how object references are stored and node objects are linked to each other.
Applying contract law to nonemployment workplace situations : Examples of these include the purchase of expensive property, and dealings with software vendors, building contractors, and facility maintenance firms.
Compute a predetermined overhead rate for the plant : Compute a predetermined overhead rate the plant as a whole based on machine hours. Compute predetermined overhead rates for each department using machine hours.
Reads an input record and prints the name : Reads an input record and prints the name if the current total is less than the limit.
Describe four features of a map data structure : Describe the problems that may be encountered when computing the hash codes for adding objects into a simple array implementation of a hash table.
Evaluate approaches to self-managed learning : Evaluate approaches to self-managed learning- you will need to formulate and research ideas on why it is important to manage your own learning. Use the information that you have been given in class to set yourself some short term goals on your lea..
Stored in the array points before line seven : Questions (i) to (vii) relate to the following code. A class called Point is defined and the code fragments that are called from main() are given line numbers 1 to 7.
How has hiv affected the population distribution in africa : How has HIV/AIDS affected the population distribution in Africa (especially Southern Africa)? What social processes have driven such high rates of the epidemic and how might the spread of HIV/AIDS be contained in this area of the world

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd