Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey my teacher attached a file that i\'ll copy and past for you. for some reason

ID: 3634399 • Letter: H

Question

Hey my teacher attached a file that i'll copy and past for you. for some reason i find it very confusing and cant figure out how to tackle the problem. If someone could provide me with the actual source code that be great. its due in 3 hours and im already working on other programs for this class because my teacher is crazy. please and thankyou. heres the problem:



public class TaxComputer {

private static double basicRate = 4.0;
private static double luxuryRate = 10.0;

1. 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 rate as a static double variable that starts at 4 percent - a private static method

• luxuryRate—the luxury tax rate as a static double variable that starts at 10
percent - a private static method
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

public class TaxComputer {

// 1. 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 rate as a static double variable that starts at 4 percent - a private static method
private static double basicRate = 0.04;

// • luxuryRate—the luxury tax rate as a static double variable that starts at 10 percent - a private static method Its methods are
private static double luxuryRate = 0.1;

// • computeCostBasic(price) —a static method that returns the given price plus the basic tax, rounded to the nearest penny.
public static double computeCostBasic(double price)
{
return roundToNearestPenny(price+basicRate*price);
}

// • computeCostLuxury(price) —a static method that returns the given price plus the luxury tax, rounded to the nearest penny.
public static double computeCostLuxury(double price)
{
return roundToNearestPenny(price+luxuryRate*price);
}

// • changeBasicRateTo(newRate) —a static method that changes the basic tax rate.
public static void changeBasicRateTo(double newRate)
{
basicRate = newRate;
}

// • changeLuxuryRateTo(newRate) —a static method that changes the luxury tax rate.
public static void changeLuxuryRateTo(double newRate)
{
luxuryRate = newRate;
}

// • 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.
public static double roundToNearestPenny(double price)
{
return Math.round(price*100)/100;
}