Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 9th, 2007, 2:45 PM   #1
bargain4uuu
Newbie
 
Join Date: Mar 2007
Posts: 4
Rep Power: 0 bargain4uuu is on a distinguished road
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 ( ) {
...
}



bargain4uuu is offline   Reply With Quote
Old Mar 9th, 2007, 3:49 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
:beard: :eek: :beard: :eek: :beard:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Mar 9th, 2007, 4:03 PM   #3
bargain4uuu
Newbie
 
Join Date: Mar 2007
Posts: 4
Rep Power: 0 bargain4uuu is on a distinguished road
??? if this is so easy for you could you help me????
bargain4uuu is offline   Reply With Quote
Old Mar 9th, 2007, 4:13 PM   #4
bargain4uuu
Newbie
 
Join Date: Mar 2007
Posts: 4
Rep Power: 0 bargain4uuu is on a distinguished road
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
bargain4uuu is offline   Reply With Quote
Old Mar 9th, 2007, 4:45 PM   #5
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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
Arevos is offline   Reply With Quote
Old Mar 9th, 2007, 5:40 PM   #6
bargain4uuu
Newbie
 
Join Date: Mar 2007
Posts: 4
Rep Power: 0 bargain4uuu is on a distinguished road
I still don't know how to do this

Calendar now = Calendar.getInstance();
bargain4uuu is offline   Reply With Quote
Old Mar 9th, 2007, 6:02 PM   #7
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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();
Note that the type of "now" is a Calendar, but it holds a GregorianCalendar instance. This is possible because Calendar is the parent class of GregorianCalendar. I could also have done:
GregorianCalendar now = new GregorianCalendar();
But "Calendar" is shorter to type, and if I use a generic class like Calendar, then potentially my function can work with any number of calendar systems. This is useful behaviour.
Arevos is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming with Java: Tutorial ReggaetonKing Java 7 May 20th, 2008 10:58 AM
Special browser in Java (Project) stalefish Java 3 Feb 9th, 2008 4:22 PM
First Java Program duale2005 Java 3 May 22nd, 2006 5:17 PM
Java programmers, game developers, artists, be ware! RPG game team is recruiting! atcomputers.us Paid Job Offers 7 Sep 25th, 2005 7:25 PM
Begin my first lesson to learn Java satimis Java 7 Mar 3rd, 2005 2:45 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:01 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC