Jon Cacuza

Greenhorn
+ Follow
since Sep 28, 2018
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jon Cacuza

Does anyone know if there any study guides out for this exam or in the works?

Carey Brown wrote:

Jon Cacuza wrote:Your object should have its own members, for example.
However, These names should be more descriptive so that other programmers reading your code can follow along. For this example, I'll use m_Input.


Java conventions say that an underscore (_) should not be used in naming variables, methods, or classes. Use camel case instead. The one exception to this rule are constants whose names should be in all upper case with underscores separating name components. Additionally, the use of underscores or even something like "m_" as a prefix to indicate that it is a member variable is frowned upon.



I apologize, at my job we use m_ to define members of the object- it helps in big projects. I will stick to java's naming convention here on the forums though. ;)
8 months ago
Your object should have its own members, for example.



However, These names should be more descriptive so that other programmers reading your code can follow along. For this example, I'll use m_Input.



m_Input is now a member, it is however private. So only methods that are inside of the Player Object can assign a value to m_Input or manipulate m_Input's value.

Other methods that are not inside of the Player Object can't access, or mutate, m_Input because they cannot see it- this is because m_Input is set to private.
We can allow them to access m_Input by creating public methods to set m_Input up with a value or to get the value that is stored in m_Input (which is what you were doing).




Take note of the "String e" inside of the arguments of the function. You can change the variable "e" to whatever you want, and its scope is only defined inside of the setInput function. "e" will lose its value once this function ends. So we store its value to the member's object m_Input so this way we can keep it.

Also, keep in mind that the value stored inside of the member m_Input can only be seen by methods that are inside of the Player Object, you will have to code a method to allow others to see the value inside of m_Input.



Please note the argument has nothing inside of the argument parenthesis. The getInput method only returns the value of the Input whenever it is called.

Since your program has a static method, you will have to create an instance of your Player object inside of it, which you did.



Whenever you call "new" on an object:
In memory, the computer allocates enough space to store all of the Object's members and their values for that instance of your object. In this class, our instance of the Player Object is called player.
This means, in memory, player, has its own member m_Input that we can set a value to and view its value using our get and set methods.

I was informed by staff to not give you a solution and have you work on it.
I hope this helps point you in the right direction.

Good luck
8 months ago