Question: ICS 141. Programming with Objects. Lab 5. Your Name: _____________________________________________________________ Points: 15 Points earned: You must attempt to complete the lab during lab time. If

ICS 141. Programming with Objects. Lab 5.

Your Name: _____________________________________________________________

Points: 15

Points earned:

You must attempt to complete the lab during lab time. If cannot, you may work on it outside and submit it by the beginning of the next class. But I will allow that only if you work on the problem in the assigned lab time. You may work alone or in a group of two. Your score will depend on how far you are able to complete the work and the correctness of the work. In this lab, you are asked to do Java programming use Java basic execution flow constructs.

Goals: To solidify the knowledge on I/O accesses, Java Exception management system, Java automatic file closing feature.

The Problem Statement

In this lab section, you are going to learn how to read data from keyboard and write the data to a disk file. You are going to write an application that has one class (simple enough). The requirements for this lab are to use the following classes: BufferedReader, InputStreamReader, System.in, FileWriter (cannot use Scanner class); to use the try-catch structure and use the automatic file closing feature.

This application will display the following message in the DOS console:

Enter a line of text (stop to quit), then hit enter.)

:

prompting the user type a line of string. The program will keep offer column symbol : until the user typed stop. For each line typed, the program will write it to a disk file named myData.txt (make sure that each new line is stored as separate line). The disk should be automatically closed when the program exits.

Please follow the following sequence of steps to generate the content (Test Case 1).

Test Case 1

At the prompt type: the first line

At the prompt type: the second line

At the prompt type: this line contains 8, 9, 10

At the prompt type: stop

Go to the appropriate directory, find and open the myData.txt file.

The Directory that the FileWriter will Write File to

Sometime, a programmer (especially the ones new to Java) will wonder where the input file should be put or where the written file is created. In this lab, we used one file written method

FileWriter fw = new FileWriter("myData.txt").

You will be given the opportunity of finding out where the file will be located.

SCORE YOUR POINTS BY DOING THE FOLLOWING

According to the information given above, draw a class diagram in the space below (using UML notation) (4 pts).

Answer:

Programming work

After debugging the code, cut and paste the Java source code in the space below (4 pts).

Answer:

The input file and output file are usually located at the root of a project. In the space below, give the absolute directory path for your projects bin and the absolute directory path of the output file myData.txt (including the file) (2 pts).

Answer:

Output the file content (in the space below, cut and paste the content of the output file myData.txt) (5 pts).

Answer:

Tip: there is an almost identical application in week 8s lecture notes.

Hand to your instructor the following:

1) this document (with all the bold faced sections finished), with screen capture stapled.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!