Gregorian Calendar Error

Joined
Oct 2, 2006
Messages
1
Reaction score
0
Well I'm writing a school project and my compiler keeps telling me a line is wrong with the errors ".class expected" and ")" expected. We are required to use the Gregorian calendar and so far this is what I have.

package craijwlab2;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;



public static void main(String[] args) {
GregorianCalendar cal = new GregorianCalendar();

cal.add(Calendar.MONTH, 1);


JOptionPane.showMessageDialog(null, "Todays date is "+cal.get(Calendar.MONTH)+"/"+cal.get(Calendar.DATE)+"/"+cal.get(Calendar.YEAR));

String birthMonth;
birthMonth = JOptionPane.showInputDialog("Which month number were you born in?:");
int month = Integer.parseInt(birthMonth);

String dayOfBirth;
dayOfBirth = JOptionPane.showInputDialog("Which day of the month were you born?:");
int date = Integer.parseInt(dayOfBirth);

String birthYear;
birthYear= JOptionPane.showInputDialog("What is the year of your birth:");
int year = Integer.parseInt(birthYear);

**GregorianCalendar birthday= new GregorianCalendar(int month, int date, int year);**

JOptionPane.showInputDialog("So your birthday is "+(birthday)+"?");
}

}

The line with the stars around it is the one with the errors but maybe I'm missing something in the code? Thanks in advance. The aim of this project is to get the information from the user about their birthday and then use it and today's date to get their age.
 
Last edited:
Joined
Sep 20, 2006
Messages
7
Reaction score
0
First, in your example you're missing your class declaration, e.g.

public class Foo { ...

Assuming that's just a typo, since you're getting actual compiler errors, in your ** ... ** line, take out the "int"s. You use those when you declare or define a new method, not when you call one (the GregorianCalendar constructor in this case). You only need to pass in the variable...

GregorianCalendar birthday= new GregorianCalendar(month, date, year);

If what you're passing in isn't an int, the compiler will complain.

Good luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top