SHARE
TWEET

eloeloeloelo

a guest Oct 21st, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Main {
  2.     public static void main(String[] args) {
  3.  
  4.         Donkey D = new Donkey();
  5.         Monkey M = new Monkey();
  6.         Parrot P = new Parrot();
  7.  
  8.         int g2 = (int)(Math.random() * 2);
  9.         int g1 = (int)(Math.random() * 3);
  10.  
  11.         if (g1 == 0 || g2 == 1){
  12.             g1 = D.show(); //wybieramy Donkey
  13.             g2 = M.show(); //wybieramy Monkey
  14.         }
  15.         else if (g1 == 0 || g2 == 2){
  16.             g1 = D.show(); //wybieramy Donkey
  17.             g2 = P.show(); //wybieramy Parrot
  18.         }
  19.         else if (g1 == 1 || g2 == 2){
  20.             g1 = M.show(); //wybieramy Monkey
  21.             g2 = P.show(); //wybieramy Parrot
  22.         }
  23.  
  24.  
  25.         System.out.println();
  26.  
  27.         Judge J = new Judge();
  28.         J.play(g1, g2);
  29.         System.out.println(g1);
  30.         System.out.println(g2);
  31.     }
  32. }
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. public interface Player {
  46.     int show();
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. public class Donkey implements Player{
  63.  
  64.     @Override
  65.     public int show() {
  66.         System.out.println("Donkey choose Rock");
  67.         return 0;
  68.     }
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. public class Monkey implements Player {
  82.  
  83.     @Override
  84.     public int show() {
  85.         int random = (int)(Math.random() * 3);
  86.         if (random == 0){
  87.             System.out.println("Monkey choose Rock");
  88.         }
  89.         else if (random == 1){
  90.             System.out.println("Monkey choose Papper");
  91.         }
  92.         else if (random == 2){
  93.             System.out.println("Monkey choose Scissors");
  94.         }
  95.         return random;
  96.     }
  97. }
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. public class Parrot implements Player {
  117.  
  118.     @Override
  119.     public int show() {
  120.         int random = (int)(Math.random() * 2);
  121.         if (random == 0){
  122.             System.out.println("Parrot choose Rock");
  123.         }
  124.         else if (random == 1){
  125.             System.out.println("Parrot choose Papper");
  126.         }
  127.         return random;
  128.     }
  129. }
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143. public class Judge {
  144.  
  145.     void play(int g1, int g2){
  146.         System.out.println("And the winner is ");
  147.         if (g1>g2)
  148.             System.out.println("g1>g2");
  149.     }
  150. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top