Results 1 to 11 of 11
- 12-05-2012, 02:26 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 24
- Rep Power
- 0
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!
- 12-05-2012, 02:45 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
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.
Website: Learn Java by Examples
- 12-05-2012, 02:58 AM #3
Member
- Join Date
- Dec 2012
- Posts
- 24
- Rep Power
- 0
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?
- 12-05-2012, 03:01 AM #4
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: Having a problem with a leap year program.
What do you want the getFib() method produce for you?
Website: Learn Java by Examples
- 12-05-2012, 03:04 AM #5
Member
- Join Date
- Dec 2012
- Posts
- 24
- Rep Power
- 0
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.
- 12-05-2012, 03:10 AM #6
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
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?
Website: Learn Java by Examples
- 12-05-2012, 03:13 AM #7
Member
- Join Date
- Dec 2012
- Posts
- 24
- Rep Power
- 0
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
- 12-05-2012, 03:14 AM #8
Member
- Join Date
- Dec 2012
- Posts
- 24
- Rep Power
- 0
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.
- 12-05-2012, 03:16 AM #9
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
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.
Website: Learn Java by Examples
- 12-05-2012, 03:17 AM #10
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: Having a problem with a leap year program.
Give your self some times to get the basic of Java. You can start here: The Java™ Tutorials
Website: Learn Java by Examples
- 12-05-2012, 03:19 AM #11
Member
- Join Date
- Dec 2012
- Posts
- 24
- Rep Power
- 0
Similar Threads
-
Help with Leap Year program
By newtojavahelp in forum New To JavaReplies: 18Last Post: 12-04-2012, 07:13 PM -
Leap Year Test: Help!
By Zigster in forum New To JavaReplies: 5Last Post: 04-23-2012, 05:02 AM -
Leap Year Calculator
By Pkaay in forum New To JavaReplies: 9Last Post: 10-12-2010, 10:47 PM -
Having problem in calculating leap year
By lclclc in forum New To JavaReplies: 3Last Post: 09-25-2009, 08:50 PM -
Leap Year Program
By busdude in forum New To JavaReplies: 3Last Post: 10-16-2008, 03:46 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks