+ 1
JAVA OOP: help with assigning values to object
hi (I'm new in Java) I'm missing something in the code and I don't know what it is. I'm trying to read an input and then assign it to an attribute, but I have to use a method to read the input, it can't be in the main. Can anyone tell me what's wrong? Thanks https://code.sololearn.com/cn826HVA0gCm/?ref=app
8 Answers
+ 2
Luz
Your scanner object is a local variable so you cannot access globally.
And also no need to make two scanner objects. You can do with only one scanner object.
https://code.sololearn.com/c6rHLQoJi4OT/?ref=app
+ 3
Luz
Setter and getter are methods which can use anywhere through the object of Class Libro.
+ 1
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ thank you
+ 1
it is OK, as you do it in your actual code
public void CargarLibro() {
System.out.println("Ingrese ISBN");
setISBN (leer.nextInt());
Other problem is that next() can't read title or author where are more words with spaces
because space is default separator used for next()
+ 1
I try this input format, separated by enter
134685997
Effective Java
Joshua Bloch
416
0
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ oh okay so I was missing the
l1.setISBN(leer.nextInt());
do you know if it's ok to put it inside the method?
Because in the assignment it says to create a method that can be used multiple times
0
zemiak oh thank you! I didn't noticed that
0
zemiak I changed it to nextLine() and now it's throwing an error, do you know what's wrong??