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

  A java program that will prompt the user to input a file

Write a Java program that will prompt the user to input a file (document) in order to count the frequency of each word. This program will display the frequency of each word sorted alphabetically or by frequency (depending on the preference of the use..

  Palindrome is a sequence of char that reads backward forwrd

A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554, and 11611. Write an application called Palindrome.java that asks the user t..

  Java program to write-read data from user using i-o function

Write java program to write and read data from user using I/O functions. Describe class with data members name[20],emp_id,basic pay,net pay.calculate all the allowances.

  Write the specification for the adt as a java interface

Write the specification for the ADT as a Java interface

  Implement a class person with two fields name and age

Implement a class Person with two fields name and age, and a class Car with three fields

  Evaluate the rtas resource requirements

Design and implement a set of classes and interfaces and use them to evaluate the RTA's resource requirements.

  Common to perform loops that vary the loop control

When an application contains an array and you want to use every element of the array in some task, it is common to perform loops that vary the loop control variable from 0 to one less than the size of the array.

  Write a java program to simulate a die

Write a Java program to simulate a die. A die has values of either 1, 2, 3, 4, 5 or 6 on the face. You should use the Math.Random() or the java.util.Random() class to generate the values on the die. The program should prompt the user to enter how ..

  Negatively impacting health care currently

Identify and explain at least two events that are negatively impacting health care currently. Tell us why you think these items are negatively impacting the access to care, and make sure that you cite your references.

  Eclipse or netbeans environments

As recommendation, you can try to use Eclipse or NetBeans environments that are used also for other courses as: Introduction in Java programming and Intermediate programming.

  Create dict letter frequencies that reads the file

createDictLetterFrequencies that reads the file and also takes a parameter n. This method should return a dictionary of dictionaries. The outer dictionary associates the previous n letters of a word with an inner dictionary, which indicates the frequ..

  Write an interface for an abstract method

Write an interface, PointingDevice, containing:  an abstract method, getXCoord that returns an int and an abstract method, getYCoord that returns an int.

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