A
A
Ashot2021-12-09 11:49:12
Java
Ashot, 2021-12-09 11:49:12

How to initialize fields passed to constructor using setters in Java?

Dear Sirs, Greetings to all. I solve the problem, according to the conditions, you need to create 3 classes, GuessNumber, Player and GuessNumberTest with the main () method.
In the Player class, we describe the players (one instance of the class corresponds to one player).
The GuessNumberTest class is responsible for creating objects, initializing them, and starting the game. Contains the main method.
let's leave the GuessNumber class for now.
Condition:

The Player class must consist of:
a constructor that takes the name of the player
String name - the name of the player (one)
int number - the number of
getters / setters entered by the user (if getters are not used, then they can be omitted)


Link to the code in pastebin (raw)

Only in this version I managed to initialize the field passed to the constructor in the class with the Test method, and then only string name without a setter, but I need both string name and int num through setters. Literals must be entered using a scanner.

I will be grateful for any help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2021-12-09
@xez

The player should not have any scanner.
The setter should only set values ​​(exactly in your case)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question