A programmer notices that the following code snippet uses the same algorithm for computing cost after taxes, but with different variables, in the two places as shown below, and in several other places in the program. What could be done to improve the program?
Final double TAXRATE1 = 10;
Final double TAXRATE2 = 5.5;
Double subtotal = price * (1 + TAXRATE1) / 100;
Double total = subtotal + shipping * (1 + TAXRATE2) / 100;
A) Declare the tax rates as variables, not constants.
B) Define a method that looks up tax rates for goods and shipping charges.
C) Define a method that prompts the user for an amount and a tax rate, then returns the total amount including the tax.
D) Define a method that computes the cost after taxes from arguments for the cost before taxes and the tax rate.
Correct Answer:
Verified
Q47: What is wrong with the following code?
Public
Q48: Which of the following is true about
Q49: You need to write a method that
Q50: What is wrong with the following code?
Public
Q51: Given the following code, which method call(s)
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
Q57: A programmer notices that the following code
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