Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class HandCricket
- {
- static Scanner x= new Scanner(System.in);
- public static void Cricket()
- {
- int p1, p12, total = 0, total2 = 0, control = 0, control2 = 0;
- double cpud, cpud2;
- int cpu, cpu2;
- System.out.println("You have selected the option for Hand Cricket. It is a very popular game among kids in India. Rules of the games are as follows");
- System.out.println("This is a player vs computer game. Both will get a chance to bat. You have to enter a number between 1 and 6. At the same time the computer will generate a number.");
- System.out.println("If the number you enter is the same as the number generated by the computer then you will be declared out. If not then the number will be added to your total score.");
- System.out.println("This will be repeated until you get out. Once you get out the same process is repeated but you will be bowling. Whoever manages to score more runs wins.");
- System.out.println("Any number larger than 6 or smaller than 1 will not be considered and runs will not be counted while batting or bowling");
- System.out.println("Begin by entering a number.");
- do
- {
- p1 = x.nextInt();
- cpud = Math.random()*(6-1)+1;
- cpu = (int)Math.rint(cpud);
- if( p1>=6 || p1<1 )
- {
- System.out.println("Not a number between 1 and 6. Please try again.");
- }
- else
- {
- System.out.println("You- " + p1 +". Computer- " + cpu);
- if( p1 == cpu )
- {
- System.out.println("You are out");
- control++;
- }
- else
- total+= p1;
- }
- }while(control == 0);
- System.out.println("Your total score is = " +total);
- System.out.println("Your chance to bowl");
- do
- {
- p12 = x.nextInt();
- cpud2 = Math.random()*(6-1)+1;
- cpu2 = (int)Math.rint(cpud2);
- System.out.println("You- " + p12 +". Computer- " + cpu2);
- if( p12>=6 || p12<1 )
- {
- System.out.println("Not a number between 1 and 6. Please try again.");
- }
- else
- {
- if( p12 == cpu2 )
- {
- System.out.println("Computer is out");
- control2++;
- }
- else
- total2+= cpu2;
- }
- if(total2 > total)
- break;
- }while(control2 == 0);
- System.out.println("Computers total score is = " +total2);
- if(total > total2)
- System.out.println("You win");
- else if(total < total2)
- System.out.println("You lose");
- else
- System.out.println("It's a draw");
- }
- }
RAW Paste Data
Copied