subject

Consider the following class definition. public class Element

{

public static int max_value = 0;

private int value;

public Element (int v)

{

value = v;

if (value > max_value)

{

max_value = value;

}

}

}

The following code segment appears in a class other than Element.

for (int i = 0; i < 5; i++)

{

int k = (int) (Math. random() * 10 + 1);

if (k >= Element. max_value)

{

Element e = new Element(k);

}

}

Which of the following best describes the behavior of the code segment?

Exactly 5 Element objects are created.

Exactly 5 Element objects are created.

A

Exactly 10 Element objects are created.

Exactly 10 Element objects are created.

B

Between 0 and 5 Element objects are created, and Element. max_value is increased only for the first object created.

Between 0 and 5 Element objects are created, and Element. max_value is increased only for the first object created.

C

Between 1 and 5 Element objects are created, and Element. max_value is increased for every object created.

Between 1 and 5 Element objects are created, and Element. max_value is increased for every object created.

D

Between 1 and 5 Element objects are created, and Element. max_value is increased for at least one object created.

Between 1 and 5 Element objects are created, and Element. max_value is increased for at least one object created.

E

The class Worker is defined below. The class includes the method getEarnings, which is intended to return the total amount earned by the worker.

public class Worker

{

private double hourlyRate;

private double hoursWorked;

private double earnings;

public Worker(double rate, double hours)

{

hourlyRate = rate;

hoursWorked = hours;

}

private void calculateEarnings()

{

double earnings = 0.0;

earnings += hourlyRate * hoursWorked;

}

public double getEarnings()

{

calculateEarnings();

return earnings;

}

}

The following code segment appears in a method in a class other than Worker. The code segment is intended to print the value 800.0, but instead prints a different value because of an error in the Worker class.

Worker bob = new Worker(20.0, 40.0);

System. out. println(bob. getEarnings());

Which of the following best explains why an incorrect value is printed?

The private variables hourlyRate and hoursWorked are not properly initialized.

The private variables hourlyRate and hoursWorked are not properly initialized.

A

The private variables hourlyRate and hoursWorked should have been declared public .

B

The private method calculateEarnings should have been declared public.

The private method calculateEarnings should have been declared public .

C

The variable earnings in the calculateEarnings method is a local variable.

The variables hourlyRate and hoursWorked in the calculateEarnings method are local variables.

E The variables hourlyRate and hoursWorked in the calculateEarnings method are local variables.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:00
Martha is a healer, a healthcare provider, and an experienced nurse. she wants to share her daily experiences, as well as her 12 years of work knowledge, with people who may be interested in health and healing. which mode of internet communication can martha use?
Answers: 3
question
Computers and Technology, 22.06.2019 18:40
Mariah was working on a multimedia presentation that included both video and audio files. the file was huge, and she wanted to send it to her coworker in another office. she needed to reduce the size of the file so that it could be transmitted faster. the utility she used to do this was
Answers: 2
question
Computers and Technology, 22.06.2019 20:30
In this lab, you complete a prewritten c program that calculates an employee’s productivity bonus and prints the employee’s name and bonus. bonuses are calculated based on an employee’s productivity score as shown below. a productivity score is calculated by first dividing an employee’s transactions dollar value by the number of transactions and then dividing the result by the number of shifts worked.
Answers: 3
question
Computers and Technology, 23.06.2019 04:00
Write a method that takes in an array of point2d objects, and then analyzes the dataset to find points that are close together. be sure to review the point2d api. in your method, if the distance between any pair of points is less than 10, display the distance and the (x,y)s of each point. for example, "the distance between (3,5) and (8,9) is 6.40312." the complete api for the point2d adt may be viewed at ~pf/sedgewick-wayne/algs4/documentation/point2d.html (links to an external site.)links to an external site.. try to write your program directly from the api - do not review the adt's source code.
Answers: 1
You know the right answer?
Consider the following class definition. public class Element

{

public sta...
Questions
question
French, 26.08.2021 22:00
question
Social Studies, 26.08.2021 22:00
question
Mathematics, 26.08.2021 22:00
Questions on the website: 13722363