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 5 of 5

Thread: methods returning zero's ???

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default methods returning zero's ???

    Will someone look at this and maybe give a pointer on why only zero's are being returned.

    public class employee {


    String name;
    int id;
    int salary;
    int age;
    String position;
    void display(){

    System.out.println("Federal Tax" +getFedTax);
    System.out.println("Social Security Tax" +getSsTax);
    System.out.println("Health Fee" +getHealthFee);
    System.out.println("Insurance" +getInsurance);
    System.out.println("Net Pay" +getNetPay);
    }
    int getFedTax;

    int fedtax = salary;
    double fedtax1 = (fedtax-800)*.17;

    int getSsTax;

    int sstaxrate = 5;
    double sstax = salary*.05;

    int getHealthFee;

    int healthrate = 5;
    double healthfee = salary*.05;

    int getInsurance;
    int insurancerate;
    {

    if (age<40)
    insurancerate = 3;
    else if(age<=50)
    insurancerate = 4;
    else if(age<=60)
    insurancerate = 5;
    else if(age>60)
    insurancerate = 6;
    getInsurance = ((insurancerate*10^-3)*salary);


    }
    double getNetPay;

    double netpay = salary-fedtax1-sstax-healthfee-getInsurance;
    }

    HERE IS MY MAIN CLASS


    public class employeeMain {

    public static void main(String[] args) {
    {
    employee employee1 = new employee();
    employee1.name = "dave johnson";
    employee1.id = 1234;
    employee1.salary = 50000;
    employee1.age = 45;
    employee1.position = "supervisor";
    employee1.display();
    }
    }
    }


  2. #2
    Junior Member
    Join Date
    Jul 2011
    Location
    toronto
    Posts
    14
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: methods returning zero's ???

    you used 'getFedTax', 'getSsTax', 'getHealthFee', 'getInsurance', and 'getNetPay' for display() but
    you actually never used those and even didn't initialize values for them.

    and just wondering, aren't those getSmth methods?

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: methods returning zero's ???

    I thought the data i put in the employeeMain would go into those methods. I need to look back at my notes but, maybe I put a { after the method name to initialize?

  4. #4
    Junior Member
    Join Date
    Jul 2011
    Location
    toronto
    Posts
    14
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: methods returning zero's ???

    those are not even methods yet....

    int getSsTax;
    int sstaxrate = 5;
    double sstax = salary*.05;
    getSsTax is still integer, not method

    if getSsTax is a method then.... it should be like

    public int getSsTax(){
    // code....
    }

  5. The Following User Says Thank You to wookyoo For This Useful Post:

    fakeClassy (August 3rd, 2011)

  6. #5
    Junior Member
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: methods returning zero's ???

    Alright I think that'll get me on the right path - thanks

Similar Threads

  1. Method returning 0 for everything
    By JJTierney in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 4th, 2010, 08:51 PM
  2. If statement not returning anything
    By Jonathan_C in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 15th, 2010, 03:38 PM
  3. Returning Null
    By Woody619 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: July 22nd, 2010, 12:53 PM
  4. [SOLVED] Java Beginner: Help with methods and returning values (hailstone program)
    By alf in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 14th, 2010, 06:28 PM
  5. returning a 2D array
    By straw in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 11th, 2010, 04:30 AM

Tags for this Thread