Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Just an overview of my methods

  1. #1
    Member
    Join Date
    Sep 2013
    Posts
    102
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Default Just an overview of my methods

    Not literally I just meant I would like an experienced eye, or a REAL programmer, to look it over and let me know is it over kill, are there other methods, etcetera.

    		public static class time implements Runnable {
     
    			public static String time;
    			public static String year;
    			public static String month;
    			public static String day;   
     
    			public time() {}
     
     
    			public static void startTime() {
    				(new Thread(new time())).start();
    									  }
     
     
    			public void run() {
    				Calendar cal = Calendar.getInstance();
    				SimpleDateFormat sdf = new SimpleDateFormat("k:m");
    				SimpleDateFormat sdf2 = new SimpleDateFormat("y:M:d");
    				int mm = 0;
    				int hh = 0;
    				int dd = 0;
    				int MM = 0;
    				int yy = 0;
    				int i = 0;
     
    				int i = 0;
    				String clear = sdf2.format( cal.getTime() );
     
    				year = clear.substring(0,clear.indexOf(":"));
    				month = clear.substring(clear.indexOf(":")+1, clear.lastIndexOf(":"));
    				day = clear.substring(clear.lastIndexOf(":")+1, clear.length());
    				time = sdf.format( cal.getTime() );
                                                            mm = Integer.getInteger(time.substring(time.indexOf(":")+1,time.length())).intValue();
    				hh = Integer.getInteger(time.substring(0,time.indexOf(":"))).intValue();
    			try {
     
    				do { 
    					++i;
    					if(i == 60){	i = 0;
    						mm = Integer.getInteger(time.substring(time.indexOf(":"), time.length())).intValue();
    						++mm;
    						if(mm == 60) {
    							hh = Integer.getInteger(time.substring(0,time.indexOf(":"))).intValue();
    							++hh;
    							if(hh == 24) {
    								hh = 1;
    								dd = Integer.getInteger(day);
    								++dd;
    								if( dd > calculateDays(getMonthNumber(month)) ) { 
    									if(getMonthNumber(month) <= 12) 
    										month = months[getMonthNumber(month)];
    									else { 
    										month = "January";
    										year = String.valueOf(Integer.getInteger(year).intValue()+1);
    									     }
     
    						                                                        }
    							          }
    								  }
    					             }
    					Thread.sleep(1000);
    				   } while( true );
    			    }catch(InterruptedException ie) { 
    			    	commandCenter.errorReports = commandCenter.increment(commandCenter.errorReports); 
    			    	commandCenter.errorReports[Array.getLength(commandCenter.errorReports)-1] = "Time Thrad has been interrupted (err:7A)";
    			                                    }
    							  }
     
     
     
    						          }


  2. #2
    Member
    Join Date
    Nov 2013
    Location
    Bangalore, India
    Posts
    70
    My Mood
    Cool
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: Just an overview of my methods

    Kindly let us know the requirement.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Just an overview of my methods

    I think you'll find the code does not do what you want, but as dineshj83 already pointed out, it's hard to be sure without knowing what you want the code to do.

  4. #4
    Member
    Join Date
    Sep 2013
    Posts
    102
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Default Re: Just an overview of my methods

    Yes, apologies I want it to run time, as in, keep up with minutes and seconds etcetera. I did edit the above code just the section where I was extracting Standard Date Format strings because I wanted to make it clearer this has proven difficult due to the small square I am given. I am fairly certain it keeps up with time; I have not officially tested it yet though. Finally I did add, after seeing your comments, the update from mm (minutes) and hh (hours) always equaling zero to whatever the current is.

Similar Threads

  1. Need help with Methods!
    By ViewtifulAaron in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 30th, 2013, 10:36 AM
  2. HELP WITH METHODS!
    By swirth123 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: March 19th, 2013, 02:52 PM
  3. Why and where abstract methods & classes and static methods are used?
    By ajaysharma in forum Object Oriented Programming
    Replies: 7
    Last Post: July 14th, 2012, 01:16 AM
  4. Quick Java Overview?
    By ShadowKing98 in forum Java Theory & Questions
    Replies: 3
    Last Post: April 1st, 2011, 08:14 AM