Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default Objects programming?

    This program produces errors
    :9: getHour(int) in Time cannot be applied to ()
    System.out.println("The time is:"+time1.getHour()+":"+time1.getMinute()+":"+tim e1.getSecond());

    I got stuck at this point of how to pass an integer to the method.
    So can someone please give me some advice?
    Thanks!



    main method
    Java Code:
    public class testTime
    {
    	public static void main(String[] args)
    	{
    		Time time1 = new Time();
    		Time time2 = new Time(555550000);
    
    		System.out.println("The time is:"+time1.getHour()+":"+time1.getMinute()+":"+time1.getSecond());
    		System.out.println("The time is:"+time2.getHour()+":"+time2.getMinute()+":"+time2.getSecond());
    
    	}//end of main
    }//end of testTime

    this is a class for time

    Java Code:
    public class Time
    {
    	private int hour;
    	private int minute;
    	private int second;
    
    	public Time()
    	{
    		long elTime = System.currentTimeMillis();
    		// Obtain the total seconds since the midnight, Jan 1, 1970
    		long totalSeconds = elTime / 1000;
    
    		// Compute the current second in the minute in the hour
    		 this.second = (int)(totalSeconds % 60);
    
    		// Obtain the total minutes
    		long totalMinutes = totalSeconds / 60;
    
    		// Compute the current minute in the hour
    		this.minute = (int)(totalMinutes % 60);
    
    		// Obtain the total hours
    		long totalHours = totalMinutes / 60;
    
    		// Compute the current hour
    		 this.hour = (int)(totalHours % 24);
    
    	}
    
    	public Time(long totalMilliseconds)
    	{
    
    		    // Obtain the total seconds since the midnight, Jan 1, 1970
    		    long totalSeconds = totalMilliseconds / 1000;
    
    		    // Compute the current second in the minute in the hour
    		     this.second = (int)(totalSeconds % 60);
    
    		    // Obtain the total minutes
    		    long totalMinutes = totalSeconds / 60;
    
    		    // Compute the current minute in the hour
    		    this.minute = (int)(totalMinutes % 60);
    
    		    // Obtain the total hours
    		    long totalHours = totalMinutes / 60;
    
    		    // Compute the current hour
        	     this.hour = (int)(totalHours % 24);
    	}
    
    
    
    		public static int getHour(int hour)
    		{
        		return hour;
    
    		}
    
    
    		public static int getMinute(int minute)
    		{
    			return minute;
    		}
    
    		public static int getSecond(int second)
    		{
    			return second;
    		}
    
    
    }//end of time

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    10

    Default

    just remove the input parameter of getter method,
    those input parameters are meaningless

  3. #3
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default

    Thank you!
    I got it!

  4. #4
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    10

    Default

    get(int) and get() are completely difference method
    just like Time() and Time(long) are different

  5. #5
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default

    i removed the parameter and static of those methods and now its working fine.
    Thanks i will make a note of it.

Similar Threads

  1. GUI Programming Help
    By sirwiggles in forum New To Java
    Replies: 4
    Last Post: 04-28-2009, 04:53 AM
  2. Replies: 1
    Last Post: 01-22-2009, 04:25 PM
  3. Socket programming
    By ikoko in forum New To Java
    Replies: 1
    Last Post: 10-16-2008, 02:50 PM
  4. New to Programming . . .Need Help
    By DSutta22 in forum New To Java
    Replies: 2
    Last Post: 09-10-2008, 05:19 AM
  5. programming
    By abcdefg in forum New To Java
    Replies: 9
    Last Post: 03-10-2008, 10:34 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
  •