Man-Machine interactive version Scissors game

Source: Internet
Author: User

     This small program is to imitate the real life scissors writes, through the random number realization computer's fist, inside has 3 classes, respectively is person class, computer class and game class. The person class and the computer class record the user name, winning and losing times, and the punch of the user and computer respectively. Game class to compare the punch of the user and the computer, output the corresponding statement. The following is code:     (1) Person class package com. Guessfist;import java.util.scanner;public class person {    public  String Name;    public int Score;         public void getname (String name) {    name=name;     }    public int getfist () {    scanner input =new scanner (system.in);     int fist=input.nextint ();     if   (fist<1&&fist>3)  {system.out.println ("warning! input Error"); return 0;}     switch  (Fist)  {case 1:system.out.println ("\ t player" +name+ ", You have Scissors"); return  fist;case 2:system.out.printlN ("\ t player" +name+ ", you are out of stone"), return fist;case 3:system.out.println ("\ t player" +name+ ", you Out of cloth");return fist; DEFAULT:SYSTEM.OUT.PRINTLN ("warning! input error, please re-enter"); Getfist (); break;} return 0;    }} (2) Computer class package com. Guessfist;import java.util.random;public class computer {    public  String Name;    public int Score;         public void getname (String name) {    name=name;     }    public int getfist () {    random r=new  random ();     int fist=r.nextint (2) +1;    switch  (Fist)  {case 1:system.out.println ("\ t computer" +name+ "scissors"); Return fist;case 2:system.out.println ("\ T computer "+name+" out of the Stone ") return fist;case 3:system.out.println (" \ t Computer "+name+" out of the cloth "); return fist;defAult:break;} return 0;    }} (3)


This article is from the Java web design blog, so be sure to keep this source http://10760879.blog.51cto.com/10750879/1717203

Man-Machine interactive version Scissors game

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.