A programmer notices that the following code snippet uses the same algorithm for computing interest earned, but with different variables, in the two places shown below and in several other places in the program. What could be done to improve the program?
Final double RATE1 = 10;
Final double RATE2 = 5.5;
Double interest = investment * RATE1 / 100;
) . .
Balance = balance + balance * RATE2 / 100;
A) Declare the rates as variables, not constants.
B) Define a method that looks up interest rates.
C) Define a method that prompts the user for an amount and a rate of interest, then returns the interest earned.
D) Define a method that computes the interest earned from an amount and a rate of interest.
Correct Answer:
Verified
Q52: A programmer notices that the following code
Q53: What is wrong with the following code?
Public
Q54: Which of the following is the best
Q55: Given the following code, what is the
Q56: What is wrong with the following code?
Public
Q58: What is the problem with the definition
Q59: You need to write a method that
Q60: Which of the following code snippets can
Q61: Assuming that a user enters 45 as
Q62: For a program that reads city names
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents