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; Declare the tax rates as variables, not constants. Define a method that looks up tax rates for goods and shipping charges. Define a method that computes the cost after taxes from arguments for the cost before taxes and the tax rate. Define a method that prompts the user for an amount and a tax rate, then returns the total amount including the tax.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 7RQ
icon
Related questions
Question
ASAP pls
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
*(1 + TAXRATE1) / 100;
+ shipping *
= price
double total
= subtotal
(1 + TAXRATE2) / 100;
O Declare the tax rates as variables, not constants.
Define a method that looks up tax rates for goods and shipping charges.
Define a method that computes the cost after taxes from arguments for the cost
before taxes and the tax rate.
Define a method that prompts the user for an amount and a tax rate, then
returns the total amount including the tax.
Transcribed Image Text: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 *(1 + TAXRATE1) / 100; + shipping * = price double total = subtotal (1 + TAXRATE2) / 100; O Declare the tax rates as variables, not constants. Define a method that looks up tax rates for goods and shipping charges. Define a method that computes the cost after taxes from arguments for the cost before taxes and the tax rate. Define a method that prompts the user for an amount and a tax rate, then returns the total amount including the tax.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Storage Devices
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning