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.
May 8 is a big day for students: on May 8, 1886, the drink now known as Coca-Cola was invented.
1. Describe how the invention of logarithms helped computing.
For extra credit: Describe one more event form the history of computing, and how this event influenced the filed of computing.
2. ACM is planning a party to celebrate the end of the semester. Write a method called party that takes as inputs the number of pizzas and the number of cokes and returns the overall cost. Each pizza is $7.50 and each large bottle of coke is $2.50. Trace this method for a sale of 6 pizzas and 3 cokes.
Your method should return 6 * $7.50 + 3 * $2.50 = $52.50.
For extra credit: describe a GUI design for entering the number of pizzas and the number of cokes and displaying the overall cost; design an algorithm and/or write a code.
3. Define a class Party in which each object has three private fields: occasion (of type String), numberOfPizzas, and numberOfCokes. Your code for defining the class should contain:
4. ACM prepared a flier about the end-of-semester party, but accidentally mentioned pepsi instead of coke. Write a piece of code that, given a string flier that contains the word pepsi exactly once, replaces this word with coke.
5. In their database, ACM keeps the dates of different parties in the corresponding date variables endOfSemester and indepedenceDay. A student accidentally typed the wrong dates: July 4 into endOfSemester and May 11 for independenceDay. Write a method that swaps the values of these two variables. Trace your method on the above example; in this example, as a result of the swap, the variable endOfSemester will now have the value "May 11", and the variable independenceDay should have the value "July 4".
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 simplify communications about the party, ACM folks decided to use one-letter abbreviations: C means coke, P means pizza, and A means ACM. Assuming that the variable singleLetter 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 C, not P, 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. For auditing purposes, the information about all the parties organized by ACM is stored in a file as follows:
Write a piece of code that asks the user for the name of this file and then places the occasions into from the input file into an array namedoccasion, the corresponding number of pizzas into an array named pizzas, and the corresponding number of cokes into an array named cokes, so that:
8. Write a method that takes as input the array pizzas and the number numberOfParties described in Problem 7, and returns the total number of pizzas served at all the parties. Assuming that the number of parties can be between 0 and 20, 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 8 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 8.0, what will be the result?
10. To make the ACM party more fun, a student proposed to bring copyrighted music that he downloaded for free from a pirate website. Is it ethical?
Another student suggested that instead of testing the software that he is supposed to test on his job, he will simply ship this software and leave the office earlier to participate in the party. Is this ethical?
For each of these two cases, present:
For extra credit: present more arguments.