CS 1401, Final Exam

Date: Tuesday, May 3, 2005
Name (please type legibly, ideally in block letters): ______________________________________________________________________
UTEP ID # (if you do not remember it, it is OK): ______________________________________________________________________

Comment: Each problem is worth (approximately) the same number of points. Problems marked by two numbers are worth twice as many points as problems marked by a single number.

On May 3, 1810, Lord Byron, the famous English poet, swam the Hellespont, a wide sea strait separating Europe and Asia, to be together with his girlfriend. His daughter Ada Lovelace also became famous - in the field of computing.

1a. Explain the contribution of Ada Lovelace to computing. Hint: what computational device was she programming for?

1b. Describe, in detail, at least one more event from the history of computing (feel free to describe yet one more event for extra credit).

2. After writing an essay about Ada Lovelace, you realized that the only time you mentioned his last name, you got confused and accidentally used her maiden name "Ada Byron".

2a. Write a method that, given an arbitrary string essay in which the name "Ada Byron" appears exactly once, replaces it with "Ada Lovelace". Hint: your method must not read or print anything, just take the string as an input and return a corrected string as a result.

2b. What are the reasonable test cases for the method you described in Problem 2a? Hint: the name can appear in the beginning of the essay, at the end, at a random place, etc.

3. Ada Lovelace is working on her famous report. She has typed in a table of contents; the corresponding section headings are stored as strings section1, section2, ... Her advisor advised her to swap Sections 1 and 2, so that the material from Section 2 appears first, and the material that is now in Section 1 appears next.

3a. Write down a code fragment that would swap the values of the corresponding section headings.

3b. Trace, step by step, how this code fragment swaps them. Draw boxes corresponding to variables section1 and section2 and show how the contents of these variables will change at each step of the computations. Hint: do not forget that strings are a reference type.

4. To facilitate the reports writing, a company decided to define a class Section in which every object has a title (= section heading), the text itself (represented as a long string), and a report number (an integer).

4a. Write down a code that defines such a class. Hint: make sure that the values of the fields are private, and that there are appropriate get and set methods to return and change the values of these fields; do not forget the constructor!

4b. Some report sections come with an attached Java program (one more long string). Write down a code that defines the corresponding class SectionWithAppendix as a subclass of the class Section.

5-6. Different sections of a company report can have different levels of confidentiality. The company decided to mark them as follows: Write down two code fragments that, based on this letter, explicitly print out the corresponding exercise complexity; for example, the input P should lead to printing the word "public" etc. In both code fragments, do not forget to print an error message if the letter does not correspond to any of the above options.

5a. In the first code fragment, use if.

5b. In the second code fragment, use switch.

6a. Explain the comparative advantages and disadvantages of using if, switch, and ?:

6b. For extra credit: Write the third code fragment for solving the same problem, by use ?: instead of if or switch.

7-8. To speed us the process of producing reports, the company decided to design a Java program that collects the information about the report. For each proposed section of this report, the report writer types in: this information is recorded into the datafile. To finish the program, the report writer type in the word "end" instead of the section's title.

7. Write a code fragment that prompts the record writer for this information, and places this information, line by line, into the file report.dat:

8. Design a GUI interface that makes it easier for a report writer to enter this data. Feel free to assume that the necessary objects like a JFrame object have already been defined.

9. Once a file report.dat (as in Problem 7) with the proposed textbook information is ready, we need to transfer the corresponding information into the corresponding arrays title[] and pagesize[].

9a. Write a code fragment for transferring the data into these arrays.

9b. Write a method that, based on the arrays title[], and pagesize[], computes (and returns) the average page size of a section. Use += and for loop. Catch the division-by-zero exception that will be raised if we try to divide by 0.

Hint: to compute an average, add up all the page sizes and divide by the number of proposed books.

10a. Let us assume that a report has 13 section, and each section has 56 pages. If a computer has one (decimal) digit of precision, how would it estimate the overall number of pages in the report?

10b. Write down and explain the main ACM requirements for ethical professional behavior. Give one example of an ethical behavior related to computing (feel free to give one more example for extra credit).