Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M91610870
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Java

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As