Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Apr 5th, 2006, 3:19 AM   #1
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
Class inside another class

just want to know if i'm crazzy or if this actually does work

        

import java.awt.*;
import hsa.Console;
import java.util.Calendar;

class CalendarTime
        {
            public long milli;
            public long minute;
            public long rightNow;
            public long rightThen;
            //public Calendar() = Now;
            // contructor
            public CalendarTime ()
            {
                Calendar Now = Calendar.getInstance ();
                this.milli = Now.getTimeInMillis (); // contructs current time
                this.minute = this.milli / 60000;

                this.rightNow = this.minute;
                this.rightThen = this.minute + 10; //default is 10 minutes.
            }

            // used to set a different time limit
            public void setTime (int x)
            {
                this.rightThen = ( Now.getTimeInMillis () / 60000 + x);
            }

            public int getTimeLeft ()
            {
                return this.rightThen - this.rightNow; // time left
            }
        }


         CalendarTime expiryDate = new CalendarTime ();
        c.print (expiryDate.getTimeLeft ());

So am i crazzy or does this actually work? I'm making a "Calendar" object in the contructor from the Calendar class in my own class. The error that I get occurs in the blue writting. I can't use "Now." so what do i use?

If it does work can you help me out please? Turns out i'm learning quite a bit tonight :banana: (up to this point anyways).
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old Apr 5th, 2006, 3:50 AM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 893
Rep Power: 4 The Dark is on a distinguished road
At the moment you are making the "Now" variable local to your constructor. You were on the right track when you made it a member variable.

class CalendarTime
        {
            public long milli;
            public long minute;
            public long rightNow;
            public long rightThen;
            public Calendar Now;
            // contructor
            public CalendarTime ()
            {
                Now = Calendar.getInstance ();
                this.milli = Now.getTimeInMillis (); // contructs current time
                this.minute = this.milli / 60000;

                this.rightNow = this.minute;
                this.rightThen = this.minute + 10; //default is 10 minutes.
            }

            // used to set a different time limit
            public void setTime (int x)
            {
                this.rightThen = ( Now.getTimeInMillis () / 60000 + x);
            }
The Dark is offline   Reply With Quote
Old Apr 5th, 2006, 12:49 PM   #3
jaeusm
Programmer
 
jaeusm's Avatar
 
Join Date: Feb 2006
Location: Columbus, OH
Posts: 84
Rep Power: 3 jaeusm is on a distinguished road
That's quite the gratuitous use of the keyword "this". You don't really need to use it in your case.
jaeusm is offline   Reply With Quote
Old Apr 5th, 2006, 1:01 PM   #4
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
Quote:
Originally Posted by jaeusm
That's quite the gratuitous use of the keyword "this". You don't really need to use it in your case.
lol.. thanks i'm just learning Java
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red 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




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

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