Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- Donkey D = new Donkey();
- Monkey M = new Monkey();
- Parrot P = new Parrot();
- int g2 = (int)(Math.random() * 2);
- int g1 = (int)(Math.random() * 3);
- if (g1 == 0 || g2 == 1){
- g1 = D.show(); //wybieramy Donkey
- g2 = M.show(); //wybieramy Monkey
- }
- else if (g1 == 0 || g2 == 2){
- g1 = D.show(); //wybieramy Donkey
- g2 = P.show(); //wybieramy Parrot
- }
- else if (g1 == 1 || g2 == 2){
- g1 = M.show(); //wybieramy Monkey
- g2 = P.show(); //wybieramy Parrot
- }
- System.out.println();
- Judge J = new Judge();
- J.play(g1, g2);
- System.out.println(g1);
- System.out.println(g2);
- }
- }
- public interface Player {
- int show();
- }
- public class Donkey implements Player{
- @Override
- public int show() {
- System.out.println("Donkey choose Rock");
- return 0;
- }
- }
- public class Monkey implements Player {
- @Override
- public int show() {
- int random = (int)(Math.random() * 3);
- if (random == 0){
- System.out.println("Monkey choose Rock");
- }
- else if (random == 1){
- System.out.println("Monkey choose Papper");
- }
- else if (random == 2){
- System.out.println("Monkey choose Scissors");
- }
- return random;
- }
- }
- public class Parrot implements Player {
- @Override
- public int show() {
- int random = (int)(Math.random() * 2);
- if (random == 0){
- System.out.println("Parrot choose Rock");
- }
- else if (random == 1){
- System.out.println("Parrot choose Papper");
- }
- return random;
- }
- }
- public class Judge {
- void play(int g1, int g2){
- System.out.println("And the winner is ");
- if (g1>g2)
- System.out.println("g1>g2");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement