1

Currently learning Java right now, seems like a more difficult version of Python. Right now, we are learning about classes, and how to transfer Variables between classes. The project is simple, we are given two classes that have to do with taxes, and one class is the main, and the other sets the variables. While not adjusting the main class, how would you go through and debug these classes?

Main Class:

public class TaxFormTest {

    public static void main(String[] args)
    {
        TaxForm michiganStateTaxForm = new TaxForm();

        michiganStateTaxForm.setTaxRate(.07);
        System.out.println("Tax Form Rate: " + michiganStateTaxForm.getTaxRate());

        michiganStateTaxForm.setTaxRate(.09);
        System.out.println("Tax Form Rate: " + michiganStateTaxForm.getTaxRate());
    }
}

Secondary Class:

public class TaxForm{

    int taxRate;
    int rate;
    private double taxrate;

    public void setTaxRate()
    {
        taxRate = rate;
    }

    public double getTaxRate()
    {
        return taxrate;
    }

}

Thank you if you are able to assist me on this question.

PM 77-1
  • 12,933
  • 21
  • 68
  • 111
  • 3
    You copied the same class twice. – exception1 Jan 29 '16 at 23:41
  • maybe something is missing? Looks like both classes you posted are identical? In any regard, what you seem to be practicing is how to use Accessors (setters/getters, ie. `getTaxRate()` gets the tax rate and `setTaxRate(double)` sets the tax rate). When you call that method, the `TaxForm` object you've created will return the tax rate or set it (depending on which method you call). – SnakeDoc Jan 29 '16 at 23:42
  • Sorry about that guys. I went through and adjusted the code. Noob move on my part. – Gerry Smith Jan 29 '16 at 23:43
  • 1
    What is your exact problem? Have you ever debugged any Java code? – PM 77-1 Jan 29 '16 at 23:45
  • I believe the class `TaxForm` is not the updated/latest version. The `setTaxRate()` does not takes arguments. –  Jan 29 '16 at 23:54

1 Answers1

1

You want to make a call on a setter:

 michiganStateTaxForm.setTaxRate(.07);

This setter takes a double and sets it on the object.

Therefore your setter should look like this:

public void setTaxRate(double rate)
    {
        taxRate = rate;
    }

Also delete int rate; from your class TaxForm it does not make sense since you want the setter to have this as a parameter.

Marcinek
  • 2,144
  • 1
  • 19
  • 25