Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

11. If the value of f(x, y, z) is always an integer, which of the following conditions ensures that the loop below terminates? while (f(x,

11. If the value of f(x, y, z) is always an integer, which of the following conditions ensures that the loop below terminates?

while (f(x, y, z) < 100) { }

Question 11 options:

1)

x, y, and z are each increased during each iteration.

2)

The value of f(x, y, z) is increased during each iteration.

3)

x, y, and z are each decreased during each iteration

4)

The sum of x, y, and z is decreased during each iteration.

5)

The value of Math.pow (f(x, y, z), 2) is decreased during each iteration.

12. The following program segment is intended to sum a[0] through a[n-1], where n = a.length: sum = 0; i = 0; n = a.length; while (i != n) { i++; sum += a[i]; }

In order for this segment to perform as intended, which of the following modifications, if any, should be made?

Question 12 options:

1)

no modification is necessary

2)

sum = 0; i = 0; should be changed to sum = a[1]; i = 1;

3)

while (i != n) should be changed to while (i <= n)

4)

sum += a[i]; should be changed to sum += a[i+1];

5)

i++; should be interchanged with sum += a[i];

13. What is the output of the following program?

int sum = 0, k, val = 1; for (k = 0; k <= 8; k++) { sum += val; val++; } System.out.println(sum);

Question 13 options:

1)

28

2)

15

3)

12

4)

45

5)

21

14. How can you identify a constructor in a class file?

I. The name of the constructor is the same as the name of the class. II. The name of the constructor is the same as the name of the file (without .java). III. The constructor looks like a method, but it has no return type (not even void).

Question 14 options:

1)

I only

2)

II only

3)

III only

4)

I and III only

5)

I, II, and III

When is it not necessary to invoke method myMethod using dot notation?

Question 15 options:

1)

When myMethod is private.

2)

When myMethod is invoked by a method in the same class as myMethod.

3)

When myMethod is public.

4)

When myMethod is both private and static.

5)

When myMethod is invoked by a method in a different class than myMethod.

16. What is a mutator method?

Question 16 options:

1)

A method that returns an instance variable or a calculation.

2)

A method that modifies an instance variable.

3)

A constructor that initializes instance variables.

4)

Any method that has a return value other than void.

5)

Any method that has a return value of void.

17. What is the output of the following code? ArrayList grades = new ArrayList(); grades.add(88); grades.add(92); grades.add(95); grades.add(83); System.out.println(grades.get(grades.size()));

Question 17 options:

1)

4

2)

An ArrayIndexOutOfBoundsException occurs.

3)

An IndexOutOfBoundsException occurs.

4)

92

5)

95

6)

83

18. public class WeatherSnapshot

{ private int tempInFahrenheit; private int humidity; // value of 56 means 56% humidity private int dewpoint; // in degrees Fahrenheit private Date date; // uses a Date object to store the date private int time; // in military time, such as 1430 = 2:30 pm private boolean cloudy; // true if 25% or more of the sky is covered // constructor not shown, but it initializes all instance variables // postcondition: returns temperature public int getTemp() { return tempInFahrenheit; } // postcondition: returns date public Date getDate() { return date; } // postcondition: returns true if precipitation is likely; false otherwise public boolean precipitationLikely() { // implementation not shown } // other methods not shown }

Which of the following is a class constructor? I. getTemp II. precipitationLikely III. WeatherSnapshot

Question 18 options:

1)

I only

2)

I and II only

3)

II only

4)

I and III only

5)

III only

19. Consider the following class designed to store weather statistics at a particular date and time.

public class WeatherSnapshot { private int tempInFahrenheit; private int humidity; // value of 56 means 56% humidity private int dewpoint; // in degrees Fahrenheit private Date date; // uses a Date object to store the date private int time; // in military time, such as 1430 = 2:30 pm private boolean cloudy; // true if 25% or more of the sky is covered // constructor not shown, but it initializes all instance variables // postcondition: returns temperature public int getTemp() { return tempInFahrenheit; } // postcondition: returns date public Date getDate() { return date; } // postcondition: returns true if precipitation is likely; false otherwise public boolean precipitationLikely() { // implementation not shown } // other methods not shown }

Suppose a WeatherSnapshot object named currentWeather has been correctly instantiated in a client class. Which of the following will correctly call the precipitationLikely method?

Question 19 options:

1)

boolean couldRain = precipitationLikely();

2)

boolean couldRain = currentWeather.precipitationLikely();

3)

boolean couldRain = currentWeather.precipitationLikely()

4)

double percentChanceOfRain = precipitationLikely();

5)

double percentChanceOfRain = currentWeather.precipitationLikely();

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

What methods do communication scholars use to conduct research?

Answered: 1 week ago