Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By verbazon

Thread: Class Time - represents time of day

  1. #1
    verbazon is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Default 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
    mubarak likes this.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default

    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

  1. Replies: 0
    Last Post: 11-22-2008, 01:49 AM
  2. Time
    By Fireking in forum New To Java
    Replies: 3
    Last Post: 09-07-2008, 01:30 AM
  3. Replies: 21
    Last Post: 08-01-2008, 11:13 AM
  4. First time with abstract class
    By crazydeo in forum New To Java
    Replies: 0
    Last Post: 06-03-2008, 06:24 PM
  5. Hello, first time here.
    By ludragon in forum Introductions
    Replies: 2
    Last Post: 01-03-2008, 05:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •