FC0-U71 practice question 24 of 25

A user is writing code to calculate the amount of pay for each worker at a company. The pay rate is the same for all workers. The code will use the formula amount_of_pay = nunber_of_hours * pay_rate Which of the following should be used in the code to represent pay_rate?

Full set: 171 questions

Domain Technology Fundamentals

Answer options
A: Object
B: Function
C: Constant Correct answer
D: Array
Correct Answer:
C. Constant
Explanation

The scenario states that the payrate is the same for all workers, meaning its value is fixed and should not change during the program's execution. In programming, a constant is the appropriate construct for a value that remains unchanged. Using a constant prevents accidental modification of the pay rate, making the code more robust, readable, and easier to maintain. The formula would then use this named constant instead of a "magic number," which is a good programming practice.

Why Incorrect

A. Object: An object is a complex data structure containing properties and methods. It is unnecessarily complex for representing a single, fixed numerical value like a pay rate.
B. Function: A function is a block of code designed to perform a specific task and return a result. It represents an action, not a static data value.
D. Array: An array is a data structure used to store a collection of multiple elements. It would be appropriate if there were different pay rates, not one single rate. ---

References

1. Oracle Corporation. (2023). Primitive Data Types. The Java™ Tutorials.

In the section "The final Keyword

" the official Java documentation states: "You can use the final keyword to denote a constant... This will render the variable PI a constant

meaning that its value cannot be changed." This directly supports the use of a constant for a fixed value like payrate.

2. Guttag

J. V. (2016). Introduction to Computation and Programming Using Python

With Application to Understanding Data (2nd ed.). MIT Press.

Chapter 2.2

"Variables and Types": While Python doesn't enforce constants

the text introduces the concept of binding names to values. The established convention for values not intended to change is to use all-caps names. This highlights the programming principle of distinguishing fixed values (constants) from those that can change (variables)

which is the core of the question.

3. Scott

M. L. (2015). Programming Language Pragmatics (4th ed.). Morgan Kaufmann.

Chapter 3.3.1

"Name-to-Object Bindings": This academic textbook distinguishes between variables

which can be reassigned to different values

and constants

which are "bound to a value only once." This fundamental definition confirms that a constant is the correct choice for a value like payrate that is established once and does not change.

Scroll to Top