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

  Write the flow of execution of application

Write the flow of execution of application step by step and briefly explain the functionality of each function being called (like the first step would be to instantiate Frame and then instantiate Panel and place it into the Frame).

  Java-s ability to derive new fonts from existing ones

Find out where on your system these font libraries are located. When you do, please specify the operating system and the location (folder/directory) where you found them. Discuss Java's ability to derive new fonts from existing ones.

  Compute the daily wage of an employee

Write a JAVA program that will input Employee Name, Rate per hour, No. of hours worked and will compute the daily wage of an employee. If the number of hours worked exceeds eight hours add 30% to each excess hours as overtime rate.

  A game of tic-tac-toe

A game of tic-tac-toe, two players (one the computer) take turns marking an available cell in a 3 X 3 grid (a two dimensional array) with their respective tokens (either and X or an O). When one player has placed three tokens in a horizontal

  Create a data set with 100 integer values.

Create a data set with 100 integer values. Create a program that uses the division method of hashing to store the data values into hash tables with table sizes of 7,,51 and 151. Use the linear probing method of collision resolution. Print out the ..

  Given a hash function hkey prepare a java simulation

given a hash function hkey prepare a java simulation program to determine each of the subsequent quantities after

  Create a program called date java to perform

Create a program called Date.java to perform error-checking on the initial values, for instance: fields month, day, and year. Also, provide a method nextDay() to increment the day by one. The Date object should always remain in a consistent state.

  Write a class called misc that has no instance variables

Write a static double method called evaluateQuadraticPolynomial that takes four double parametersa, b, c, and x and returns the value of ax^2 + bx + c

  Build distributed applications using technologies

Build distributed applications using technologies like Unix and Java sockets, SUN RPC, Java RMI, and message-passing tools such as PVM and MPI and

  Minimal spanning tree decreasing edge

minimal spanning tree decreasing edge dismissalreverse-delete algorithm. develop an implementation that computes the

  String that contains at least five letters

Write an application that prompts the user for a String that contains at least five letters and at least five digits. Continuously reprompt the user until a valid String is entered. Display a message indicating whether the user was successful or did ..

  A fault is fundamentally a deviation from expected behavior

write a 200- to 300-word short-answer response to the following a fault is basically a deviation from expected

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