Create a class that will bundle together several static methods for tax computat
ID: 3536095 • Letter: C
Question
Create a class that will bundle together several static methods for tax computations. This class should not have a constructor. Its attributes are
basicRate-the basic tax as a static double variable that starts as 4 percent
luxuryRate-the luxury tax rate as a static double variable that starts as 10 percent
Its methods are
computeCostBasic(price)-a static method that returns the given price plus the basic tax, rounded to the nearest penny.
computeCostLuxury(price)-a static method that returns the given price plus the luxury tax, rounded to the nearest penny.
changeBasicRateTo(newRate)- a static method that changes the basic tax rate.
changeLuxuryRateTo(newRate)- a static method that changes the luxury tax rate.
roundToNearestPenny(price)- a private static method that returns the given price rounded to the nearest penny. For example, if the price is 12.567, the method will return 12.57.
Explanation / Answer
// TaxComputation.java //please rate import java.util.*; public class TaxComputation { Create a class that will bundle together several static methods for tax computations. This class should not have a constructor. Its attributes are public static double basicRate= 0.04; public static double luxuryRate=0.10; //-a static method that returns the given price plus the basic tax, rounded to the nearest penny. public static double computeCostBasic(double price){ double value = price*(1+ basicRate); return roundToNearestPenny(value); } //-a static method that returns the given price plus the luxury tax, rounded to the nearest penny. public static double computeCostLuxury(double price){ double value = price*(1+ luxuryRate); return roundToNearestPenny(value); } //- a static method that changes the basic tax rate. public static void changeBasicRateTo(double newRate){ basicRate=newRate; } //- a static method that changes the luxury tax rate. public static void changeLuxuryRateTo(double newRate){ luxuryRate=newRate; } //- a private static method that returns the given price rounded to the nearest penny. //For example, if the price is 12.567, the method will return 12.57. public static double roundToNearestPenny(double price){ double value= (int)(price*100+.5)/100.0; } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.