HW8

4
Name: ______________________ Term # ____ Homework 8 - On Lecture 10 – File I/O (100 points) Hours: The homework is to be turned in as a PAPER AND PENCIL i.e., HANDWRITTEN ANSWER ONLY!(with your terminal #!) in the first ten minutes of the due date class. Also an implementation in NetBeans Java is ALSO required, thus you are to submit the ZIPPED project to BB and download it in 200 PGH the first 10 minutes of class. Hardcopy with screenshots of the running program and the SOURCE CODE is also needed. I CERTIFY THAT THE HOMEWORKs SOLUTIONs ARE MY OWN WORK! SIGNATURE: HOMEWORK CHECKLIST (YOU MUST GRADE YOURSELF!): 1. DID TURN IN HOMEWORK INSTRUCTIONS? * -10 points 2. 1.? 40 points 3. 2.? 60 points 4. Homework8.2 JAVA.zip NOT submitted to BB? * -50 points 5. Homework8.2 JAVA.zip NOT running in 200 PGH? * -50 points * If NOT, do not enter anything in the box! PLEASE ENTER YOUR GRADE IN THIS BOX: I understand that if the .zip file is NOT in BB and I did not check the BOX, I will get a ZERO for the Homework! TURNING IN THE HOMEWORK INSTRUCTIONS will be PENALTY OF -10 points. I UNDERSTAND THAT TURNING ANOTHER’s WORK IN is CHEATING. I UNDERSTAND THAT ANY KIND OF DISSEMINATION of this WORK is CHEATING. V X ?

description

hw 8

Transcript of HW8

Page 1: HW8

Name: ______________________ Term # ____

Homework 8 - On Lecture 10 – File I/O (100 points) Hours:

The homework is to be turned in as a PAPER AND PENCIL i.e.,

HANDWRITTEN ANSWER ONLY!(with your terminal #!) in the first

ten minutes of the due date class.

Also an implementation in NetBeans Java is ALSO required, thus you

are to submit the ZIPPED project to BB and download it in 200 PGH

the first 10 minutes of class. Hardcopy with screenshots of the running

program and the SOURCE CODE is also needed.

I CERTIFY THAT THE HOMEWORKs SOLUTIONs ARE MY OWN WORK!

SIGNATURE:

HOMEWORK CHECKLIST (YOU MUST GRADE YOURSELF!):

1. DID TURN IN HOMEWORK INSTRUCTIONS? * -10 points

2. 1.? 40 points

3. 2.? 60 points

4. Homework8.2 JAVA.zip NOT submitted to BB? * -50 points

5. Homework8.2 JAVA.zip NOT running in 200 PGH? * -50 points

* If NOT, do not enter anything in the box!

PLEASE ENTER YOUR GRADE IN THIS BOX:

I understand that if the .zip file is NOT in BB and I did

not check the BOX, I will get a ZERO for the Homework!

TURNING IN THE HOMEWORK INSTRUCTIONS will be PENALTY OF -10 points.

I UNDERSTAND THAT TURNING ANOTHER’s WORK IN is CHEATING.

I UNDERSTAND THAT ANY KIND OF DISSEMINATION of this WORK is CHEATING.

V X ?

Page 2: HW8

2

1. (40 pts)

a. (5 pts) What kind of exception might be thrown by the following, and

what would it indicate if this exception were thrown?

PrintWriter outputStream = new PrintWriter(new FileOutputStream("stuff.txt"));

ANSWER:

b. (5 pts) Might the following throw an exception that needs to be caught or

declared in a throws clause?

Scanner inputStream = new Scanner(new FileInputStream("morestuff.txt"));

ANSWER:

c. (30 pts) Write a complete Java program that tests whether or not the

directory (folder) containing the program also contains a file named

COSC.txt.

The program has no input and the only output tells whether or not there is a

file named COSC.txt.

Netbeans AS HOMEWORK8.c build and run, Source Code and Screenshot.

ANSWER:

Page 3: HW8

3

2. (60 pts)

The textfiles boynames. txt and girlnames. txt, which are included in the

source code for this book, contain a list of the 1,000 most popular boy and

girl names in the United States for the year 2003 as compiled by the Social

Security Administration.

These are blank- delimited files where the most popular name is listed first,

the second most popular name is listed second, and so on, to the 1,000th

most popular name, which is listed last. Each line consists of the first name

followed by a blank space and then the number of registered births using that

name in the year. For example the girlnames. txt file begins with:

Emily 25494

Emma 22532

Madison 19986

This indicates that Emily was the most popular name with 25,494 registered

namings, Emma was the second most popular with 22,532, and Madison was

the third most popular with 19,986.

Write a program that reads both the girl’s and boy’s files into memory using

arrays. Then, allow the user to input a name. The program should search

through both arrays. If there is a match, then it should output the popularity

ranking and the number of namings. The program should also indicate if

there is no match.

For example, if the user enters the name “ Justice,” then the program should

output:

Justice is ranked 456 in popularity among girls with 655 namings.

Justice is ranked 401 in popularity among boys with 653 namings.

If the user enters the name “ Walter,” then the program should output:

Walter is not ranked among the top 1000 girl names.

Walter is ranked 356 in popularity among boys with 775 namings.

Page 4: HW8

4

a. (10 pts) OOA & OOD: Draw the UML Class Diagram.

ANSWER:

b. (50 pts) Implementation: In Netbeans AS HOMEWORK8.2 build

and run. Source Code and Screenshots as hardcopy.

Submit the ZIPPED NetBeans project to Black Board!

http://media.pearsoncmg.com/aw/aw_savitch_abjava_4/videos/video10_2_1/video.html

http://media.pearsoncmg.com/aw/aw_savitch_abjava_4/videos/video10_2_2/video.html

ANSWER: