Calendar Project for school

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2008
Posts: 208
Reputation: llemes4011 is an unknown quantity at this point 
Solved Threads: 13
llemes4011 llemes4011 is offline Offline
Posting Whiz in Training

Calendar Project for school

 
0
  #1
Aug 24th, 2008
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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 413
Reputation: sciwizeh is on a distinguished road 
Solved Threads: 22
sciwizeh's Avatar
sciwizeh sciwizeh is offline Offline
Posting Pro in Training

Re: Calendar Project for school

 
0
  #2
Aug 24th, 2008
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 );
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "
-Albert Einstein
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 208
Reputation: llemes4011 is an unknown quantity at this point 
Solved Threads: 13
llemes4011 llemes4011 is offline Offline
Posting Whiz in Training

Re: Calendar Project for school

 
0
  #3
Aug 24th, 2008
awesome, thanks, it works perfectly now. Now i just have to make the code more flexible, for lack of a better word >.< hahaha
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 973 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC