That entitles you to refer the question back because whoever set it doesn't know what a default constructor is.S. Eckstrom wrote:. . . Initialized in default constructor . . . Default constructor . . . Parameterized constructor . . . .
Eclipse does in fact give the correct solution to that warning if you find the appropriate dropdown list. Hover your mouse on the yellow triangle and choose the option @SuppressWarnings("resource") from the list. This is the only situation where you are allowed to keep a Scanner or anything like that open for the duration of the program. And one of the efw instances where you may use @SuppressWarnings. Only use it when you are absolutely sure the code is correct.S. Eckstrom wrote:Eclipse only gives me one warning: Resource leak: 'sc' is never closed. I'm not finding the problem to fix this. . . .
Carey Brown wrote:Not related to your current issue but you should only ever have ONE INSTANCE of a Scanner created using System.in in your PROJECT. The best way to achieve this is by having (only) one of your classes contain a public constant for this that can be accessed from any class in the project. Example:
Now if you need keyboard input use KEYBOARD as the instance name, as in
Other classes would require something a bit more verbose:
Also, never, never, close KEYBOARD regardless of what Eclipse's warnings tell you.
Carey Brown wrote:
Carey Brown wrote:Not related to your current issue but you should only ever have ONE INSTANCE of a Scanner created using System.in in your PROJECT. The best way to achieve this is by having (only) one of your classes contain a public constant for this that can be accessed from any class in the project. Example:
Now if you need keyboard input use KEYBOARD as the instance name, as in
Other classes would require something a bit more verbose:
Also, never, never, close KEYBOARD regardless of what Eclipse's warnings tell you.
S. Eckstrom wrote:... when I run the Shopping Cart Class. When I run the Shopping Cart Manager Class, it stops at Enter Customer's Name:
This is the errors from the ZyBooks: