![]() |
Java programing any ideas????Please help
Complete the condition in the if statement below so that it will be true when the date in the GregorianCalendar instance myGC1 is not later than the date of the GregorianCalendar instance myGC2:
if ( ) { ... } :rolleyes: :rolleyes: :rolleyes: :confused: :confused: :confused: |
:beard: :eek: :beard: :eek: :beard: :rolleyes:
|
??? if this is so easy for you could you help me????
|
I'm doing this like that
myGC1.compare(myGC2)<=0 Test 1 succeeded (0 marks): The expected output was produced correctly. Test 2 succeeded (0 marks): The expected output was produced correctly. Test 3 failed (exit code = 1): Main.java:35: cannot find symbol symbol : method compare(java.util.Calendar) location: class java.util.Calendar return (myGC1.compare(myGC2)<=0 ); ^ 1 error Test 4 failed (exit code = 1): Exception in thread "main" java.lang.NoClassDefFoundError: Main |
Look at the error that you get. It says that it "cannot find symbol" and that this symbol is "method compare". In other words, it can't find a method called "compare" on your Calendar object.
Next look up the Calendar class (from which GregorianCalendar derives), on Sun's online Java documentation. Usually you can just type the full class name (java.util.Calendar) into Google and it'll find the right page for you without having to figure out where Sun's search engine is. Look through the Calendar documentation. It doesn't have a "compare" method, which explains why your Java compiler couldn't find it. There is, however, a "compareTo" method, and a "before" and "after" method. See? Simple when you know how ;) |
I still don't know how to do this :confused:
Calendar now = Calendar.getInstance(); :confused: |
You don't explain what you want to do. It's always helpful to explain what you want to do, rather than posting an incorrect line of code and expecting people to know what it is you want to do.
However, I'd guess that you want to create a new Calendar instance. You can't create a new Calendar object, because Calendar is an abstract class. There are several different calendar systems around, and you need to tell Java which one you want. The standard calendar system in use today is the Gregorian Calendar, and that's the one you're told to use. So: :
Calendar now = new GregorianCalendar();:
GregorianCalendar now = new GregorianCalendar(); |
| All times are GMT -5. The time now is 2:23 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC