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

All of these are Java questions: 1. The Math.ceil method in the Java standard li

ID: 3687690 • Letter: A

Question

All of these are Java questions:

1. The Math.ceil method in the Java standard library takes a single value x and returns the smallest integer that is greater than or equal to x. Which of the following is true about Math.ceil(56.75)? Select one: a. The argument is 56.75, and the return value is 57. b. The argument is 56.75, and the return value is 56. c. The argument is 57, and the return value is 56.75. d. The argument is 56, and the return value is 56.75

2.

A stub method is

Select one:

a. A short method

b. A method that has been unit tested

c. A method that acts as a placeholder and returns a simple value so another

method can be tested

d. A method that is broken down into smaller steps through step-wise

refinement

3.

The process of hand-tracing code is valuable because

Select one:

a. It is usually faster than just running the code.

b. It is the best way to design an algorithm.

c. You must already have a working program in order to do it.

d. It gives valuable insight that you do not get by running the code

4.

Assuming that the user provides 303 as input, what is the output of the following

code snippet?

int x;

int y;

x = 0;

Scanner in = new Scanner(System.in);

System.out.print("Please enter a number: ");

y = in.nextInt();

if (y > 300)

{

x = y;

}

else

{

x = 0;

}

System.out.println("x: " + x);

Select one:

a. x: 0

b. x: 300

c. x: 303

d. There is no output due to compilation errors

5.

Assuming that the user inputs a value of 25000 for the pay and 10 for the bonus

rate in the following code snippet, what is the output?

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

System.out.print("Enter the pay: ");

double pay = in.nextDouble();

System.out.print("Enter the bonus rate: ");

double bonus = in.nextDouble();

System.out.println("The new pay is " +

(pay + pay * (bonus / 100.0)));

}

Select one:

a. The new pay is 25000

b. The new pay is 25100

c. The new pay is 27500

d. The new pay is 30000

6.

Assuming that the user inputs “twenty” as the input, what is the output of the

following code snippet?

String numEmployeesStr;

Scanner in = new Scanner(System.in);

