CSAS 1112 - Take-Home Final Exam



CSAS 1112 - Take-Home Final Exam

This exam comes in two pieces: Part 1 contains questions that do not require you to create any code, part 2 requires you to create complete, fully functioning Java programs that must be used to answer the respective questions. All answers and all Java code must be entered into this document. The completed document must be submitted via email or on disk no later than Monday, April 30, 10:20am. If you have any questions or problems, please contact me via ASAP.

You will need to download several data files for part 2 of this exam. You can find them at . Make sure to right-click on the appropriate links and select Save As … to save the files to the appropriate directories on your hard disk.

Part 1: Questions

1. Explain, in your own words, the following terms:

a) PrintWriter

b) DataInputStream

c) Excpetion

d) try-catch

e) ASCII code

2. Provide short answers to the following questions:

a) What dangers, if any, are involved when using a code segment such as new FileWriter("autoexec.bat")

b) What is the difference between character-level and byte-level data files?

c) If 8 bits are used to represent one character, how many different characters can be represented at most?

d) Is a String more like an array of characters, or a list of characters (here list refers to the type of linked lists discussed in class).

e) Can you read a character-level file with a standard text editor?

f) Can you read a byte-level file with a standard text editor?

g) If you create a program that needs to read data from a file, would you use an input stream or an output stream?

h) Why is the method to write a String to a DataOutputStream called writeUTF and not simply writeString?

i) The standard main method of a Java program has the method header

public static void main(String args[])

What type is the variable args, and where could its values come from?

3. If you write two Java int values to a file using a DataOutputStream, and you subsequently read one double value from that file using a DataInputStream, will your program crash? If it does not crash, what will be the value of the double read? Explain. What would happen if you attempt to write one double value but read one int back? How about writing one int value but attempting to read one double value back?

4. Suppose a text file contains the following lines of text, in this format:

May the force

be with you

When the file is saved, you notice it takes 26 bytes. Why that many?

5. If the String "May the force be with you" is saved to disk using a DataOutputStream's writeUTF method, will it occupy exactly 24 bytes, or more, or less? Explain. If it occupies more than 24 bytes, what type of information is stored in the extra bytes?

6. If the double value 100.123456789 is written to a file using the writeDouble method of a DataOutputStream, how many bytes will it occupy? If the same value is written using the println method of a PrintWriter, how many bytes will it occupy, approximately? Explain the difference, if any.

Part 2: Java Programs

1. A data file has been created using Java's DataOutputStream class. It contains a String, a double, another String, and two int values. Download the data file "question1.dat" from our web site. Then create a program to read the String, the double, the String, and the two int from the file and tell me what their values are.

String 1: _______________________

double: _______________________

String 2: _______________________

int: _______________________

int: _______________________

Your Program:

2. A data file has been created using Java's OutputStream class. It contains an int value and a number of String-double pairs, where the integer indicates the number of pairs that are contained in the file. For example, if the first integer value is 4, there will be 4 pairs in the form double-String following that int value. Download the data file "question2.dat" from our web site. Then create a program to find the average of the double values contained in the file. You do not need to do anything with the String values (but you may still need to read them).

int: _______________________

average: _______________________

Your Program:

3. A text file "question3.txt" has been created using Java's PrintWriter class, containing some lines of text. Download the data file "question3.txt" from our web site. Then create a Java program that reads the text from file, reverses the entire text, and writes the reversed text to an output text file named "output.txt".

Input Text: _______________________

_______________________

_______________________

_______________________

_______________________

Output Text: _______________________

_______________________

_______________________

_______________________

_______________________

Your Program:

4. Create a program to find the most frequent letter in a text file. Create that program as flexible as you can (but you do not need to create a GUI-based program).

Your Program:

Extra Credit: Create a program to find the frequency of the 5 most frequent letters in a text file.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download