Hey im working on two other programs and was wondering if someone could provide
ID: 3634336 • Letter: H
Question
Hey im working on two other programs and was wondering if someone could provide me the source code for the following: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
static is an access modifier. It tells java to load those things with static first before executing. java runs as a stack on the computer's memory. a class is a blueprint. We make an Object from the blueprint. The java keyword 'new' is how this is done. If we write a java program without making the Object, we must use static. First a typical class... class MyTaxClass { // variables that would belong to the class // each time a copy (Object) is made // the constructor public MyTaxClass( argument1, argument2) { classVar1 = argument1; classVar2 = argument2; } // another constructor public MyTaxClass() { // this is what java would make if we don't put any // constructor into the class } // then your methods private void addEm() { classVar1 += classVar2; } } // end of class so, the above is not a program. No main(). Gotta hava main() to kickstart a starting point in java. So we would write another class that uses the above class MyTaxProgram { public static void main(String[] args) { MyTaxClass smithAccount = new MyTaxClass(); // I have an Object, I can use the method defined above smithAccount.addEm(); } I thought u needed that explanation for static. Many java programs are written to run just as a program. No Object. Thus, we get to your problem. Everything has to have static in front of it. Your assignment is asking for a class (only) and they want static, so those things will load first. public class TaxComputate { // the class vars static double basicRate = .04; static double luxuryRate = .10; // no constructor, and we don't need one // the vars come pre-loaded public static String computeCostBasic( double price ) { double subTot = price + (price * basicRate); return roundToNearestpenny( subTot ); } private static String roundToNearestPenny( double total ) { // I like String.format(). It does the best rounding // fluk em if they can't take a joke, I say String rounded = String.format("%5.2f", total ); return rounded; } } String.format(.... % = a placeholder %5.2 = 5 digits with 2 decimals f= the value is a float or a double ,total = the var with the actual value and, if they want the String from roundToNearestPenny converted into a value again.... public static double getValue( String roundedAmt ) { return Double.parseDouble( roundedAmt ); }