943,796 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 1994
  • Java RSS
Aug 24th, 2008
0

Calendar Project for school

Expand Post »
ok, so, we have to make a program that displays the date 100 days from today, the day you were born, and the date 10,000 days after your birth date. I've done all that, but i want to take it a step further, i want the user to be able to input the number of days from today that he/she wishes to know the date of (if that makes any sense at all...). Here's what the part of the code i'm working on looks like:

Java Syntax (Toggle Plain Text)
  1. import java.util.GregorianCalendar;
  2. import java.lang.String;
  3. import java.util.Scanner;
  4.  
  5. public class calendarProjectTest
  6. {
  7. public static void main(String[] args)
  8. { GregorianCalendar cal = new GregorianCalendar(); //declare today's date
  9.  
  10. GregorianCalendar myBirthday = new
  11. GregorianCalendar(1992, GregorianCalendar.JUNE, 9); //declare my birthday
  12.  
  13. System.out.println("Please enter a number greater than 0:");
  14. Scanner keyboard = new Scanner(System.in);
  15. String number = keyboard.next();
  16.  
  17. int value = number;
  18.  
  19. cal.add(GregorianCalendar.DAY_OF_MONTH, number);

I'm using Bluej and it says, "incompatible types - found java.lang.String but expected int"
I'm at a loss. i don't have any idea what to do. any advise would be great. and yes, i know there are no end brackets.
Last edited by llemes4011; Aug 24th, 2008 at 4:08 pm.
Similar Threads
Reputation Points: 41
Solved Threads: 13
Posting Whiz in Training
llemes4011 is offline Offline
224 posts
since Aug 2008
Aug 24th, 2008
0

Re: Calendar Project for school

keyboard.next(); returns a string, not an int, so int value = number is trying to assign a string value to an int type. try putting this instead: int value = Integer.parseInt( number );
Reputation Points: 73
Solved Threads: 22
Posting Pro in Training
sciwizeh is offline Offline
423 posts
since Jun 2008
Aug 24th, 2008
0

Re: Calendar Project for school

awesome, thanks, it works perfectly now. Now i just have to make the code more flexible, for lack of a better word >.< hahaha
Reputation Points: 41
Solved Threads: 13
Posting Whiz in Training
llemes4011 is offline Offline
224 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Run-time GUI systems opinions
Next Thread in Java Forum Timeline: Day finder





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC