Results 1 to 11 of 11
  1. #1
    Southpaw is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Having a problem with a leap year program.

    Iv'e made the object for leap year already and it's fine, but when i try to return the method from the object I get an error.
    The code Iv'e got so far is:
    import javax.swing.JOptionPane;



    public class LeapYearJDialog
    {
    public static void main(String[] args)
    {

    String y1;
    int year;

    LeapYear box = new LeapYear();

    y1 =
    JOptionPane.showInputDialog("Input a Year.");
    year = Integer.parseInt(y1);

    System.out.println(box.getFib());





    System.exit(0);
    }
    }




    The error:
    error: cannot find symbol
    System.out.println(box.getFib());
    ^
    symbol: method getFib()
    location: variable box of type LeapYear
    1 error

    Tool completed with exit code 1


    Tool completed with exit code 1

    The object code:
    import javax.swing.JOptionPane;


    public class LeapYear
    {
    public boolean setFib(int year)
    {
    if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
    return true;
    else
    return false;

    }
    }

    Thanks for any help guys!

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    7

    Default Re: Having a problem with a leap year program.

    You don't have a method named getFib() in the LeapYear class. That's why you got that error.

  3. #3
    Southpaw is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Re: Having a problem with a leap year program.

    So i need to use something like:

    import javax.swing.JOptionPane;


    public class LeapYear
    {
    public boolean setFib(int year)
    {
    if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
    return true;
    else
    return false;

    }

    public boolean getFib(int year)
    {

    return ;
    }
    }

    but what would i use for the return?

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    7

    Default Re: Having a problem with a leap year program.

    What do you want the getFib() method produce for you?

  5. #5
    Southpaw is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Re: Having a problem with a leap year program.

    From what I understand I need it to return the boolean fib method to the jdialog program.

  6. #6
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    7

    Default Re: Having a problem with a leap year program.

    Your question is that you need to create a program to check whether a year is a leap year or not. You have a LeapYear class in there you already have a method named setFib(). What I can see that this method seems to check if a year is LeapYear or not by returning a boolean value true or false. In your other class you call the LeapYear class getFib() which is undefined. Don't you mean that you want to call the setFib() method instead?

  7. #7
    Southpaw is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Re: Having a problem with a leap year program.

    ok so when i use that method I get this:
    import javax.swing.JOptionPane;



    public class LeapYearJDialog
    {
    public static void main(String[] args)
    {

    String y1;
    int year;

    LeapYear box = new LeapYear();

    y1 =
    JOptionPane.showInputDialog("Input a Year.");
    year = Integer.parseInt(y1);

    System.out.println(box.setFib());

    System.exit(0);
    }
    }

    : error: method setFib in class LeapYear cannot be applied to given types;
    System.out.println(box.setFib());
    ^
    required: int
    found: no arguments
    reason: actual and formal argument lists differ in length
    1 error

  8. #8
    Southpaw is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Re: Having a problem with a leap year program.

    Im sorry I am very new to Java and programming in general. This is my first class in college dealing with actual coding.

  9. #9
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    7

    Default Re: Having a problem with a leap year program.

    The setFib() method requires an argument as you declare the method as public boolean setFib(int year). So when you calling this method you should give it the year argument.

  10. #10
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    7

    Default Re: Having a problem with a leap year program.

    Quote Originally Posted by Southpaw View Post
    Im sorry I am very new to Java and programming in general. This is my first class in college dealing with actual coding.
    Give your self some times to get the basic of Java. You can start here: The Java™ Tutorials

  11. #11
    Southpaw is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Re: Having a problem with a leap year program.

    Ha! Thank you that was what i was missing. I was mistaken, I thought when you used setmethod you had to use the getmethod in the program. Thank you for the help it's really appreciated. I'll give you some rep for the help. Thanks again!

Similar Threads

  1. Help with Leap Year program
    By newtojavahelp in forum New To Java
    Replies: 18
    Last Post: 12-04-2012, 07:13 PM
  2. Leap Year Test: Help!
    By Zigster in forum New To Java
    Replies: 5
    Last Post: 04-23-2012, 05:02 AM
  3. Leap Year Calculator
    By Pkaay in forum New To Java
    Replies: 9
    Last Post: 10-12-2010, 10:47 PM
  4. Having problem in calculating leap year
    By lclclc in forum New To Java
    Replies: 3
    Last Post: 09-25-2009, 08:50 PM
  5. Leap Year Program
    By busdude in forum New To Java
    Replies: 3
    Last Post: 10-16-2008, 03:46 AM

Posting Permissions

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