JAVA OOP: help with assigning values to object | Sololearn: Learn to code for FREE!


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

12/4/2021 2:10:52 AM


9 Answers

New Answer


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.


Luz Setter and getter are methods which can use anywhere through the object of Class Libro.


A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ thank you


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()


I try this input format, separated by enter 134685997 Effective Java Joshua Bloch 416


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


zemiak oh thank you! I didn't noticed that


zemiak I changed it to nextLine() and now it's throwing an error, do you know what's wrong??