CS 1401, Quiz 4, TR version, based on Test 1

Date: Thursday, September 25, 2014
Name (please type legibly, ideally in block letters): ______________________________________________________________________

3. The following formula enables us to compute the volume V of a box with sides x, y, and z: V = xyz. Assuming that x, y, and z are already placed in the corresponding variables of type double, write a Java code statement for assigning the corresponding value to the variable v of type double. Explain, step-by-step, which arithmetic operations will be performed first, which next, etc., and trace the computations on the example when x = 2.0, y = 3.0, and z = 4.0. Explain what happens if you simply write xyz in your Java code.

(Turn over, please)

7. National Geographic is one of the most popular magazines. Write a piece of code that decides which of the three given magazines is the most popular. The titles of three magazines are stored in the variables mag1, mag2, and mag3, and the numbers of subscribers to each of these magazines is stored in the variables sub1, sub2, and sub3. Use if-then statements to write down a piece of Java code that prints the title of the most popular of the three magazines.

Comment: There is no need to read anything, assume that all six variables have already been assigned values.