Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Directions: Select the choice that best fits each statement. The following question ( s ) refer to the following incomplete class declaration. A 4 1

Directions: Select the choice that best fits each statement. The following question(s) refer to the following incomplete class declaration.
A 41-line code segment reads as follows. Line 1: public class Time Record. Line 2: open brace. Line 3: private int hours, semicolon. Line 4: private int minutes, semicolon, forward slash, forward slash, 0 less than or equal to minutes less than 60. Line 5: forward slash, asterisk, asterisk, Constructs a Time Record object. Line 6: asterisk, at, param h the number of hours. Line 7: asterisk, Precondition, colon, h greater than or equal to 0. Line 8: asterisk, at, param m the number of minutes. Line 9: asterisk, Precondition, colon, 0 less than m less than 60. Line 10: asterisk, forward slash. Line 11: public Time Record, open parenthesis, int h comma int m, close parenthesis. Line 12: open brace. Line 13: hours equals h, semicolon. Line 14: minutes equals m, semicolon. Line 15: close brace. Line 16: blank. Line 17: forward slash, asterisk, asterisk, at, return the number of hours. Line 18: asterisk, forward slash. Line 19: public int get Hours, open parenthesis, close parenthesis. Line 20: open brace, forward slash, asterisk, implementation not shown, asterisk, forward slash, close brace. Line 21: blank. Line 22: forward slash, asterisk, asterisk, at, return the number of minutes. Line 23: asterisk, Post condition, colon, 0 less than or equal to minutes less than 60. Line 24: asterisk, forward slash. Line 25: public int get Minutes, open parenthesis, close parenthesis. Line 26: open brace, forward slash, asterisk, implementation not shown, asterisk, forward slash, close brace. Line 27: blank Line 28: forward slash, asterisk, asterisk, Adds h hours and m minutes to this Time Record. Line 29: asterisk, at, param h the number of hours. Line 30: asterisk, Precondition, colon, h greater than or equal to 0. Line 31: asterisk, at, param m the number of minutes. Line 32: asterisk, Precondition, colon, m greater than or equal to 0. Line 33: asterisk, forward slash. Line 34: public void advance, open parenthesis, int h comma int m, close parenthesis. Line 35: open brace. Line 36: hours equals hours plus h, semicolon. Line 37: minutes equals minutes plus m, semicolon. Line 38: forward slash, asterisk, missing code, asterisk, forward slash. Line 39: close brace. Line 40: forward slash, forward slash, Other methods not shown. Line 41: close brace.
Question
Consider the following declaration that appears in a class other than TimeRecord.
TimeRecord [] timeCards = new TimeRecord [100] ;
Assume that timeCards has been initialized with TimeRecord objects. Consider the following code segment that is intended to compute the total of all the times stored in timeCards.
A 5-line code segment reads as follows. Line 1: Time Record total equals new Time Record, open parenthesis, 0 comma 0, close parenthesis, semicolon. Line 2: for, open parenthesis, int k equals 0, semicolon, k less than time Cards, dot, length, semicolon, k, plus, plus, close parenthesis.
Line 3: open brace. Line 4: forward slash, asterisk, missing expression, asterisk, forward slash, semicolon. Line 5: close brace.
Which of the following can be used to replace /* missing expression */ so that the code segment will work as intended?
Responses
timeCards [ k ].advance ()
timeCards [ k ].advance ()
total += timeCards [ k ].advance ()
total += timeCards [ k ].advance ()
Option C shows a 2-line code segment that reads as follows. Line 1: total, dot, advance, open parenthesis, time Cards, open square bracket, k, close square bracket, dot, hours comma. Line 2: time Cards, open square bracket, k, close square bracket, dot, minutes, close parenthesis.
Image with alt text: Option C shows a 2-line code segment that reads as follows. Line 1: total, dot, advance, open parenthesis, time Cards, open square bracket, k, close square bracket, dot, hours comma. Line 2: time Cards, open square bracket, k, close square bracket, dot, minutes, close parenthesis.
Option D shows a 2-line code segment that reads as follows. Line 1: total, dot, advance, open parenthesis, time Cards, open square bracket, k, close square bracket, dot, get Hours, open parenthesis, close parenthesis, comma. Line 2: time Cards, open square bracket, k, close square bracket, dot, get Minutes, open parenthesis, close parenthesis, close parenthesis.
Image with alt text: Option D shows a 2-line code segment that reads as follows. Line 1: total, dot, advance, open parenthesis, time Cards, open square bracket, k, close square bracket, dot, get Hours, open parenthesis, close parenthesis, comma. Line 2: time Cards, open square bracket, k, close square bracket, dot, get Minutes, open parenthesis, close parenthesis, close parenthesis.

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

More Books

Students also viewed these Databases questions

Question

What is nonverbal communication?

Answered: 1 week ago