I have created the following code in java, replit, that's a guessing game. Attached are the classes I've created as separate files. Since I can only upload 2 files, I have written the code in class Main at the very end. Now I need to create and write data into a CSV file, tracking the results of multiple players scores in the Guessing Game. This will require the use of several imported java class including : java.io.File java.io.FileWriter java.util.Scanner java.util.Random java.util.UUID java.io.IOException; And I know nothing about this, so I really need help. You would need to modify all my classes/files accordingly. Also ignore the results.csv file that I tried creating in the pdfs attached. Basically you would need to use the File object along with the Player object, and the properties of the player class is what needs to be written into the CSV. I haven't included any properties of the player class yet (like private UUID id; private String name; private int totalGames; private int totalGuesses; private int bestGame; something along those lines). Use a File and the Scanner to resume a players set of games as read from the CSV.   This is how class main looks like: import java.util.Scanner; import java.util.Random; 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();     } }

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 created the following code in java, replit, that's a guessing game. Attached are the classes I've created as separate files. Since I can only upload 2 files, I have written the code in class Main at the very end. Now I need to create and write data into a CSV file, tracking the results of multiple players scores in the Guessing Game. This will require the use of several imported java class including :

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

And I know nothing about this, so I really need help. You would need to modify all my classes/files accordingly. Also ignore the results.csv file that I tried creating in the pdfs attached. Basically you would need to use the File object along with the Player object, and the properties of the player class is what needs to be written into the CSV. I haven't included any properties of the player class yet (like private UUID id; private String name; private int totalGames; private int totalGuesses; private int bestGame; something along those lines). Use a File and the Scanner to resume a players set of games as read from the CSV.

 

This is how class main looks like:

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

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();
    }
}

