Results 1 to 3 of 3
Thread: method problem *double
- 01-21-2013, 09:09 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 40
- Rep Power
- 0
Method Problem using Double
hello java masters,
I'm having problems with understanding how method work and how does it being pulled. I don't want the answer to my hw but I wish you guys could give me some clues and better understanding to my confusion. Just recently did method with boolean expression, i did that one fine, method had return with either true or false.
What I can't understand is how would you apply method when you are dealing with double. Basic program asks user to input their annual income and program will calculate their taxes. (done)
COPY OF GOOD PROGRAM WITHOUT METHOD:
NOW, when I'm trying to add method getting bunch of errors(12)Java Code:import java.util.Scanner; public class state_income_tax { public static void main(String [] args) { //prep Scanner kybd = new Scanner(System.in); final double LIMIT = 20000.00; final double REG_RATE = 0.02; final double HIGH_RATE = 0.025; final double FIXED = 400.00; double userInput; double tax; System.out.print("Please enter your income amount: "); userInput = kybd.nextInt(); System.out.println("");//spacing //calculation if(userInput<=LIMIT) { tax = REG_RATE*userInput; System.out.print("You owe to state of New Jersey $" + tax); } else { tax = HIGH_RATE*userInput+FIXED; System.out.print("You owe to state of New Jersey $" + tax); } } }
Any help on the method portion is greatly appreciated!Java Code:import java.util.Scanner; public class state_income_tax_wMethod { public static void main(String [] args) { //prep Scanner kybd = new Scanner(System.in); final double LIMIT = 20000.00; final double REG_RATE = 0.02; final double HIGH_RATE = 0.025; final double FIXED = 400.00; double userInput; double tax; double income; //added for method System.out.print("Please enter your income amount: "); userInput = kybd.nextInt(); income = calcStateTax(LIMIT, REG_RATE, HIGH_RATE, FIXED, userInput, tax); System.out.println("");//spacing //calculation System.out.print("You owe to state of New Jersey $" + tax); }//end of main public static double calcStateTax(double income) { if(userInput<=LIMIT) { tax = REG_RATE*userInput; // I know this is wrong, if I would use boolean I could use return true OR false. [B]I DON'T know how to apply method when using double[/B] } else { tax = HIGH_RATE*userInput+FIXED; } }//end of method }
BartLast edited by xcaldk74; 01-21-2013 at 10:31 PM.
- 01-21-2013, 09:37 PM #2
Member
- Join Date
- Jan 2012
- Posts
- 40
- Rep Power
- 0
Re: method problem *double
So I thought about it. Method needs return so this is what I have(method):
But I'm still getting error code saying that this method cannot be applied:Java Code:System.out.print("You owe to state of New Jersey $" + tax); }//end of main public static double calcStateTax(double income) { if(userInput<=LIMIT) { tax = REG_RATE*userInput; } else { tax = HIGH_RATE*userInput+FIXED; } return tax;
state_income_tax_wMethod.java:24: error: method calcStateTax in class state_income_tax_wMethod cannot be applied to given types;
income = calcStateTax(LIMIT, REG_RATE, HIGH_RATE, FIXED, userInput, tax);
^
required: double
found: double,double,double,double,double,double
reason: actual and formal argument lists differ in length
- 01-22-2013, 09:10 AM #3
Re: method problem *double
reason: actual and formal argument lists differ in length
This is how you call the method:
and this is the declaration:Java Code:calcStateTax(LIMIT, REG_RATE, HIGH_RATE, FIXED, userInput, tax);
Count the arguments and compare types.Java Code:public static double calcStateTax(double income)
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
Similar Threads
-
why are GObject method params double
By wileedingo in forum New To JavaReplies: 3Last Post: 05-06-2012, 08:27 PM -
double execution of a method
By matteo in forum AWT / SwingReplies: 0Last Post: 01-13-2011, 02:11 PM -
JSpinner getValue method bug in double?
By cotarelo in forum AWT / SwingReplies: 9Last Post: 07-05-2010, 05:53 PM -
non-static method add(double,double) cannot be referenced from a static context
By cravi85 in forum Java SoftwareReplies: 5Last Post: 03-21-2009, 09:32 PM -
Double Value problem
By sakthivel123 in forum New To JavaReplies: 2Last Post: 07-10-2008, 04:18 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks