Hi I am very new to Java and I'm not even sure If I am asking a valid question. But I will try to describe my it as best as I can.
I am trying to save my data permanently but it keep restarting whenever I re-run the program or when I delete stuff in my main method. For example, consider the following code:
public class Player {
private int wins;
public Player {
wins = 0;
}
public getWins() {
return wins;
}
public addWins() {
this.win++;
}
}
public class Game {
public static void main(String[] args) {
Player john = new Player();
Player jayson = new Player();
coinFlipMatch(john, jayson);
}
public void coinFlipMatch(Player p1, Player p2) {
int coinFlip = (int) (Math.random() * 2 + 1);
if (coinFlip == 0) {
p1.addWins();
} else {
p2.addWins();
}
}
}
So basically, I want player's wins to go up whenever they win a game of coin flip. But I can only do so much because I actually want the number of wins to stay there permanently. Of course, the value for 'int wins' will not stay if I re-run the program or if I delete what is on the main method. But that's exactly why I am here is because of that. I am wondering if such an idea is even possible? How do I make it so that 'int wins' will always be there and not change unless I add more to it?
thank you for reading this rather long (and maybe stupid) question. I would appreciate any help you guys can offer!