First Class:
Package Lianxi;
Import Java.util.Scanner;
public class Rjcq {
Scanner input = new Scanner (system.in);
Defining the properties of a player class
String name;
int score;
String Action;
int num;
Define the scissors method of the player class
public void Show () {
System.out.println ("\ n please punch: 1. Scissors 2. Stone 3. Cloth");
Boolean A = true;
do {
num = Input.nextint ();
if (num = = 1 | | num = = 2 | | num = = 3) {
Switch (num) {
Case 1:
Action = "scissors";
Break
Case 2:
Action = "stone";
Break
Case 3:
Action = "cloth";
Break
}
A = false;
System.out.println ("You punch:" + action);
} else {
System.out.println ("Enter the wrong number, please re-enter");
}
} while (a);
}
}
A second class:
Package Lianxi
public class Rjcq01 {//Computer class
String name;
int score;
String Action;
int sum;
Define the Computer class scissors method
public void Show () {
Generate random numbers
sum= (int) (Math.random ());
Switch (sum) {
Case 1:
Action= "Scissors";
Break
Case 2:
Action= "Stone";
Break
Case 3:
action= "cloth";
Break
}
System.out.println (name+ "Punch" +action);
}
}
A third class:
Package Lianxi;
Import Java.util.Scanner;
public class Rjcq02 {
Game class
Scanner input=new Scanner (system.in);
Defining the properties of a game class
Creating objects for the Player class
Renjicaiquan it=new Renjicaiquan ();
Creating objects for a computer class
Renjicaiquan1 is=new renjicaiquan1 ();
int number;
int witch=0;
Ways to define game processes
public void process () {
SYSTEM.OUT.PRINTLN ("--------------------------welcome into the game world--------------------------\ n");
System.out.println ("\t\t********************************");
System.out.println ("\t\t********** scissors, beginning *************");
System.out.println ("\t\t********************************");
System.out.println ();
System.out.println ("Punching rule: 1. Scissors 2. Stone 3. Cloth");
System.out.print ("Please select the opponent role (1: Liu Bei 2: Sun Quan 3: Caocao):");
Boolean B = true;
do {
Number = Input.nextint ();
if (number = = 1 | | number = = 2 | | number = = 3) {
Switch (number) {
Case 1:
Is.name = "Liu Bei";
Break
Case 2:
Is.name = "Sun Quan";
Break
Case 3:
Is.name = "Caocao";
Break
}
b = false;
} else {
System.out.println ("Enter the wrong number, please re-enter");
}
} while (b);
System.out.print ("Please enter your name:");
It.name = Input.next ();
System.out.println (it.name + "VS" + is.name + "PVP \ n");
System.out.println ("Do you want to start?" (y/n) ");
Char answer = Input.next (). charAt (0);
while (answer = = ' Y ') {
It.show ();
Is.show ();
if (It.num = = is.sum) {
System.out.println ("Draw");
} else if ((It.num = = 2) && (is.sum = = 1)) | | (It.num = = 1) && (is.sum = = 3) | | ((It.num = = 3) && (is.sum = = 2))) {
System.out.println ("You won, it's awesome!") ");
it.score++;
} else {
System.out.println ("You've lost, you're stupid!") ");
is.score++;
}
witch++;
System.out.println ("\ n");
System.out.println ("Do you want to continue?" (y/n) ");
Answer = Input.next (). charAt (0);
}
}
/**
* How to define game billing
*/
public void Showresult () {
System.out.println ("********************************");
System.out.println (it.name + "VS" + is.name);
System.out.println ("PvP times:" + witch);
System.out.println ("\ n name \t\t score");
System.out.println (it.name + "\t\t" + it.score);
System.out.println (is.name + "\t\t" + is.score);
if (It.score < Is.score) {
System.out.println ("You really stupid, next time refueling!") ");
} else if (It.score = = Is.score) {
System.out.println ("Even a draw, our next showdown!") ");
} else {
System.out.println ("You're awesome! It's amazing!! ");
}
System.out.println ("********************************");
}
}
Test class:
Package java12;
public class Renjicaiquan3 {
public static void Main (string[] args) {
Renjicaiquan2 play=new renjicaiquan2 (); Creating objects for Game classes
Play.process (); Call game Process method of game class
Play.showresult (); Call the game class's billing method
}
Man-Machine Scissors