Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Method in class cannot be applied to given types

  1. #1
    Junior Member
    Join Date
    Apr 2021
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Method in class cannot be applied to given types

    Im trying to make a program that takes taxpayer information and their tax dues.
    The tax due depends on income and marital status (single, married, or divorced and 0-20000, 20001-50000, or 50000+), i can probably figure this out later but im pretty stumped right now.

    this is my full error message:

    Method setTaxes in class TaxPayer content be applied to given types:
    required: double, char, double
    found: double
    reason: actual and formal argument lists differ in length


    Did i mess anything up?



    I wrote //here over the lines of code i need help with

    /*
    Week 1 Assignment
    TaxPayer
    */
    public class TaxPayer {
     
       private int social;
       private String lastName;
       private String firstName;
       private String address1;
       private String address2;
       private String city;
       private String state;
       private int zip;
       private double income;
       private char marital;
     
       //here
       private double taxes;
     
       public TaxPayer(int socialIn, String lastNmIn, String firstNmIn, String add1In, String add2In, String cityIn, String stateIn, int zipIn, double incomeIn, char maritalIn, 
    //Here
    double taxesIn )
       {
           setSocial(socialIn);
           setLastNm(lastNmIn);
           setFirstNm(firstNmIn);
           setAdd1(add1In);
           setAdd2(add2In);
           setCity(cityIn);
           setState(stateIn);
           setZip(zipIn);
           setIncome(incomeIn);
           setMarital(maritalIn);
     
     
           //here, this is where the error pops up
           setTaxes(taxesIn);  
     
       }  
     
        public void setSocial(int socialIn)
        {
            if(socialIn>0)
            {
                social=socialIn;
            }
            else
            {
                social=0;
            }
        }  
     
        public void setLastNm(String lastNmIn){
     
            lastName=lastNmIn;   
     
     
        }
     
     
        public  void setFirstNm(String firstNmIn){
            firstName=firstNmIn;
        }  
     
     
        public void setAdd1(String add1In){
     
                address1=add1In;
     
        }
     
        public void setAdd2(String add2In){
            if(add2In.equals("")){
                address2="null";
            }
            else{
                address2=add2In;
            }
        }
     
     
        public void setCity(String cityIn){
     
                city=cityIn;
     
        }
     
        public void setState(String stateIn){
     
                state=stateIn;
     
        }
     
        public void setZip(int zipIn){
            if(zipIn>0){
                zip=zipIn;
            }
            else{
                zip=0;
            }
     
        }
     
        public void setIncome(double incomeIn){
            if (incomeIn>0){
                income=incomeIn;
            }
            else{
                income=0;
            }
        }
     
        public void setMarital(char maritalIn){
            marital=maritalIn;
     
        }
     
    /*
    Income:	 Tax Rate: Single  Tax Rate: Married	Tax Rate: Divorced
    0-20,000	                15%	                 14%	                13%
    20,001 - 50,000	        22%	                 21%	                20%
    Over 50,000	        30%	                 28%	                26%
    */
     
        //Here
        public void setTaxes(double taxesIn, char maritalIn, double incomeIn){
            if(incomeIn<20000.00&&maritalIn=='S'){
                taxes=0.15*20000.0;
     
            }
     
        }
     
     
     
     
     
     
     
     
        public int getSocial(){
            return social;
        }
        public String getLastNm(){
            return lastName;
        }
        public String getFirstNm(){
            return firstName;
        }
        public String getAdd1(){
            return address1;
        } 
        public String getAdd2(){
            return address2;
        }
        public String getCity(){
            return city;
        }
        public String getState(){
            return state;
        }
        public int getZip(){
            return zip;
        }
        public double getIncome(){
            return income;
        }  
        public char getMarital(){
            return marital;
        }
     
     
     
     
        //And here
        public double getTaxes(){
            return taxes;
        }
    }
    Last edited by Cheeseballs77; April 24th, 2021 at 12:32 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Method in class cannot be applied to given types

    Please copy the full text of any error messages and paste it here.

    The args passed to a method must match those that are in the method's declaration.


    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Cheeseballs77 (April 24th, 2021)

Similar Threads

  1. constructor in class cannot be applied to given types
    By Quert in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 1st, 2018, 09:05 AM
  2. errror constructor class cannot be applied to give types
    By Aosora in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 13th, 2014, 07:24 AM
  3. Method not being applied
    By import.Snupas in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 24th, 2014, 10:08 AM
  4. [SOLVED] method in class cannot be applied
    By ange in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 30th, 2013, 05:03 AM
  5. **Constructor in class cannot be applied to given types;...
    By bassie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 2nd, 2012, 03:15 PM

Tags for this Thread