Java Learning Notes----enumeration test questions

Source: Internet
Author: User

Define a traffic light enumeration class, including red, green, yellow lights, need to get the next light method, and to achieve a red light 5 seconds after the turn of the green light, green 3 seconds after the yellow lamp, yellow light after 2 seconds into a red light, so cycle
1  Public classTEST5 {2 3      /**4       * @throwsinterruptedexception5       */6       Public Static voidMain (string[] args)throwsinterruptedexception {7deng[] Deng =Deng. VALUES ();8             for(inti = 0;i < 3;i++){9Deng d =Deng[i];Ten                if(d = =Deng. Red) { One System. out.println (d); AThread. Sleep (5000); - System. Out.println (D.next ()); -}Else if(d = =Deng. Green) { theThread. Sleep (3000); - System. Out.println (D.next ()); -}Else if(d = =Deng. Yellow) { -Thread. Sleep (2000); + //System.out.println (D.next ()); -i =-1; +               } A           } at      } - } - enumdeng{ -Red ("Red light"){ -             PublicDeng Next () { -                returnGreen; in           } -},green ("green light")){ to             PublicDeng Next () { +                returnYellow; -           } the},yellow ("Yellow Light"){ *             PublicDeng Next () { $                returnRed;Panax Notoginseng           } -      }; the       Public AbstractDeng Next (); +      PrivateString name; A      PrivateDeng (String name) { the             This. Name =name; +      } - @Override $       PublicString toString () { $            returnname; -      } -}

Java Learning Notes----enumeration test questions

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.