Clock, Swimming Pool

Source: Internet
Author: User
1 package COM. FJ; 2 3 Import Java. util. calendar; 4 5/** 6 * Clock Class 7 * @ author junlin 8*9 */10 public class clock {11 private int hour; 12 private int minute; 13 private int second; 14 15 public clock () {16 calendar = calendar. getinstance (); 17 hour = calendar. get (calendar. hour_of_day); 18 minute = calendar. get (calendar. minute); 19 second = calendar. get (calendar. second); 20} 21 22 public void go () {23 second ++; 24 if (second> = 59) {25 second = 0; 26 minute ++; 27} 28 If (minute> = 59) {29 minute = 0; 30 hour ++; 31} 32 If (hour> = 23) {33 hour = 0; 34} 35} 36 37 public stringbuffer show () {38 stringbuffer time = new stringbuffer (); 39 if (hour <10) {40 time. append ("0"); 41} 42 time. append (hour + ":"); 43 If (minute <10) {44 time. append ("0"); 45} 46 Time. append (minute + ":"); 47 If (second <10) {48 time. append ("0"); 49} 50 time. append (second); 51 return time; 52} 53 54 public int gethour () {55 return hour; 56} 57 public void sethour (INT hour) {58 this. hour = hour; 59} 60 public int getminute () {61 Return minute; 62} 63 public void setminute (INT minute) {64 this. minute = minute; 65} 66 public int getsecond () {67 return second; 68} 69 public void setsecond (INT second) {70 this. second = Second; 71} 72 73}
 1 Clock clock = new Clock(); 2         for (int i = 0;i < 10; i++) { 3             clock.go(); 4             System.out.println(clock.show()); 5             try { 6                 Thread.sleep(1000); 7             } catch (InterruptedException e) { 8                 e.printStackTrace(); 9             }10         }

Swimming Pool

1 package COM. FJ; 2/** 3 * Pool 4 * @ author junlin 5*6 */7 public class circle {8 private double radius; 9 10 public double getarea () {11 double area = math. pI * radius; 12 return area; 13} 14 15 public double getcircumference () {16 double circumference = 2 * Math. pI * radius; 17 return circumference; 18} 19 20 public double getradius () {21 return radius; 22} 23 24 public void setradius (double radius) {25 this. radius = radius; 26} 27 28 29}
1 circle circle1 = new circle (); 2 circle circle2 = new circle (); 3 double radius = integer. parseint (joptionpane. showinputdialog ("Enter the pool radius:"); 4 circle1.setradius (RADIUS); 5 circle2.setradius (radius + 3); 6 system. out. printf ("decoration aisles need %. 2f RMB! \ N ", (circle2.getarea ()-circle1.getarea () * 10); 7 system. Out. printf (" wall repair requires %. 2f RMB! ", Circle2.getcircumference () * 8 );

 

Clock, Swimming Pool

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.