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.javax 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 Search ✓ Files Packager files O target .settings .classpath .project 04 - Guessing Game.pdf Game.java GameManager.java Main.java Player.java results.csv All ✓ Tools 31 pom.xml Recent AI 04 - Guessing Game-ShriIyer ✓ Authentication D Chat Q Code Search > Console Database ▷ Debugger 19 4 Join Replit Core ⠀ Ctrl Shift F Main.java Main.java 47 48 49 50 51 52 53 v 54 55 56 57 58 正 59 60 x */ import java.util.Scanner; import java.util. Random; 61 0 } 62 } 63 64 04 - Guessing Game.pdf x Player.java x public class Main { public static void main(String[] args) { Scanner console = new Scanner(System.in); Random random = new Random(); X CAI) Java Game game = new Game(console, random); game.startGame(); console.close(); Game.java x Stop + Ln 62, Col 2 • Spaces: 2 History Ⓒ > Console û x Run Its myner. 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. Shell Overall results: Total games = 1 Total guesses = 11 Guesses/game Best game Run 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 x + 11.0 = 11 90% | 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 + Reset ✓ Resubmit A 33m on 12:11:29 3m on 12:48:27
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();
}
}
Unlock instant AI solutions
Tap the button
to generate a solution