System.out.println("Please enter the number of your employees:

");

numEmployeesStr = in.next();

int numEmployees = Integer.parseInt(numEmployeesStr);

if (numEmployees < 10)

{

System.out.println("Very small business!");

}

else

{

System.out.println("Small business");

if (numEmployees > 100)

{

System.out.println("Mid size business");

}

else

{

System.out.println("Large business");

}

}

Select one:

a. Very small business!

b. Small business

c. Mid size business

d. Run-time error

7.

Assuming that a user enters 45 as the brightness of a lamp, which of the following

hand-trace tables is valid for the given code snippet?

int brightness = 0;

String description = "";

Scanner in = new Scanner(System.in);

System.out.print("Enter your lamp brightness (in watts): ");

brightness = in.nextInt();

if (brightness >= 120)

{

description = "very bright";

if (brightness >= 100)

{

description = "bright";

}

}

else

{

description = "pleasant";

if (brightness <= 50)

{

description = "dim";

}

}

Select one:

a.

brightness

description

0

""

45

"pleasant"

"dim"

b.

brightness

description

0

"very bright"

45

"bright"

c.

brightness

description

0

""

45

"bright"

"pleasant"

d.

brightness

description

0

"bright"

45

"pleasant"

8.

Question

8

Not yet answered

Marked out of 1.00

Assuming that a user enters 22 as the price of an item, which of the following hand

trace tables is valid for the code below?

public static void main(String[] args)

{

int price = 0;

Scanner in = new Scanner(System.in);

System.out.print("Please enter object’s price: ");

price = in.nextInt();

System.out.println("Object price is " + getStatus(price));

}

public static String getStatus(int price)

{

String status = "";

if (price >= 50)

{

status = "reasonable";

if (price >= 75)

{

status = "costly";

}

}

else

Question

9

Not yet answered

Marked out of 1.00

{

status = "inexpensive";

if (price <= 25)

{

status = "reasonable";

}

}

return status;

}

Select one:

a. PriceStatus0""22"inexpensive" "reasonable"

b. PriceStatus0"inexpensive"22"reasonable"  

c. PriceStatus0""22"reasonable" "costly"

d. PriceStatus0"reasonable"22"costly"

9.

What does the following statement sequence print?

String str = "Harry";

int n = str.length();

String mystery = str.substring(0, 1) + str.substring(n - 2, n);

System.out.println(mystery);

Select one:

a. Ha

b. Har

c. Hy

d. Hry

10.

What is the output of the following code snippet?

int[] myarray = { 10, 20, 30, 40, 50 };

System.out.print(myarray[2]);

System.out.print(myarray[3]);

Select one:

a. 1050

b. 2030

c. 3040

d. 4050

11.

What does the following statement sequence print?

final String str = "Java";

str += " is powerful";

System.out.println(str);

Select one:

a. Java is powerful

b. Java + is powerful

c. is powerful

d. Nothing; compile-time error

12.

During program development, errors are

Select one:

a. very rare

b. prevented by the compiler

c. automatically tracked by the Integrated Development Environment (IDE)

d. unavoidable

13.

Java 7 introduced enhanced syntax for declaring array lists, which is termed

Select one:

a. angle brackets.

b. method lists.

c. diamond syntax.

d. symmetric slants.

14.

Consider the following code snippet. What is the potential problem with the if

statement?

double average;

average = (g1 + g2 + g3 + g4) / 4.0;

if (average == 90.0)

{

System.out.println("You earned an A in the class!");

}

Select one:

a. Using == to test the double variable average for equality is error-prone.

b. The conditional will not evaluate to a Boolean value.

c. The assignment operator should not be used within an if-statement

conditional.

d. Literals should never be used in if statement conditionals

15.

Computer scientists have devised something that allows programmers to describe

tasks in words that are closer to the syntax of the problems being solved. This is

called a(n)

Select one:

a. Embedded system

b. Machine instruction

c. High-level programming language

d. Compiler

Explanation / Answer

1. The Math.ceil method in the Java standard library takes a single value x and returns the smallest integer that is greater than or equal to x. Which of the following is true about Math.ceil(56.75)? A

Select one:

a. The argument is 56.75, and the return value is 57.

b. The argument is 56.75, and the return value is 56.

c. The argument is 57, and the return value is 56.75.

d. The argument is 56, and the return value is 56.75

2.

A stub method is C

Select one:

a. A short method

b. A method that has been unit tested

c. A method that acts as a placeholder and returns a simple value so another

method can be tested

d. A method that is broken down into smaller steps through step-wise

refinement

3.

The process of hand-tracing code is valuable because D

Select one:

a. It is usually faster than just running the code.

b. It is the best way to design an algorithm.

c. You must already have a working program in order to do it.

d. It gives valuable insight that you do not get by running the code

4.

Assuming that the user provides 303 as input, what is the output of the following

code snippet? C

int x;

int y;

x = 0;

Scanner in = new Scanner(System.in);

System.out.print("Please enter a number: ");

y = in.nextInt(); //User enters 303.

if (y > 300) //303 > 300 is true.

{

x = y; //x value will become 303.

}

else

{

x = 0;

}

System.out.println("x: " + x); //303 will be printed to screen.

Select one:

a. x: 0

b. x: 300

c. x: 303

d. There is no output due to compilation errors

5.

Assuming that the user inputs a value of 25000 for the pay and 10 for the bonus

rate in the following code snippet, what is the output? C

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

System.out.print("Enter the pay: ");

double pay = in.nextDouble(); //25000 is read into pay.

System.out.print("Enter the bonus rate: ");

double bonus = in.nextDouble(); //10 is read into bonus.

System.out.println("The new pay is " +

(pay + pay * (bonus / 100.0))); new pay is: 25000 + 25000 * (10 / 100.0) = 25000 + 25000 * 0.1 = 27500.

}

Select one:

a. The new pay is 25000

b. The new pay is 25100

c. The new pay is 27500 //Its simple as the pay is 10% higher, which means 25000 * 1.1 = 27500.

d. The new pay is 30000