1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Vladimir [108]
3 years ago
12

Consider the following instance variables and incomplete method that are part of a class that represents an item. The variables

years and months are used to represent the age of the item, and the value for months is always between 0 and 11, inclusive. Method updateAge is used to update these variables based on the parameter extraMonths that represents the number of months to be added to the age.
private int years;
private int months; // 0 <= months <= 11
public void updateAge(int extraMonths)
{
/* body of updateAge */
}
Which of the following code segments shown below could be used to replace /* body of updateAge */ so that the method will work as intended?
I int yrs = extraMonths % 12;
int mos = extraMonths / 12;
years = years + yrs;
months = months + mos;
II int totalMonths = years * 12 + months + extraMonths;
years = totalMonths / 12;
months = totalMonths % 12;
III int totalMonths = months + extraMonths;
years = years + totalMonths / 12;
months = totalMonths % 12;
a. I only
b. II only
c. III only
d. I and II only
e. II and III
Computers and Technology
1 answer:
velikii [3]3 years ago
3 0

Answer:

e. II and III

Explanation:

Given

The above code segment

Required

Which can complete the updateAge() method

From the program we understand that the updateAge() will update the year and month based on the extraMonths passed to it.

For instance

<em />years = 6<em> and </em>months = 8<em />

<em>updateAge(5) will update years to 7 and month 1</em>

Having established that, next we analyze options I, II and III

<u>Code I</u>

1. This divides extraMonths by 12 and saves the remainder in yrs.

For instance: 15 months = 1 year and 3 months. So:

yrs = 3

2. This divides extraMonths by 12 and saves the whole part in mos

For instance: 15 months = 1 year and 3 months. So:

mos = 1

3. This updates the value of years by the result of 1 (i.e. the remaining months)

4. This updates the value of years by the result of 2 (i.e. the remaining years)

months = months + mos;

Conclusion:, (I) is incorrect because years and months were updated with the wrong values

<u>Code II</u>

1. This converts years to months, then add the result of the conversion to extraMonths + month

For instance: years = 3; months = 6; extraMonths = 15

totalMonths = 3 * 12 + 6 + 15 = 57\ months

2. This calculates the number of years in totalMonths

years = totalMonths / 12;

i.e years = 57/12 = 4

3. This divides totalMonths by 12 and saves the remainder in months

months = totalMonths \% 12;

i.e. months = 57\%12 = 9

<u>Rough Calculation</u>

years = 3; months = 6; extraMonths = 15

3\ years + 6\ months + 15\ months = 4\ years\ 9\ months

Conclusion: Code II is correct

<u>Code III</u>

1. This calculates the total months

For instance: years = 3; months = 6; extraMonths = 15

totalMonths = 6 + 15 = 21\ months

2. This calculates the number of years in totalMonths, then add the result ot years

years = years + totalMonths / 12;

i.e. years = 3 + 21/12 = 3 + 1 = 4

3. This divides totalMonths by 12 and saves the remainder in months

months = totalMonths \% 12;

i.e. months = 21\%12 = 9

<u>Rough Calculation</u>

years = 3; months = 6; extraMonths = 15

3\ years + 6\ months + 15\ months = 4\ years\ 9\ months

Conclusion: Code III is correct

You might be interested in
Escribe 10 ejemplos de lo que consideras un byte
stira [4]

<u>Respuesta:</u>

Espero y te pueda ayudar: ).

4 0
3 years ago
PLEASE HELP! (12PTS)
Mrrafil [7]

I would say False, it is a personal computer and you should be able to update it yourself. ;w;

Your welcome <3

5 0
3 years ago
Rasheed is memorizing his multiplication tables by using flash cards. He does this frequently enough that eventually he does not
slavikrds [6]

Answer:

Long-term memory

Explanation:

There are two common types of memory - Long-term and short-term.

In short-term memory, information are stored just for a very short time before they are eventually discarded or transferred to the long-term memory. It is sometimes called working memory. For example, short-time memory can be used to remember that a particular event is going to be by 12pm today. After the event, the information might either be discarded or pushed to the long-term memory.

In long-term memory, information are stored for a very long term, almost permanently. For example, long-term memory enables you to remember an event that has taken place in the past. In the case of Rasheed, he has so much learned the multiplication tables in such a way that information on the tables have been stored indefinitely in a part of his brain called hippocampus. Every time he needs the multiplication tables, they are always available. So he is already taking advantage of the long-term memory.

4 0
3 years ago
Binary calculation of 1110÷101​
NemiM [27]
10.90 not sure tho. POWKSKS
3 0
3 years ago
Read 2 more answers
Which level of prevention describes a nurse conducting health awareness training programs at a community center?
zalisa [80]

The level of prevention describes a nurse conducting health awareness training programs at a community center is 1: Primary.

<h3>What is Health awareness?</h3>

This is known to be the full understanding in regards to the health, healthcare as well as  its services, health needs, and others.

Note that the reason for the Awareness training is one that is made for prevention, as well as early detection, targeted therapy and  other ways that are used to make sure of effective treatment.

Therefore, it is vital for one to be involved in it and as such, the level of prevention describes a nurse conducting health awareness training programs at a community center is 1: Primary.

Learn more about health awareness from

brainly.com/question/1676978

#SPJ1

See options below

Which level of prevention describes a nurse conducting health awareness training programs at a community center?

1

Primary

2

Secondary

3

Tertiary

4

Indirect

6 0
2 years ago
Other questions:
  • Server farms such as Google and Yahoo! provide enough compute capacity for the highest request rate of the day. Imagine that mos
    12·1 answer
  • Is 37 words per minute when typing an okay grade?
    15·2 answers
  • Which feature of a router provides traffic flow and enhances network security?
    6·1 answer
  • IDPSs can also help the organization protect its assets when its networks and systems are still exposed to ____________________
    9·1 answer
  • Which event occurred in the 1990s?
    5·1 answer
  • The clerk ordered three ribbons, 12 markers, and 15 erasers.
    10·1 answer
  • What is the traditional computer architecture long-supported by windows?
    6·1 answer
  • Richard needs to copy information from another slide presentation that uses a different design template. To ensure that the info
    10·1 answer
  • The _______ displays the name of the open file and the program
    11·1 answer
  • You have been hired as a security administrator. While analyzing your organization's personnel policies, you notice the presence
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!