0>
Search
✓ Files
.settings
.classpath
Main.java
Player.java
ii results.csv
.project
04 - Guessing Game.pdf
Game.java
GameManager.java
Packager files
target
pom.xml
✓ Tools
All
Recent
Ω AI
Authentication
Chat
Q Code Search
> Console
04 - Guessing Game-ShriIyer ✓
Database
▷I Debugger
Docs
Extensions
000
4 Join Replit Core
Ctrl Shift F
X
Main.java x
Player.java
1 import java.util.Scanner;
2
3 public class Player {
4 v
5
6
7
8 v
9
10 v
11
12
13
14 v
15
16
17 v
18
19 v
20
21
22 y
23
24
25
26
27
28
29
+ "...");
9
04 - Guessing Game.pdf x
}
public int playGame (Scanner console, int answer) {
System.out.println("I'm thinking of a number between 1 and " + Game. MAX
integer.");
}
int guesses = 0;
AI (✓) Java
while (true) {
guess" + (guesses ==1 ? "!" : "es!"));
break;
} else if (guess < answer) {
System.out.print("Your guess? ");
if (console. hasNextInt()) {
Player.java X Game.java x
int guess = console.nextInt();
guesses++;
}
if (guess == answer) {
System.out.println("You got it right in " + guesses + "
System.out.println("It's higher.");
System.out.println("It's lower.");
} else {
}
} else {
+
}
return guesses;
■ Stop
System.out.println("Invalid input. Please enter a valid
console.next(); // consume invalid input
Ln 29, Col 2 • Spaces: 2 History
> Console X
Run
It's lower.
Your guess? 76
It's lower.
Your guess? 65
quess?
It's lower.
I cower
60
Your guess?
It's higher.
to megmen
Your guess? 61
It's higher.
is higher
Your guess? 62
It's higher.
Your guess? 63
You got it right in 11 guesses!
Play again? (y/n)
No
Overall results:
Total games
= 1
Total guesses = 11
Guesses/game = 11.0
Best game
= 11
Run
Shell
Your guess? 3
It's higher.
Your guess? 4
It's higher.
It's higher.
Your quess?
Your guess?
It's
It's higher
5
higher.
I'm thinking of a number between 1 and 100...
Your guess? 2
It's higher.
Your guess? 6
It's
It's
higher.
higher.
Your guess? 7
It's higher.
It's higher.
Your guess?
Your guess? 8
It's higher.
It's higher.
Your quess?
Your guess?
higher.
30
It's
Your guess? 40
It's higher.
Your guess? 50
It's lower.
Your guess?
80%
+
Reset
Transcribed Image Text:0> Search ✓ Files .settings .classpath Main.java Player.java ii results.csv .project 04 - Guessing Game.pdf Game.java GameManager.java Packager files target pom.xml ✓ Tools All Recent Ω AI Authentication Chat Q Code Search > Console 04 - Guessing Game-ShriIyer ✓ Database ▷I Debugger Docs Extensions 000 4 Join Replit Core Ctrl Shift F X Main.java x Player.java 1 import java.util.Scanner; 2 3 public class Player { 4 v 5 6 7 8 v 9 10 v 11 12 13 14 v 15 16 17 v 18 19 v 20 21 22 y 23 24 25 26 27 28 29 + "..."); 9 04 - Guessing Game.pdf x } public int playGame (Scanner console, int answer) { System.out.println("I'm thinking of a number between 1 and " + Game. MAX integer."); } int guesses = 0; AI (✓) Java while (true) { guess" + (guesses ==1 ? "!" : "es!")); break; } else if (guess < answer) { System.out.print("Your guess? "); if (console. hasNextInt()) { Player.java X Game.java x int guess = console.nextInt(); guesses++; } if (guess == answer) { System.out.println("You got it right in " + guesses + " System.out.println("It's higher."); System.out.println("It's lower."); } else { } } else { + } return guesses; ■ Stop System.out.println("Invalid input. Please enter a valid console.next(); // consume invalid input Ln 29, Col 2 • Spaces: 2 History > Console X Run It's lower. Your guess? 76 It's lower. Your guess? 65 quess? It's lower. I cower 60 Your guess? It's higher. to megmen Your guess? 61 It's higher. is higher Your guess? 62 It's higher. Your guess? 63 You got it right in 11 guesses! Play again? (y/n) No Overall results: Total games = 1 Total guesses = 11 Guesses/game = 11.0 Best game = 11 Run Shell Your guess? 3 It's higher. Your guess? 4 It's higher. It's higher. Your quess? Your guess? It's It's higher 5 higher. I'm thinking of a number between 1 and 100... Your guess? 2 It's higher. Your guess? 6 It's It's higher. higher. Your guess? 7 It's higher. It's higher. Your guess? Your guess? 8 It's higher. It's higher. Your quess? Your guess? higher. 30 It's Your guess? 40 It's higher. Your guess? 50 It's lower. Your guess? 80% + Reset
D>
Search
✓ Files Ⓒ
settings
classpath
Main.java
4 Player.java
results.csv
project
04 - Guessing Game.pdf
Game.java
GameManager.java
Packager files
target
pom.xml
✓ Tools
Recent
All
1000000
AI
Authentication
Chat
Q Code Search
> Console
Database
DI Debugger
Docs
| 04 - Guessing Game-ShriIyer
Extensions
-Git
Packages
PostgreSQL
Join Replit Core
Ctrl Shift F
X
Main.java
Game.java
1 import java.util. Random;
2
import java.util.Scanner;
3
5
6
7
8
9v
10
11
12
13
14 v
15
6 7 18 19 20122 3 24 25 26 27 28 29 01234355劲894042 3 4 45 46 x
16
17
36
37 0
38 |
43
44
CAI
public class Game {
v
public static final int MAX = 100;
private final Scanner console;
private final Random random;
J.04 - Guessing Game.pdf x Player.java x
}
public Game(Scanner console, Random random) {
this.console = console;
this.random = random;
public void startGame() {
int totalGames = 0;
int totalGuesses = 0;
}
}
() Java
int bestGame = Integer.MAX_VALUE;
while (true) {
}
Player player = new Player();
int answer = 1 + random.nextInt(MAX);
int guesses = player.playGame (console, answer);
totalGames++;
totalGuesses += guesses;
Game.java Ex
bestGame= Math.min(bestGame, guesses);
System.out.println("Play again? (y/n)");
String playAgain = console.next( ).toLowerCase();
if (!playAgain.startsWith("y")) {
}
break;
+
printOverallStatistics (totalGames, totalGuesses, bestGame);
private void printOverallStatistics(int totalGames, int totalGuesses, int bestGame) {
Generate Ctrl I
System.out.println("Overall results:");
System.out.println("Total games
+ totalGames);
System.out.println("Total guesses = " + totalGuesses);
System.out.printf("Guesses/game = %.1f\n", (double) totalGuesses / totalGames);
System.out.println("Best game
bestGame);
Ln 38, Col 1
■ Stop
• Spaces: 2 History O
> Console X
Run
It's higher.
Your guess? 50
It's higher.
Your guess? 60
It's higher.
Your guess? 07
It's higher.
Your guess? 80
It's lower.
Your guess? 76
It's lower.
Your guess? 65
It's lower.
Your guess? 60
It's higher.
Your guess? 61
It's higher.
Your guess? 62
It's higher.
Your guess? 63
You got it right in 11 guesses!
Play again? (y/n)
No
Overall results:
Total games
= 1
Total guesses = 11
Guesses/game = 11.0
Best game
= 11
Run
Shell
I'm thinking of a number between 1 and 100...
Your guess? 2
It's higher.
Your guess? 3
It's higher.
Your guess? 4
It's higher.
Your guess? 5
It's higher.
Your guess? 6
It's higher.
Your guess? 7
It's higher.
Your guess? 8
It's higher.
Your guess? 30
It's higher.
Your guess? 40
It's higher.
Your guess? 50
It's lower.
Your guess?
Transcribed Image Text:D> Search ✓ Files Ⓒ settings classpath Main.java 4 Player.java results.csv project 04 - Guessing Game.pdf Game.java GameManager.java Packager files target pom.xml ✓ Tools Recent All 1000000 AI Authentication Chat Q Code Search > Console Database DI Debugger Docs | 04 - Guessing Game-ShriIyer Extensions -Git Packages PostgreSQL Join Replit Core Ctrl Shift F X Main.java Game.java 1 import java.util. Random; 2 import java.util.Scanner; 3 5 6 7 8 9v 10 11 12 13 14 v 15 6 7 18 19 20122 3 24 25 26 27 28 29 01234355劲894042 3 4 45 46 x 16 17 36 37 0 38 | 43 44 CAI public class Game { v public static final int MAX = 100; private final Scanner console; private final Random random; J.04 - Guessing Game.pdf x Player.java x } public Game(Scanner console, Random random) { this.console = console; this.random = random; public void startGame() { int totalGames = 0; int totalGuesses = 0; } } () Java int bestGame = Integer.MAX_VALUE; while (true) { } Player player = new Player(); int answer = 1 + random.nextInt(MAX); int guesses = player.playGame (console, answer); totalGames++; totalGuesses += guesses; Game.java Ex bestGame= Math.min(bestGame, guesses); System.out.println("Play again? (y/n)"); String playAgain = console.next( ).toLowerCase(); if (!playAgain.startsWith("y")) { } break; + printOverallStatistics (totalGames, totalGuesses, bestGame); private void printOverallStatistics(int totalGames, int totalGuesses, int bestGame) { Generate Ctrl I System.out.println("Overall results:"); System.out.println("Total games + totalGames); System.out.println("Total guesses = " + totalGuesses); System.out.printf("Guesses/game = %.1f\n", (double) totalGuesses / totalGames); System.out.println("Best game bestGame); Ln 38, Col 1 ■ Stop • Spaces: 2 History O > Console X Run It's higher. Your guess? 50 It's higher. Your guess? 60 It's higher. Your guess? 07 It's higher. Your guess? 80 It's lower. Your guess? 76 It's lower. Your guess? 65 It's lower. Your guess? 60 It's higher. Your guess? 61 It's higher. Your guess? 62 It's higher. Your guess? 63 You got it right in 11 guesses! Play again? (y/n) No Overall results: Total games = 1 Total guesses = 11 Guesses/game = 11.0 Best game = 11 Run Shell I'm thinking of a number between 1 and 100... Your guess? 2 It's higher. Your guess? 3 It's higher. Your guess? 4 It's higher. Your guess? 5 It's higher. Your guess? 6 It's higher. Your guess? 7 It's higher. Your guess? 8 It's higher. Your guess? 30 It's higher. Your guess? 40 It's higher. Your guess? 50 It's lower. Your guess?
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Math class and its different methods
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
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