Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Suppose you need to write a method that calculates the volume of a 3D rectang

ID: 3680057 • Letter: 1

Question

1.

Suppose you need to write a method that calculates the volume of a 3D rectangular solid. Which of the following is the best choice for the declaration of this method?

Select one:

a. public static void volume(int a)

b. public static double volume(double w, double h, double l)

c. public static void volume(double w, double h, double l)

d. public static double volume(double w)

2.

For a program that reads city names repeatedly from the user and calculates the distance from a company's headquarters, which of the following would be a good design based on stepwise refinement?

Select one:

a. Write one method that calculates distance randomly.

b. Write one method that reads city name.

c. Write one method that reads city name and another method that calculates distance.

d. Write one method that reads distance and finds city name.

3.

Which process helps with identifying the methods that make up a computer program?

Select one:

a. Black boxing

b. Stepwise refinement

c. Parameter passing

d. Debugging

4.

Given the following method, what is the result of getNumber(n)?

Select one:

a. Always 0 for every argument n

b. Always 2 for every argument n

c. Close to 0, but not always 0

d. Compilation error

5.

You need to write a method that calculates the shipping cost for an appliance, which depends on the item's 3D dimensions and weight. What should be the inputs and their data types for this method?

Select one:

a. double size, double weight

b. double size, double weight, double price

c. double size, double weight, double shippingCost

d. double width, double height, double depth, double weight

6.

Which of the following is the correct header for a method definition named calcSum that accepts four int arguments and returns a double?

Select one:

a. public static double calcSum()

b. public static calcSum(int a, int b, int c, int d)

c. public static double calcSum(int a, int b, int c, int d)

d. public static int calcSum(double a, double b, double c, double d)

7.

What is the output of the following code snippet?

Select one:

a. fun(2) = 4

b. fun(2) = 8

c. fun(2) = 16

d. fun(2) = 32

Explanation / Answer

1) b) public static double volume(double w, double h, double l).

2) c) Write one method that reads city name and another method that calculates distance.

3) b) Stepwise refinement.

4) c) Close to 0, but not always 0.

5) d) double width, double height, double depth, double weight.

6) c) public static double calcSum(int a, int b, int c, int d).

7) b) fun(2) = 8.