I have the following code in java, replit: //First class public class Main {     public static void main(String[] args) {         Scanner console = new Scanner(System.in);         Random random = new Random();         Game game = new Game(console, random);         game.startGame();         console.close();            } }   //Second class import java.util.Scanner; public class Player {   private String name;   private int totalGames;   private int totalGuesses;   private int bestGame;   public Player() {       this.name = null;        this.totalGames = 0;       this.totalGuesses = 0;       this.bestGame = Integer.MAX_VALUE;   }   public String getName() {       return name;   }   public void setName(String name) {       this.name = name;   }   public int getTotalGames() {       return totalGames;   }   public void setTotalGames(int totalGames) {       this.totalGames = totalGames;   }   public int getTotalGuesses() {       return totalGuesses;   }   public void setTotalGuesses(int totalGuesses) {       this.totalGuesses = totalGuesses;   }   public int getBestGame() {       return bestGame;   }   public void setBestGame(int bestGame) {       this.bestGame = bestGame;   }    }   //Third class import java.util.Scanner; import java.util.Random; public class Game {     public static final int MAX = 100;     private final Scanner console;     private final Random random;     public Game(Scanner console, Random random) {         this.console = console;         this.random = random;     }     public void startGame() {         int totalGames = 0;         int totalGuesses = 0;         int bestGame = Integer.MAX_VALUE;         Player player = new Player();          while (true) {             int answer = 1 + random.nextInt(MAX);             int guesses = playGame(console, answer);             totalGames++;             totalGuesses += guesses;             bestGame = Math.min(bestGame, guesses);             player.setTotalGames(totalGames);             player.setTotalGuesses(totalGuesses);             player.setBestGame(bestGame);             System.out.println("Play again y/n?");             String playAgain = console.next().toLowerCase();             if (!playAgain.startsWith("y")) {                 break;             }         }         printOverallStatistics(player.getTotalGames(), player.getTotalGuesses(), player.getBestGame());     }   public int playGame(Scanner console, int answer) {           System.out.println("I'm thinking of a number between 1 and " + Game.MAX + "...");           int guesses = 0;           while (true) {               System.out.print("Your guess? ");               if (console.hasNextInt()) {                   int guess = console.nextInt();                   guesses++;                   if (guess == answer) {                       System.out.println("You got it right in " + guesses + " guess" + (guesses == 1 ? "!" : "es!"));                       break;                   } else if (guess < answer) {                       System.out.println("It's higher.");                   } else {                       System.out.println("It's lower.");                   }               } else {                   System.out.println("Invalid input. Please enter a valid integer.");                   console.next();                }           }           return guesses;       }     private void printOverallStatistics(int totalGames, int totalGuesses, int bestGame) {         System.out.println("Total games: " + totalGames);         System.out.println("Total guesses: " + totalGuesses);         System.out.println("Guesses/game: " + (totalGames == 0 ? 0 : totalGuesses / totalGames));         System.out.println("Best game: " + bestGame);     }          public static void main(String[] args) {         Scanner console = new Scanner(System.in);         Random random = new Random();         Game game = new Game(console, random);         game.startGame();         console.close();     } }     Now I've created a player_results.csv file. I want help with adding code to my existing class so that it reads from the csv file(which can be updated by just editing it, example in attachment below). Then, convert those strings into a player object you can use to resume a series of games in the console. In other words, update the players statistics as though they were resuming from the state they last left the guessing game. It should work for all players you add in the file. You must use these:  java.io.File java.io.FileWriter java.util.Scanner java.util.Random java.util.UUID Must use FileWriter not bufferedfilewriter or anything else, and Arrays.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I have the following code in java, replit:

//First class

public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        Random random = new Random();

        Game game = new Game(console, random);
        game.startGame();

        console.close();
      
    }
}

 

//Second class

import java.util.Scanner;

public class Player {
  private String name;
  private int totalGames;
  private int totalGuesses;
  private int bestGame;

  public Player() {
      this.name = null; 
      this.totalGames = 0;
      this.totalGuesses = 0;
      this.bestGame = Integer.MAX_VALUE;
  }

  public String getName() {
      return name;
  }

  public void setName(String name) {
      this.name = name;
  }

  public int getTotalGames() {
      return totalGames;
  }

  public void setTotalGames(int totalGames) {
      this.totalGames = totalGames;
  }
  public int getTotalGuesses() {
      return totalGuesses;
  }

  public void setTotalGuesses(int totalGuesses) {
      this.totalGuesses = totalGuesses;
  }

  public int getBestGame() {
      return bestGame;
  }

  public void setBestGame(int bestGame) {
      this.bestGame = bestGame;
  }
  
}

 

//Third class

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

public class Game {
    public static final int MAX = 100;
    private final Scanner console;
    private final Random random;

    public Game(Scanner console, Random random) {
        this.console = console;
        this.random = random;
    }

