Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA: (Find yourself in PI) In this assignment you will find a numeric string (if it exists) within a file containing the first 1 million

JAVA: (Find yourself in PI)

In this assignment you will find a numeric string (if it exists) within a file containing the first 1 million characters of the decimal expansion of PI. The numeric string in question is a 6 character string representing your birth date. E.g., if your birth date is January 1, 1984, then the string is 010184. The file containing the first 1 million characters of the decimal expansion of PI is named pidigits.txt and is available for download from D2L. Your code should prompt the user for their birthday and then verify that the string entered by the user is indeed a valid date string. Invalid date strings include the following:

013284 // No month has more than 31 days

022905 // 2005 was not a leap year

150184 // There are only 12 months

093196 // September only has 30 days etc.

Thus, a birth date string is of the form: mmddyy where mm is a two digit string representing the month, dd is a two digit string representing the day and yy is a two digit string representing the year. Once a birth date string has been entered by the user and validated, you will open pidigits.txt and read in a single character at a time using a BufferedReader instance. If a non-digit character such as a space, tab, or blank line is read, discard it. If the character is a digit character, keep it until a match/non-match has been established. As you read the characters, if there is a match between the birth date string and the characters read, report this to the user. Your code must find all such matches in the file, report all such matches to the user, report the character position in the file at which a given match begins, report the number of comparisons made in establishing the match, and report the total number of comparisons used in reading the entire file.. The format used for reporting is:

Your birthday 022348 was found at character position 1013664 in pidigits.txt

The number of comparisons so far is: 919560

Your birthday 022348 was found at character position 1073634 in pidigits.txt

The number of comparisons so far is: 973942

The total number of comparisons made in reading this file is: 1111091

If there are no matches for the birth date string, then your code should simply output the total number of comparisons made in reading the file. Constraints:

Your must use BufferedReader for all IO. No Scanner instances nor JOptionPanes allowed. Failure to observe this constraint will result in a significant loss of points.

Each character in pidigits.txt will be read in exactly once using the read() method of the BufferedReader class. You must use the version of read() that takes no parameters. You do not need to back up and reread characters that have already been read. Failure to observe this constraint will result in a significant loss of points.

You are not allowed to store the characters read in an array or any other kind of container. They are to be stored in char variables only. It should be obvious that you need only 6 such variables for this assignment. Failure to observe this constraint will result in a significant loss of points. You are not allowed to use any methods from the String class for finding matches.

You may and should use the isDigit() method. The isDigit() method is a static method in the Character class. Failure to observe this constraint will result in a significant loss of points. Your code must validate that the birth date string entered by the user is indeed a valid date. You must do this by passing the string as a parameter to a constructor of some sort of Date class. The Date class can be one that you build from scratch or can be based on one of the Date classes in the Java API (Calendar, GregorianCalendar, etc.). The code in your Date class is allowed to use methods from the String class. Failure to observe this constraint will result in a significant loss of points.

The name of the file containing your main() method must be YourFirstNameYourLastNameIV.java. The name of the file containing your code for your Date class must be BirthDate.java. Failure to observe this constraint will result in a significant loss of points.

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

Students also viewed these Databases questions