Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

So, I asked this question before, but the answer I got wasn\'t what I asked for.

ID: 3663728 • Letter: S

Question

So, I asked this question before, but the answer I got wasn't what I asked for. Anyway, I need help writing a java program that plays a rock, paper, scissors double round game using a circular linked list. Each player (#0-9) in the tournament is controlled by the computer, and "they" (computer acting as the player) randomly choose rock, paper, or scissors each round. The computer players have a win, lose, and tie record, which is displayed at the end of each individual round. (ex: 0 vs 1, 0 vs 2,...0 vs 9) And after #0-9 have played against everyone, they compete against everyone ONE MORE TIME. At the very end of all the games, the scores (wins, ties, and losses) of each number (#0-9) are displayed.

Explanation / Answer

import java.util.Random;
import java.util.Scanner;

public class Game {
  
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       Random generator = new Random();
       System.out.println("Enter no of players: ");
       int no_of_players = sc.nextInt();
      
       String personPlay=""; //User's play -- "R", "P", or "S"
        String otherPlay = ""; //Other's play -- "R", "P", or "S"
        int personInt; //Randomly generated number used to determine computer's play
        int otherIntInt;
        String response;
      
      
       CircularLL list = new CircularLL(no_of_players);
       int i =0;
       Player start = list.head;
       Player current = null;
      
      
       System.out.println("Welcome to the Rock Paper Scissors Tournament!");
       System.out.println("We have "+no_of_players+" players. Let’s BEGIN!");
      
       while(i < no_of_players) {
           current = list.getNext(start);
           while(current != start) {
              
               //Generate computer's play (0,1,2)
               personInt = generator.nextInt(3)+1;
              
                //Translate computer's randomly generated play to
                //string using if //statements
                if (personInt == 1) {
                   personPlay = "R";
                   System.out.println(start.name + " uses Rock");
                }
                else if (personInt == 2) {
                   personPlay = "P";
                   System.out.println(start.name + " uses Paper");
                }
                else if (personInt == 3) {
                   personPlay = "S";
                   System.out.println(start.name + " uses Scissors");
                }
              
              
              //Generate computer's play (0,1,2)
               otherIntInt = generator.nextInt(3)+1;
              
                //Translate computer's randomly generated play to
                //string using if //statements
                if (otherIntInt == 1) {
                   otherPlay = "R";
                   System.out.println(current.name + " uses Rock");
                }
                else if (otherIntInt == 2) {
                   otherPlay = "P";
                   System.out.println(current.name + " uses Paper");
                }
                else if (otherIntInt == 3) {
                   otherPlay = "S";
                   System.out.println(current.name + " uses Scissors");
                }


                if (otherPlay.equals(personPlay)) {
                   start.no_of_ties++;
                   current.no_of_ties++;
                   System.out.println("TIE!");
                }
                else if (otherPlay.equals("R")) {
                   if (personPlay.equals("S")){
                       current.no_of_wins++;
                       start.no_of_losses++;
                       System.out.println(current.name+" Wins!");
                   }else if (personPlay.equals("P")) {
                       start.no_of_wins++;
                       current.no_of_losses++;
                       System.out.println(start.name+" Wins!");
                   }
                }
                else if (otherPlay.equals("P")) {
                   if (personPlay.equals("S")) {
                       start.no_of_wins++;
                       current.no_of_losses++;
                       System.out.println(start.name+" Wins!");
                   }else if (personPlay.equals("R")) {
                       current.no_of_wins++;
                       start.no_of_losses++;
                       System.out.println(current.name+" Wins!");
                   }
                }
                else if (otherPlay.equals("S")) {
                     if (personPlay.equals("P")) {
                       current.no_of_wins++;
                           start.no_of_losses++;
                           System.out.println(current.name+" Wins!");
                     }else if (personPlay.equals("R")) {
                       start.no_of_wins++;
                           current.no_of_losses++;
                           System.out.println(start.name+" Wins!");
                     }
                }
              
                current = current.next; // playing with next player
           }
          
           i++;
           start = start.next;
       }
      
       System.out.println("The tournament is over here are the results!");
       // Traversing
       start = list.head;
       i = 0;
       while( i < no_of_players) {
           System.out.println("Name "+start.name+" Wins "+start.no_of_wins+
                   " Ties "+start.no_of_ties+" Losses "+start.no_of_losses);
           start = start.next;
           i++;
       }
      
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote