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!
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.
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?
Re: Having a problem with a leap year program.
What do you want the getFib() method produce for you?
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.
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?
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
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.
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.
Re: Having a problem with a leap year program.
Quote:
Originally Posted by
Southpaw
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
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!