Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is my date not working?

 
Angela Hill
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having trouble finding out the reason why my code is broken @ ~ line 121: date1=SDF.parse(inputText,pos); cal1.setTime(date1); And again @~ Line 128: getDate2 date2= new getDate2();
If anybody could please help!!! I really do not see what I am doing wrong. I'm sure it is probably something simple that I am over looking.

Thanks in advance



 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Broken? In what way? Please read our FAQ pages ItDoesntWorkIsUseless and TellTheDetails, which describe better ways of explaining your problem.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Legions of men and women have been asking themselves the same question
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SimpleDateFormat.parse() returns a java.util.Date object. In line 120 you are assigning the return value of this method to a "getDate" object. (Where's class "getDate", is that a class you wrote yourself?). That doesn't work, because "getDate" is not the same class (or a superclass) of java.util.Date.

Likewise, Calendar.setTime() needs a java.util.Date object, not a "getDate" object.
 
Alex Armenteros
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely the code is a little messed up but...

If you want others to understand it, put the code of all your classes (getDate and getDate2) and put what do you see wrong on the program's behaivour.

But at first glance... where is inputText variable declared? I don't find it.

And... are you trying to instantate methods?
 
Angela Hill
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the confusion.... the errors I am getting for line 120. Is saying that I am not declaring the variable... What I am trying to get the code to do is to read the input of Today's date, I also need the cal1.SetTime(date1) to be incorporated with this as well. In other words the input is March 20, 2012. this is then set as date1 so when declared in date2 it counts the days from each transaction to then figure the interest earned. I hope this helps. Once again thanks in advance for any help.
 
Angela Hill
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes the getDate is what I wrote myself
 
Alex Armenteros
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not assigning the result from the call of br.readLine() on line 116.

you'd probably want to do this String inputText=br.readLine();

Just look how you do it on line 42

This
input = Float.parseFloat(br.readLine());

is equivalent to this

String inputText=br.readLine();
input = Float.parseFloat(inputText);

I hope this helps you

I insist the you should post the code of getDate and getDate2 classes ,as you could have problems with that also.
 
Winston Gutkowski
Bartender
Pie
Posts: 10504
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angela Hill wrote:What I am trying to get the code to do is to read the input of Today's date...

I'm a bit confused. Why do you need to "read the input of today's date"? Today's date is today's date, and you set it with something like
new GregorianCalendar();
from which you can get a Date, a millisecond offset, or pretty much anything else you like.

Could you elaborate?

Winston
 
Angela Hill
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex~ Thank you that did help a lot! I can't believe I didn't think of that!... The code below is all that I have written for getDate and getDate2. Where the notes are that the code is still broken I am getting errors...At line 9 it says incompatible types. Then at line 10 the error shows:

method setTime in class java.util.Calendar cannot be applied to given types;
required: java.util.Date
found: edu.umsl.mis3806.getDate
reason: actual argument edu.umsl.mis3806.getDate cannot be converted to java.util.Date by method invocation conversion


The error at line 17 says that the assigned value is never used and that it is not assigned. which to me does not make sense because I thought that is what I was trying to do. if that makes sense? :s
 
Alex Armenteros
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Calendar's method setTime needs a Date object the easiest way I'm capable to think of is create a method that returns a Date object based on a getDate Object.



 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you may need to read up on Java standards regarding naming. You should never name a class getDate.
 
Winston Gutkowski
Bartender
Pie
Posts: 10504
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angela Hill wrote:Alex~ Thank you that did help a lot! I can't believe I didn't think of that!... The code below is all that I have written for getDate and getDate2.

I hate to say, but I'm still mystified. Why are you asking somebody to enter 'today's date'? If it's for a game, and it's Stardate 3274.3, I can understand; otherwise the System knows what today's date is.

As for a future date, both Date and GregorianCalendar are Comparable, so I'm not quite sure why you're going through a lot of convoluted logic to work out whether it's a future date or not. If you feel you have to, get 'today's' date, and compare it (with compareTo()) with a similarly entered 'future' date; if the the second isn't greater than the first...bingo, you have an error.

HIH

Winston
 
Angela Hill
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston,
The point of know todays date is stimulating the day that the account is opened and thus the future date...well a date in the future. The point of knowing these dates are to see how much interest is earned.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angela Hill wrote:Then at line 10 the error shows:

method setTime in class java.util.Calendar cannot be applied to given types;
required: java.util.Date
found: edu.umsl.mis3806.getDate
reason: actual argument edu.umsl.mis3806.getDate cannot be converted to java.util.Date by method invocation conversion

The compiler is exactly saying what I explained above.

Calendar.setTime() takes a java.util.Date but you are trying to pass it a edu.umsl.mis3806.getDate.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic