Each problem is worth (approximately) the same number of points. Extra credits for a problem will be given only if the problem itself is solved correctly. If you use extra sheets of papers, please place your name on each sheet.
On May 10, 1924, J. Edgar Hoover became the Director of FBI. Under his leadership, FBI successfully fought against the Mafia, who was at that time smuggling alcohol into the USA. FBI succeeded in jailing Mafia's leader Al Capone. Hoover remained the FBI Director until his death in 1972.
1. Describe the contribution of Ada Lovelace to computing.
For extra credit: Describe one more event form the history of computing, and how this event influenced the filed of computing.
2. Al Capone is planning to smuggle a load of whisky and beer into the US. Write a method called smuggling that takes as inputs the number of bottles of whisky and the number of bottles of beer and returns the overall expected profit. Each whisky bottle brings a profit of $5.00 and each bottle of beer bring $0.50.
Trace this method for smuggling of 20 bottles of whisky and 10 bottles of beer. Your method should return 10 * $5.00 + 10 * $0.50 = $105.00.
For extra credit: describe a GUI design for entering the number of bottles of whisky and the number of bottles of beer and displaying the overall expected profit; design an algorithm and/or write a code.
3. Define a class Smuggling in which each object has three private fields: smugglerName (of type String), numberOfWhiskies, and numberOfBeers. Your code for defining the class should contain:
4. Al Capone prepared a letter to send to the bars about the incoming shipment. His advisors advised him to replace the word "whisky" (which may get him in trouble) with the words "Irish milk". Write a piece of code that, given a string letter that contains the word whisky exactly once, replaces this word with Irish milk.
5. Al Capone originally planned for his friend Bugsy Siegel to smuggle whisky from Canada, and for his other friend Scarface to smuggle alcohol from Mexico via El Paso. So, he placed the value "Bugsy Siegel" into the variable canada, and the value "Scarface" into the variable mexico. It turned out that Bugsy was in Las Vegas, closer to El Paso, so Al Capone decided to swap the assignments. Write a method that swaps the values of the two above variables. Trace your method on the above example; in this example, as a result of the swap, the variable mexico will now have the value "Bugsy Siegel", and the variable canada should have the value "Scarface".
Hint: your program should work (i.e., swap the values) for all possible values of these two variables, not just the ones used in the example.
6. To make sure that FBI did not find out their secrets, the gangsters decided to use one-letter abbreviations: W means whisky, B means beer, and A means Al Capone. Assuming that the variable secretLetter contain one of these abbreviation, write a piece of code that, based on the value of this variable, prints the meaning of the corresponding abbreviation. If the letter is neither W, not B, nor A, print a blank space.
Write two versions of this code:
For extra credit: what are the relative advantages and disadvantages of using ?: instead of if or switch statements?
7. To keep track of all their profits, the gangsters decided to store all the information about smuggling in a file as follows:
Write a piece of code that asks the user for the name of this file and then places the smuggler names from the input file into an array named smuggler, the corresponding number of whiskies into an array named whiskies, and the corresponding number of beers into an array named beers, so that:
8. Write a method that takes as input the array whiskies and the number smugglings described in Problem 7, and returns the total number of whiskies smuggled into the US. Assuming that the number of smugglings can be between 0 and 10, 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 5 and 10 into binary, add and multiply these numbers in binary, and translate the results back into decimal (to check the correctness of the result).
For extra credit: Suppose that a computer has only one decimal significant digit, and it uses round-off; if you ask this computer to add 5.0 and 10.0, what will be the result?
10. To help fight crime, a student interning at FBI wrote a code enabling people to tap into phone conversations, and suggested to this bosses that they use without asking for an official approval. Is it ethical?
Since FBI does not have the latest software to process its databases, the same student suggested to download an illegally posted copy of a new code cracking software. Is such downloading ethical?
For each of these two cases, present:
For extra credit: present more arguments.