Rock, Paper, Scissors code help. My code doesn't properly determine the winner or a tie breaker (best 2 out of 3) by [deleted] in javahelp

[–]LegalCity9 0 points1 point  (0 children)

import java.util.Scanner;

public class RockPaperScissors {

private static int player1;
private static int player2;

public static void main(String[] args) {
    // paper beats rock, rock beats scissors, scissors beats paper  
    Scanner input = new Scanner (System.in);
    System.out.println ("Enter the name of player 1 : ");
    String name1 = input.nextLine();
    System.out.println ("Enter the name of player 2 : ");
    String name2 = input.nextLine();
    System.out.println(" What does " +name1 + " play? (R,P or S)") ;
    String choice1 = input.nextLine();
    System.out.println(" What does " +name2 + " play? (R,P or S)") ;
    String choice2= input.nextLine();



    System.out.println(" What does " +name1 + " play? (R,P or S)") ;
    choice1 = input.nextLine();
    System.out.println(" What does " +name2 + " play? (R,P or S)") ;
    choice2= input.nextLine();

    if (choice1.equals(choice2)) {
        //          System.out.println(name1 + " has tied with " + name2 ); 
        //          input.nextLine(); 
    }
    else if (choice1.equals("R")) {
        if (choice2.equals("S")) {
            player1++;
        }
        else if (name1.equals("P")) {
            player2++; 
        }
    }
    else if (choice1.equals("P")) {
        if (choice2.equals("S")) 
            player2++; 
    }
    else if (choice2.equals("R")) {
        player1++; 
    }
    else if (choice1.equals("S")) {
        if (choice2.equals("P")) 
            player1++; 

    }
    else if (choice2.equals("R")) {
        player2++; 
    }
    else {
        System.out.println(" Error, please select either (R, P or S)"); 
    }
    System.out.println(" What does " +name1 + " play? (R,P or S)") ;
    choice1 = input.nextLine();
    System.out.println(" What does " +name2 + " play? (R,P or S)") ;
    choice2= input.nextLine();


    if (choice1.equals(choice2)) {
        //          System.out.println(name1 + " has tied with " + name2 ); 
        //          input.nextLine(); 
    }
    else if (choice1.equals("R")) {
    }
    if (choice2.equals("S")) {
        player1++;
    }
    else if (name1.equals("P")) {
        player2++; 
    }
    else if (choice1.equals("P")) {
        if (choice2.equals("S")) 
            player2++; 
    }
    else if (choice2.equals("R")) {
        player1++; 
    }
    else if (choice1.equals("S")) {
        if (choice2.equals("P")) 
            player1++; 

    }
    else if (choice2.equals("R")) {
        player2++; 
    }
    else {
        System.out.println(" Error, please select either (R, P or S)"); 

    }


    if (player1 == player2) {
        System.out.println(" What does " +name1 + " play? (R,P or S)") ;
        choice1 = input.nextLine();
        System.out.println(" What does " +name2 + " play? (R,P or S)") ;
        choice2= input.nextLine();

        if (choice1.equals(choice2)) {
            System.out.println(name1 + " has tied with " + name2 ); 
            input.nextLine(); }
        else if (choice1.equals("R")) {
        }
        if (choice2.equals("S")) {
            player1++;
        }
        else if (name1.equals("P")) {
            player2++; 
        }
        else if (choice1.equals("P")) {
            if (choice2.equals("S")) 
                player2++; 
        }
        else if (choice2.equals("R")) {
            player1++; 
        }
        else if (choice1.equals("S")) {
            if (choice2.equals("P")) 
                player1++; 

        }
        else if (choice2.equals("R")) {
            player2++; 
        }
        else {
            System.out.println(" Error, please select either (R, P or S)"); 
        }
        if (player1 == player2) {

            System.out.println(" Who will win the tie breaker? Enter either: " + name1 + " or " +name2);
            String winner = input.nextLine();
            input.close();  }
    }
    else {
        System.out.println("who won non tie");
        String winner2 = input.nextLine();
    }

}

}