Results 1 to 3 of 3
  1. #1
    xcaldk74 is offline Member
    Join Date
    Jan 2012
    Posts
    40
    Rep Power
    0

    Question 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:

    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);
             }
          	
          		
          }
       
       }
    NOW, when I'm trying to add method getting bunch of errors(12)

    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
       
       
       
       }
    Any help on the method portion is greatly appreciated!

    Bart
    Last edited by xcaldk74; 01-21-2013 at 11:31 PM.

  2. #2
    xcaldk74 is offline Member
    Join Date
    Jan 2012
    Posts
    40
    Rep Power
    0

    Default Re: method problem *double

    So I thought about it. Method needs return so this is what I have(method):

    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;
    But I'm still getting error code saying that this method cannot be applied:

    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

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default Re: method problem *double

    reason: actual and formal argument lists differ in length

    This is how you call the method:
    Java Code:
    calcStateTax(LIMIT, REG_RATE, HIGH_RATE, FIXED, userInput, tax);
    and this is the declaration:
    Java Code:
    public static double calcStateTax(double income)
    Count the arguments and compare types.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. why are GObject method params double
    By wileedingo in forum New To Java
    Replies: 3
    Last Post: 05-06-2012, 09:27 PM
  2. double execution of a method
    By matteo in forum AWT / Swing
    Replies: 0
    Last Post: 01-13-2011, 03:11 PM
  3. JSpinner getValue method bug in double?
    By cotarelo in forum AWT / Swing
    Replies: 9
    Last Post: 07-05-2010, 06:53 PM
  4. Replies: 5
    Last Post: 03-21-2009, 10:32 PM
  5. Double Value problem
    By sakthivel123 in forum New To Java
    Replies: 2
    Last Post: 07-10-2008, 05:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •