CS 1401, Final Exam

Date: Wednesday, December 6, 2006
Name (please type legibly, ideally in block letters): ______________________________________________________________________

UTEP ID#:____________________             Class Section (Circle one): 9:30 am or 11:30 am

Each problem is worth (approximately) the same number of points. Extra credit for a problem will be given only if the problem itself is solved correctly. If you use extra sheets of paper, place your name on each sheet.

1. Describe the contribution of Herman Hollerith to computing. For extra credit: Describe one more event from the history of computing, and how this event affected the field of computing.


2. A music store owner is planning a big sale to promote rock and country music CDs. Write a method called totalCDSale that takes as inputs a number of rock CDs and a number of country music CDs and returns the pre-tax amount of the sale. Each rock CD is $7.50 and each country CD is $6.50.   Trace this method for a sale of 3 rock CDs and 4 country music CDs.

Your method should return 3 * $7.50 + 4 * $6.50 = $48.50.


For extra credit: describe a GUI design for entering the number of purchased CDs and displaying the total (pre-tax) sale amount; design an algorithm and/or write a code.


3. Define a class MusicCD in which each object has three private fields: title, musicGenre, and listPrice. Your code for defining the class should contain:


4. To attract young customers, a music store owner wrote a newspaper ad that offered a free copy of the Shrek soundtrack for customers presenting the ad and buying at least 10 music CDs. After writing the ad, the store owner checked the stock of Shrek CDs and found only 3 in stock. Before sending the ad to the newspaper, the store owner will have to change the free CD title from Shrek to Madagascar. Write a piece of code that, given a string paperAd that contains Shrek exactly once, replaces this title with Madagascar.


5. Write a method that swaps the values of two globally defined dollar amount variables named listPrice and salePrice. Trace your method on the example when originally the contents of the variable listPrice is 9.99, and the contents of the variable salePrice is 17.99. As a result of the swap, the first variable will now have the value 17.99, and the second will have the value 9.99.


6. A chat program has been optimized to allow single-letter entries for a list of user-defined chat abbreviations. A user has defined lol as L, NVM as N, FWIW as F, and BTDT as B. Assuming that the chat program stores single letter entries in the variable singleLetterEntry, write a piece of code that, based on the value of this variable, prints the corresponding abbreviation. If the letter is neither L, N, F, or B, print a blank space.

Write two versions of this code:

What are the relative advantages and disadvantages of using switch and if statements? For extra credit: what are the relative advantages and disadvantages of using ?: instead of if or switch statements?


7. The entire inventory of a music store is contained in a file as follows:


Write a piece of code that asks the user for the file name and then places the CD titles from the input file into an array name cdTitle, the corresponding number of copies into an array named cdCopies, and the corresponding music genre in an array named musicGenre so that:



The total number of CD titles should be placed into the variable cdTitleTotal. Use a try-catch statement to handle the situation when there is no file with the input file name and print out the corresponding error message.


8. Write a method that takes as input the array musicGenre and the number cdTitleTotal described in Problem 7, and returns the total number of “Rap” CD titles. Assuming that the number of titles in any genre can be from 0 to 1000, what are the reasonable test cases for this method? Give specific examples of the corresponding test data.


9. Use the algorithms that we learned in class to translate 8 and 9 into binary, add and multiply these numbers in binary, and translate the results back into decimal (to check the correctness of the result). Suppose that a computer has only one decimal significant digit, and it uses round-off; if you ask this computer to multiply 8.0 and 9.0, what will be the result?


10. Is it ethical to compare your answers with somebody else’s during an individual (not a team) exam? Is it ethical, instead of buying a copyrighted music CD, to download it, for free, from a webpage where it is illegally posted? For each of these two cases, present: