start a new game

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I need help with the level 3, 4 features mentioned in the picture. My code is attached below

 

    int rounds = 0;
    int playerScore = 0;
    int computerScore = 0;
    int playerNumber = 1;
    int computerNumber = 1;
    int playerLosses = 0;
    int computerLosses = 0;
    int playerWins = 0;
    int computerWins = 0;
    int playerTies = 0;
    int computerTies = 0;
    int playerTotalPoints = 0;
    int computerTotalPoints = 0;
    int playerRolls = 0;
    int computerRolls = 0;
    int menuChoice = 0;
    

    PrintStream output = new PrintStream(new File("output.txt"));
    PrintStream console = System.out;   
    System.setOut(output);
    
    c.println("\t\t\t\tDice Game");
    c.println("\t\t\t\t---------");
    c.println("Please select your option:");
    c.println("1- Play against computer.");
    c.println("2- Exit the game, show summary and print to output.txt.");
    c.println("******************************************************");
    menuChoice = c.readInt();
    

    c.clear();
    

    while(menuChoice != 2)
    {
      if(menuChoice == 1)
      {
        c.println("How many rounds would you like to play?");
        rounds = c.readInt();
        c.println();
      }
      else if(menuChoice == 2)
      {
        System.exit(0)
      }
      else 
      {
        c.println("Invalid option. Choose again.");
      }
      
      //for loop
      for(int x = 0; x < rounds; x++)
      {
        playerNumber = (int) (Math.random()*6 + 1);
        computerNumber = (int) (Math.random()*6 + 1);
        
        if(playerNumber > computerNumber)
        {
          c.println("You win round "  + (x+1) + ".");    
          
          
          playerWins++;
          computerLosses++;
        }
        else if(computerNumber > playerNumber)
        {
          c.println("The computer wins round " + (x+1) + "." );  
          
          
          computerWins++;
          playerLosses++;
        }
        else if(playerNumber == computerNumber)
        {
          c.println("Round " + (x+1) + " is a tie.");
          

          playerTies++;
          computerTies++;
        }
   
        playerScore = ((2*(playerWins)) + playerTies);
        computerScore = ((2*(computerWins)) + computerTies);
        

        System.out.println("[Player]");
        System.out.println("Player Dice Number: " + playerNumber);    
        c.println("Player Dice Number: " + playerNumber); 
        System.out.println("Player Rolls: " + playerRolls++);                                  
        System.out.println("Points: " + playerScore);            
        c.println("Points: " + playerScore);                 
        System.out.println("Wins: " + playerWins);                    
        System.out.println("Losses: " + playerLosses);             
        System.out.println("Ties: " + playerTies);
        
        System.out.println();
        
        System.out.println("[Computer]");
        System.out.println("Computer Dice Number: " + computerNumber);     
        c.println("Computer Dice Number: " + computerNumber);     
        System.out.println("Computer Rolls: " + computerRolls++); 
        System.out.println("Points: " + computerScore);
        c.println("Points: " + computerScore);
        System.out.println("Wins: " + computerWins);
        System.out.println("Losses: " + computerLosses);
        System.out.println("Ties: " + computerTies);
        System.out.println("*****************************************");
        System.out.println();
        
        c.println("Press [Enter] to continue.");
        c.getChar();
        c.println();
      }
      
      c.println("Please select your option");
      c.println("1- Play against computer.");
      c.println("2- Exit the game, show summary and print to output.txt.");
      c.println("******************************************************");
      menuChoice = c.readInt();
      
      c.clear();    
      
      if(playerScore > computerScore)
      {
        c.println("You win the game by " + (playerScore - computerScore) + " point(s)!");
        c.println("--> Detailed rounds summary has been printed to output.txt");
        System.out.println(">You won the game!");
        System.out.println("------------------");
      }
      else if(computerScore > playerScore)
      {
        c.println("The computer wins the game by " + (computerScore - playerScore) + " point(s)!");
        c.println("--> Detailed rounds summary has been printed to output.txt");
        System.out.println(">The computer won the game!");
        System.out.println("---------------------------");
      }
      else if(playerScore == computerScore)
      {
        c.println("Both the players have an equal score.");
        c.println("Player score = " + playerScore);
        c.println("Computer score = " + computerScore);
        c.println("--> Detailed rounds summary has been printed to output.txt");
        System.out.println(">Both players have an equal score. It is a tie");
        System.out.println("----------------------------------------------");
      }
      

      output.close();
    }

Level 3 Features
- A player must be able to start a new game after finishing a game.
The results of each round and the final game result is written to an Output.txt file.
- The details of each round of play are stored in an array.
Level 4 Features
- The game stats & winner declaration must be processed and displayed using a command method
called outputResults() that uses the information stored in the array that stores the points from
each round played.
Transcribed Image Text:Level 3 Features - A player must be able to start a new game after finishing a game. The results of each round and the final game result is written to an Output.txt file. - The details of each round of play are stored in an array. Level 4 Features - The game stats & winner declaration must be processed and displayed using a command method called outputResults() that uses the information stored in the array that stores the points from each round played.
Expert Solution
steps

Step by step

Solved in 7 steps with 8 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY