Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 26th, 2003, 11:27 PM
apw420 apw420 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: NYC
Posts: 11 apw420 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
help with class Time

Trying to do the following problem but keep hitting roadblocks...

The following class is a Time object.

class Time {
private int hour;
private int minute;
private int second;

public Time( ) { // set hour, minute and second to zero }
public Time(int hr, int min, int sec) { // set hour, minute and second }
public void setTime(int hr , int min, int sec) { // set hour, minute and second }
public void printTime( ) { //prints the time in the form of 0:0:0 }
public void tick( ) { // increments the time by one second }
};

Implement (code) all the constructor and methods. Assume that a time of 00:00:00 is
represented by 0:0:0 -- (use 0 to represent 00). Test the Time object. [HINT:] Use
a for loop to test the tick( ) method.

Here's what I have so far, but I'm just hitting a wall. Any help is greatly appreciated.


public class Time {

private int hour;
private int minute;
private int second;

public Time(){
int hour=0;
int minute=0;
int second=0;
}

public Time (int hr, int min, int sec){

}

public void setTime(int hr, int min, int sec){
hour=hr;
minute=min;
second=sec;

}

public void printTime() {
System.out.println("The time is " + hour +":"+ minute +":"+second);
}

public void tick(){
second++;


}

public static void main(String [] args){


Time t1 = new Time();
t1.setTime(10,30,15);
for(int i=0; i < 60; i++){
t1.tick();
t1.printTime();
}




}
}

Reply With Quote
  #2  
Old July 1st, 2003, 09:19 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
I'll give you a few hints. UNIX computer systems store the date as a "timestamp", which means they store the number of seconds that have elapsed since January 1, 1970 (I think). Whenever you need the current time, they just do some math with the timestamp and the starting date to figure out the current date and time. For instance: "Tue Jul 1 17:43:08 PDT 2003" is equals to
"1057106588"

Second hint, there are 86400 seconds in a single day (24 hours * 60 minutes * 60 seconds).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > help with class Time


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT