On Apr 11, 8:59 am, "Jon Carlson" <[email protected]> wrote:
> Hi all,  I seem to be having trouble with the following code for the
> homework.  Does anyone know why I am getting the error?
>
> import java.util.Date;
>
> public class MyCurrentDate extends Thread implements Runnable {
I've never seen this, I thought you have either to extend Thread or
implement Runnable, but both seems to me very, very strange to say the
least.

>
>     Date date;
>
>     MyCurrentDate(Date date) {
>
>         date = this.date;
>
>     }
>
>     public void run() {
>
>         for (int i = 0; i < 10; i++) {
>
>             System.out.format("DONE! %s%n", date.toString());
>
>             try {
>
>                 sleep(100);
>
>             } catch (InterruptedException e) {}
>
>         }
>
>     }
>
> }
Where do you create a MyCurrentDate object instance? If you don't do
it, you will end with a date variable not initialized, hence the
error.
Besides, your program is not exactly following the requirements.
Supposingly it works as it is, you will print the same date 10 times,
I think the requirements is to print the current date 10 times which
is not the same providing you use a right format with milliseconds to
print it, there should be difference between the printed lines. That
means that the date should be determined in the run method, or to say
it better in a method called by the run method.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to