Results 1 to 2 of 2
- 04-12-2009, 09:58 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 2
- Rep Power
- 0
Class Time - represents time of day
Hello All,
I'm writing a Class Time that represents a time of day. It has hour & minute attributes; the hour ranging from 0 to 23, where 0 to 11 represents a time before noon; the minute, ranging 0 to 59.
I've tried setting it up so far and have commented what each method needs to include but am stuck as a confused beginner. I would appreciate any help possible.
Thanks!
Java Code:public class Time { private int hour; private int minute; public Time() //default constructor initializing time to 0 hours, 0 minutes { hour = 0; minute = 0; } private boolean isValid(hour,minute) //returns true if given hour & minute values are of range { if(hour >= 0 && hour <= 23) && (minute >= 0 && minute <=11)) { return true; } else { return false; } } public void setTime(hour,minute) //set time if given values are valid - how do i do this? { if(isValid) { //set time | } public void setTime(hour,minute,isAM) //sets time if given values are valid //hour range: 1 to 12 //parameter isAM true if the time is an a.m. time, otherwise false { if(isValid) { } } }- write a default constructor initializing time to 0 hours, 0 minutes
- write a private method isValid(hour,minute) that returns true if the given hour & minute values are in appropriate range
- write method setTime(hour,minute) setting time if given values are valid
- write another method setTime(hour,minute,isAM) setting time if given values are valid. The given hour should be in range 1 to 12. isAm is true if the time is an a.m., otherwise false
- 04-13-2009, 01:06 AM #2
Aren't you supposed to do your own homework? If you've really written the code you posted, you should be able to do the rest of it.
db
edit Here's a great learning resource:
The Java™ Tutorials
Similar Threads
-
"source not found" at debug time when creating new class
By rafamd11 in forum New To JavaReplies: 0Last Post: 11-22-2008, 01:49 AM -
Time
By Fireking in forum New To JavaReplies: 3Last Post: 09-07-2008, 01:30 AM -
i click on it,then first time error page comes,second time click then product page co
By 82rathi.angara in forum New To JavaReplies: 21Last Post: 08-01-2008, 11:13 AM -
First time with abstract class
By crazydeo in forum New To JavaReplies: 0Last Post: 06-03-2008, 06:24 PM -
Hello, first time here.
By ludragon in forum IntroductionsReplies: 2Last Post: 01-03-2008, 05:03 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks