• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java Problem

That sure looks like Java to me, not javascript. After looking at the code, I have a single question. Have you ever written a java program before?

The class you attached is called "taxwhiz3" and in its main method you declare four doubles "double rate, amount,taxWhiz, calcTax;"

Those 4 doubles make this line completely non-sensical "taxWhiz.calcTax = new taxWhiz(rate);"

1) We don't see the taxWhiz class, so if the class doesn't exist how are you going to construct an instance of it?
2) The taxWhiz variable is a double. There is not calcTax method in the double class.
3) If you aren't trying to call the calcTax method of the double class then you're really confused becase you're trying to use the "." operator between two variables.

4) Look at points 2 & 3 again, only for this line "System.out.println(taxWhiz.calcTax(amount));"
 
I have no experience coding. I have no interest in it either. This is a pre-req for my degree so i have to take it. That was an example the teacher gave me ( i added the double rate, amount...ect because it was erroring it and i figure it had to be there.

Im really lost and these assignments have nothing really to do with the chapter as the chapter was just concentrating on output text.
 
Originally posted by: Kilrsat
That sure looks like Java to me, not javascript. After looking at the code, I have a single question. Have you ever written a java program before?
My thoughts exactly. After seeing this, I thought maybe I wasnt as good as I thought I was with javascript. haha, but I think I probably am.

 
"/*
Define a class named TaxWhiz that computes the sales
tax for a purchase. It should store the current tax
rate as an instance variable. Following the model of
the Rectangle class, you can initialize the rate using
a TaxWhiz() method. This class should have one public
method, calcTax(double purchase), which returns a
double, whose value is purchases times the tax rate.
For example, if the tax rate is 4 percent, 0.04, and
the purchase is $100, then calcTax() should return
4.0.
*/"

Those are the instructions. You need to create a TaxWhiz class. Its constructor should take an argument (a double) that is the rate of tax for those purchases. The TaxWhiz class needs to have one fuction calcTax() that takes the purchase price as an argument and returns the amount of tax on that purchase.

Even a chapter on output has to cover the rough basics of what a class is because everything in Java is done inside a class. The instructions refer to a specific example "the Rectangle class" so I'm sure you have an example of what you need to do.

The skeleton structure of what you want to do is this, of course you need to fill in the details:
 
Originally posted by: BigJimbo
I have no experience coding. I have no interest in it either. This is a pre-req for my degree so i have to take it. That was an example the teacher gave me ( i added the double rate, amount...ect because it was erroring it and i figure it had to be there.

Im really lost and these assignments have nothing really to do with the chapter as the chapter was just concentrating on output text.

Take a look at the Java tutorial that Sun has provided on its website. There is a lot of good information in this guide, and it will also teach you a little bit about object oriented programming, which is fundamental to coding in Java.
 
Originally posted by: BigJimbo
okay im getting further. but what is this "TaxWhiz taxWhiz = new TaxWhiz(rate);" its haning up on that line.

"new TaxWhiz(rate)" makes a new TaxWhiz object and passes rate then "stores" it in the var taxWhiz or what ever you name it.

Example

Book myBook = new Book(65);
Apple a = new Apple();
TaxWhiz w = new TaxWhiz(5);
 
Back
Top