Java Program day1020

Source: Internet
Author: User

Clock program

1  PackageCom.lovo;2 3 ImportJava.util.Calendar;4 5 /**6 * Clock class7  */8  Public classClock {9     Private intHour//whenTen     Private intMinute//points One     Private intSecond//seconds A      -     /** - * Constructor the      */ -      PublicClock () { -Calendar cal =calendar.getinstance (); -hour = Cal.get (11); +minute = Cal.get (12); -Second = Cal.get (13); +     } A      at     /** - * Walk the word -      */ -      Public voidGo () { -second++; -         if(Second = = 60) { inSecond = 0; -minute++; to             if(Minute = = 60) { +minute = 0; -hour++; the                 if(Hour = = 24) { *Hour = 0; $                 }Panax Notoginseng             } -         } the     } +      A     /** the * Show Time +      * @returnstring of the current time -      */ $      PublicString ShowTime () { $String time = ""; -         if(Hour < 10) { -Time + = "0"; the         } -Time + = Hour + ":";Wuyi         if(Minute < 10) { theTime + = "0"; -         } WuTime + = minute + ":"; -         if(Second < 10) { AboutTime + = "0"; $         } -Time + =second; -         returnTime ; -     } A}

Validation Program

1  PackageCom.lovo;2 3  Public classTest04 {4 5      Public Static voidMain (string[] args)throwsException {6Clock C =NewClock ();7          while(true) {8 System.out.println (C.showtime ());9 c.go ();TenThread.Sleep (1000);//let the current program sleep for 1 seconds One         } A     } -}

Summarize:
Objects are all things that represent the real world, and an object represents a specific thing. Objects are primarily composed of properties and behaviors. A property is a representation of what the object is made of, and the behavior represents what the object can do. A class is the "blueprint" or "template" of an object.

Java Program day1020

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.