Hi - So currently I have code in java (in replit.com) that writes to a player_results.csv file I've created based the results of a game played in the console, with a random ID, the player's name, total games, total guesses, and best game. It's basically a guessing game where, using a scanner, the program asks for the user's name, "thinks" of a number, and you have to guess it based on whether the program says the number you guessed is higher or lower than the number it's thinking. It asks to play the game again, and if you say something that starts with "y" or "Y" (Example: Yeehaw or yes or Yass or even Yeet or something) then it continues, otherwise it stops the game and the results are printed out(total games, total guesses, etc. you'll see in my code). If you see one of the files I have attached, it has main.java's code along with the output of the console in the screenshot. After I played the game (twice) as you see in the console, the output in player_results.csv was the following: 4ee9f207-6840-4d3c-bd3d-48c810282f70,Sid,1,5,5 a5e157d1-9bff-4d63-b814-6d8cabf5423a,Shri,2,11,5 I have also attached Game.java, and Player.java looks like this: import java.util.Scanner; import java.util.UUID; public class Player { private UUID id; private String name; private int totalGames; private int totalGuesses; private int bestGame; public Player() { this.id = UUID.randomUUID(); this.name = null; this.totalGames = 0; this.totalGuesses = 0; this.bestGame = Integer.MAX_VALUE; } public UUID getId() { return id; } 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; } public int playGame(Scanner console, int answer) { System.out.println("I'm thinking of a number between 1 and " + Game.MAX + "..."); int guesses = 0;
Hi - So currently I have code in java (in replit.com) that writes to a player_results.csv file I've created based the results of a game played in the console, with a random ID, the player's name, total games, total guesses, and best game. It's basically a guessing game where, using a scanner, the program asks for the user's name, "thinks" of a number, and you have to guess it based on whether the program says the number you guessed is higher or lower than the number it's thinking. It asks to play the game again, and if you say something that starts with "y" or "Y" (Example: Yeehaw or yes or Yass or even Yeet or something) then it continues, otherwise it stops the game and the results are printed out(total games, total guesses, etc. you'll see in my code). If you see one of the files I have attached, it has main.java's code along with the output of the console in the screenshot. After I played the game (twice) as you see in the console, the output in player_results.csv was the following:
4ee9f207-6840-4d3c-bd3d-48c810282f70,Sid,1,5,5
a5e157d1-9bff-4d63-b814-6d8cabf5423a,Shri,2,11,5
I have also attached Game.java, and Player.java looks like this:
import java.util.Scanner;
import java.util.UUID;
public class Player {
private UUID id;
private String name;
private int totalGames;
private int totalGuesses;
private int bestGame;
public Player() {
this.id = UUID.randomUUID();
this.name = null;
this.totalGames = 0;
this.totalGuesses = 0;
this.bestGame = Integer.MAX_VALUE;
}
public UUID getId() {
return id;
}
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;
}
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;
}
}
Now I want help with this: Please add code to read from my csv file. Convert those strings from the csv file into a player object that you can use to resume a series of games.
Step by step
Solved in 3 steps with 1 images