Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could someone help me with managing and accessing a File in my BabyNames project? Here is the code I have below: import java.io.File; import java.io.FileNotFoundException;

Could someone help me with managing and accessing a File in my BabyNames project? Here is the code I have below:

import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import javax.swing.JOptionPane;

public class BabyClient { public static void main(String args[]) throws FileNotFoundException { Scanner keyboard = null; try { do { String yearInput = JOptionPane.showInputDialog (null, "Enter Year of Birth: "); int babyYear = Integer.parseInt (yearInput); if (babyYear > 2001 || babyYear < 1995) { JOptionPane.showMessageDialog (null, "Please Input A Valid Year!"); } keyboard = new Scanner (new File("yob" + babyYear + ".txt")); String genderInput = JOptionPane.showInputDialog (null, "Enter Gender: "); char babyGender = genderInput.charAt (0); String babyName = JOptionPane.showInputDialog (null, "Enter Baby Name: "); } while(true); } catch (Exception e) { JOptionPane.showMessageDialog (null, "Please Input Valid Info"); } }

}

My question is how do I start to do this, what I need help with is bolded and italicized below:

ASSIGNMENT BELOW!

For this programming assignment, you will be writing software in support of a data base search to determine if a particular baby name was popular in a particular year. If the baby name is in the data base, you are to display the year, name, and number of babies given that name in that year. If the baby name is not in the data base, you are to display the year, name, and a short message indicating the name was not found in that year.

Program Requirements:

Use JOptionPane for ALL user input and output

Must validate ALL user input

Must include ALL necessary exception handling

ALL methods must do only one thing

Must follow ALL programming style guidelines

Program Description:

Ask the user for the baby name, the gender (some names apply to both genders) and the year to search, or to exit the program (be efficient in the use of JOptionPanes - users do not like to see too many different boxes)

Build the file name to search (the file name is yobxxx.txt, where xxx is the four-digit year) (yob means year of birth)

Open the file

Search the file for the name and gender requested

Display the results to the user (year, name, gender, number of babies with name), or a not found message containing the name and year searched

Close the file

Ask the user to search another name, gender, year or to quit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How could an organization's culture be used as a control mechanism?

Answered: 1 week ago

Question

Describe the nature of negative messages.

Answered: 1 week ago