CS 1401 Introduction to Computer Science
Fall 2012, Sample Test 2
(posted November 2, 2012)

Background: On November 2, 1815, George Boole was born. When George Boole was young, his father trained him in commerce. George did not follow in his father's path, he became a scientist, but the computational skills he learned from his father helped him in his research.

George Boole was the first to show that simple logical reasoning does not require high intellectual abilities, it can be performed by simple computations. In his honor, variables whose values are "true" and "false" are called boolean, and operations on these variables (like "and" and "or") are called boolean operations.

1. A normal price for a copy of George Boole's original book on logic was 3 shillings. However, a customer who decided to buy 10 or more copies got a wholesale price of 2 shillings per book. Define a Java method bill(int numOfCopies) that, given a number of copies, returns the total amount that one needs to pay for that many copies. In the main program, apply this method to compute the total amount that needs to be paid for buying 12 copies.

2. In addition to logic, Boole also studies how to analyze sequence of records made at different moments of time. For example, if we have temperatures recorded at different days, it is important to find the highest of these temperatures. Let us assume that the recorded temperatures are stored in the array temp, so that:

Write a method that, given an array of real numbers (of type double), computes the largest of all its elements. Trace your method step-by-step on the example of an array that has three elements: temp[0] = 70, temp[1] = 72, and temp[2] = 68.

3-4. The names of all the customers of the store owned by Boole Sr. are stored, in alphabetic order, in an array customers.

To compare two strings a and b, you can use the following Java operations:

5. Design a class Customer, each element of which contains three fields: the customer's name, the amount of money the customer spent on his or her purchases, and the customer's address. Do not forget to add a constructor method and accessor ("get") and modifier ("set") methods. In the main program, create a new object with your own name as a customer.

6. When George Boole was young, his father taught him how to compute the total amount of money earned from different customers during a day. Let us automate this task. Write a program that would:

This amount would then added to the total (in the beginning of the day, the total is 0). This process repeats until the user says "no" (N). At this point, the program should print the total amount earned during the day.

For example, if during the day, three customers came, the first bought 4 shillings worth of stuff, the second 5.5 shillings worth, and the third 1.5 shillings worth, then:

This value 11.0 should then be printed.