Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.Math;
- import java.util.Scanner;
- class Vending_Machine
- {
- private static int n;
- static int arr[];
- static
- {
- n = (int)(Math.random()*10 + 1);
- arr = new int[2];
- }
- static int draw( int draw , int playerno )
- {
- if(n % draw == 0)
- {
- n = n - draw;
- arr[playerno - 1]++;
- if(n == 0)
- System.out.println("Player " + ((arr[0] > arr[1]) ? 1 : 2) + " wins");
- return 1;
- }
- else
- {
- System.out.println("Sorry you couldnt take anything");
- return 0;
- }
- }
- static boolean isEmpty()
- {
- if(n == 0)
- return true;
- return false;
- }
- };
- class Driver
- {
- public static void main(String args[])
- {
- int play1;
- int play2;
- Scanner sc = new Scanner(System.in);
- System.out.println("GAME SHOW STARTS");
- while(!Vending_Machine.isEmpty())
- {
- System.out.println("Player1 GIVE CHOICE !!");
- play1 = sc.nextInt();
- Vending_Machine.draw(play1,1);
- if(Vending_machine.isEmpty()) break;
- System.out.println("Player2 GIVE CHOICE !!");
- play2 = sc.nextInt();
- Vending_Machine.draw(play2,2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement