Answered step by step
Verified Expert Solution
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 questions refer to the following incomplete class declaration.
A line code segment reads as follows. Line : public class Time Record. Line : open brace. Line : private int hours, semicolon. Line : private int minutes, semicolon, forward slash, forward slash, less than or equal to minutes less than Line : forward slash, asterisk, asterisk, Constructs a Time Record object. Line : asterisk, at param h the number of hours. Line : asterisk, Precondition, colon, h greater than or equal to Line : asterisk, at param m the number of minutes. Line : asterisk, Precondition, colon, less than m less than Line : asterisk, forward slash. Line : public Time Record, open parenthesis, int h comma int m close parenthesis. Line : open brace. Line : hours equals h semicolon. Line : minutes equals m semicolon. Line : close brace. Line : blank. Line : forward slash, asterisk, asterisk, at return the number of hours. Line : asterisk, forward slash. Line : public int get Hours, open parenthesis, close parenthesis. Line : open brace, forward slash, asterisk, implementation not shown, asterisk, forward slash, close brace. Line : blank. Line : forward slash, asterisk, asterisk, at return the number of minutes. Line : asterisk, Post condition, colon, less than or equal to minutes less than Line : asterisk, forward slash. Line : public int get Minutes, open parenthesis, close parenthesis. Line : open brace, forward slash, asterisk, implementation not shown, asterisk, forward slash, close brace. Line : blank Line : forward slash, asterisk, asterisk, Adds h hours and m minutes to this Time Record. Line : asterisk, at param h the number of hours. Line : asterisk, Precondition, colon, h greater than or equal to Line : asterisk, at param m the number of minutes. Line : asterisk, Precondition, colon, m greater than or equal to Line : asterisk, forward slash. Line : public void advance, open parenthesis, int h comma int m close parenthesis. Line : open brace. Line : hours equals hours plus h semicolon. Line : minutes equals minutes plus m semicolon. Line : forward slash, asterisk, missing code, asterisk, forward slash. Line : close brace. Line : forward slash, forward slash, Other methods not shown. Line : close brace.
Question
Consider the following declaration that appears in a class other than TimeRecord.
TimeRecord timeCards new TimeRecord ;
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 line code segment reads as follows. Line : Time Record total equals new Time Record, open parenthesis, comma close parenthesis, semicolon. Line : for, open parenthesis, int k equals semicolon, k less than time Cards, dot, length, semicolon, k plus, plus, close parenthesis.
Line : open brace. Line : forward slash, asterisk, missing expression, asterisk, forward slash, semicolon. Line : 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 line code segment that reads as follows. Line : total, dot, advance, open parenthesis, time Cards, open square bracket, k close square bracket, dot, hours comma. Line : time Cards, open square bracket, k close square bracket, dot, minutes, close parenthesis.
Image with alt text: Option C shows a line code segment that reads as follows. Line : total, dot, advance, open parenthesis, time Cards, open square bracket, k close square bracket, dot, hours comma. Line : time Cards, open square bracket, k close square bracket, dot, minutes, close parenthesis.
Option D shows a line code segment that reads as follows. Line : total, dot, advance, open parenthesis, time Cards, open square bracket, k close square bracket, dot, get Hours, open parenthesis, close parenthesis, comma. Line : 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 line code segment that reads as follows. Line : total, dot, advance, open parenthesis, time Cards, open square bracket, k close square bracket, dot, get Hours, open parenthesis, close parenthesis, comma. Line : 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started