    public void startGame() {
        int totalGames = 0;
        int totalGuesses = 0;
        int bestGame = Integer.MAX_VALUE;

        Player player = new Player(); 

        while (true) {
            int answer = 1 + random.nextInt(MAX);
            int guesses = playGame(console, answer);

            totalGames++;
            totalGuesses += guesses;
            bestGame = Math.min(bestGame, guesses);

            player.setTotalGames(totalGames);
            player.setTotalGuesses(totalGuesses);
            player.setBestGame(bestGame);

            System.out.println("Play again y/n?");
            String playAgain = console.next().toLowerCase();
            if (!playAgain.startsWith("y")) {
                break;
            }
        }

        printOverallStatistics(player.getTotalGames(), player.getTotalGuesses(), player.getBestGame());
    }

  public int playGame(Scanner console, int answer) {
          System.out.println("I'm thinking of a number between 1 and " + Game.MAX + "...");
          int guesses = 0;

          while (true) {
              System.out.print("Your guess? ");
              if (console.hasNextInt()) {
                  int guess = console.nextInt();
                  guesses++;

                  if (guess == answer) {
                      System.out.println("You got it right in " + guesses + " guess" + (guesses == 1 ? "!" : "es!"));
                      break;
                  } else if (guess < answer) {
                      System.out.println("It's higher.");
                  } else {
                      System.out.println("It's lower.");
                  }
              } else {
                  System.out.println("Invalid input. Please enter a valid integer.");
                  console.next(); 
              }
          }
          return guesses;
      }

    private void printOverallStatistics(int totalGames, int totalGuesses, int bestGame) {
        System.out.println("Total games: " + totalGames);
        System.out.println("Total guesses: " + totalGuesses);
        System.out.println("Guesses/game: " + (totalGames == 0 ? 0 : totalGuesses / totalGames));
        System.out.println("Best game: " + bestGame);
    }

    
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        Random random = new Random();

        Game game = new Game(console, random);
        game.startGame();

        console.close();
    }
}


   

Now I've created a player_results.csv file. I want help with adding code to my existing class so that it reads from the csv file(which can be updated by just editing it, example in attachment below). Then, convert those strings into a player object you can use to resume a series of games in the console. In other words, update the players statistics as though they were resuming from the state they last left the guessing game. It should work for all players you add in the file. You must use these: 

  • java.io.File
  • java.io.FileWriter
  • java.util.Scanner
  • java.util.Random
  • java.util.UUID

Must use FileWriter not bufferedfilewriter or anything else, and Arrays.

Search
✓ Files Ⓒ
04 - Guessing Game.pdf
Game.java
GameManager.java
Main.java
player_results.csv
Player.java
Packager files
target
pom.xml
✓ Tools
All
Recent
C AI
Authentication
Chat
Q Code Search
> Console
Database
⠀
CtrlShiftF
Main.java X Player.java
player_results.csv
1 Sid, 1,7,7
2
3
CAI
(*) Comma Separated Values
player_results.csv X
Game.java x
+
Ln 1, Col 10 • Spaces: 2 History
> Console û x
Run
Run
I'm thinking of a number between 1 and 100...
Your guess? 40
It's lower.
Your guess? 30
It's lower.
Your guess? 20
It's lower.
Your guess? 10
It's lower.
Your guess? 5
It's higher.
Your guess? 7
It's lower.
Your guess? 6
You got it right in 7 guesses!
Play again y/n?
Yes
I'm thinking of a number between 1 and 100...
Your guess? 40
It's lower.
Your guess? 20
It's higher.
Your guess? 30
It's higher.
Shell x +
Your guess? 34
It's lower.
Your guess? 32
It's lower.
Your guess? 31
You got it right in 6 guesses!
Play again y/n?
No
Total games: 2
Total guesses: 13
Guesses/game: 6
Best game: 6
2s on 20:55:51, 01/20/
43m on 20:56:03, 01/20 ✓
Transcribed Image Text:Search ✓ Files Ⓒ 04 - Guessing Game.pdf Game.java GameManager.java Main.java player_results.csv Player.java Packager files target pom.xml ✓ Tools All Recent C AI Authentication Chat Q Code Search > Console Database ⠀ CtrlShiftF Main.java X Player.java player_results.csv 1 Sid, 1,7,7 2 3 CAI (*) Comma Separated Values player_results.csv X Game.java x + Ln 1, Col 10 • Spaces: 2 History > Console û x Run Run I'm thinking of a number between 1 and 100... Your guess? 40 It's lower. Your guess? 30 It's lower. Your guess? 20 It's lower. Your guess? 10 It's lower. Your guess? 5 It's higher. Your guess? 7 It's lower. Your guess? 6 You got it right in 7 guesses! Play again y/n? Yes I'm thinking of a number between 1 and 100... Your guess? 40 It's lower. Your guess? 20 It's higher. Your guess? 30 It's higher. Shell x + Your guess? 34 It's lower. Your guess? 32 It's lower. Your guess? 31 You got it right in 6 guesses! Play again y/n? No Total games: 2 Total guesses: 13 Guesses/game: 6 Best game: 6 2s on 20:55:51, 01/20/ 43m on 20:56:03, 01/20 ✓
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education