- He makes a private variable (Type string) called girlName; Public variables can be used by ANY class, but private variables can only be used by the class they're in (In this case, only things INSIDE tuna.java can use girlName)
- He then makes a method called setName - Its purpose is to give a value to the variable girlName - In the perameters, he defines a new variable called name - He does this in the perameters so it can be set simply by calling the "setName" method somewhere else, and filling the arguments in. In the method he makes it so girlName is the same as whatever words are held in the variable name.
- Makes a return method for the variable girlName - He puts string because this method is going to return (send the user) a string (The string that's being held in girlName) - 'return girlName' will just print out whatever's being held in girlName when this 'getName' method is called on.
- Creates a method for the final output, he calls it saying. It's only purpose is to output the 'final statement'. He uses a printf, which is just a formatted print. %s tells the print that the variable it's going to be recieving its data from will be a string. The he just puts the name of the string in there so it knows which one to retrieve the info from; getName. So basically it'll print out "Your first gf was" and then (aka print) will return girlName
- He goes back to the class called apples, and it's got a scanner to take input and an object to 'connect' apples.java to tuna.java
- Obviously he prints out a line that asks for your input - Creates a variable (He calls it temporary, but really it exists forever, but it won't be used except to take user's input) - sets it equal to whatever user types in.
- He uses his object for the other class (tuna) and 'asks' the object to call on the method inside tuna, which is called setName - In the arguments, he types in temp - Basically, whatever string comes into temp will get sent to setName (Remember that setName's purpose was to give a value to the variable girlName) (So temp gets your input, throws it over to 'name', and then name gives it to girlName)
- Then he uses the tuna object again, this time to get whatever the method 'saying' does (In this case it prints out that line of text, plus returns girlName (Does that because it calls getName, which returns girlName))
I hope that helps you, I tried to go into as much detail as possible on EVERYTHING, because I don't know what you did and didn't understand :P
That's it for the 16th, I'll write one for the 17th now. Stand by
- A constructor will allow you to assign a value to a variable as soon as your object is created.
- Basically, he creates a constructor - The method's name has to be the same as the class - The constructor's purpose is to pass a value (this value would be given FROM the tuna object in the apples class) into the string variable called girlName.
- The constructor is again, going to be recieving a string value, so in the perameters he sets it to a string and calls it 'name'. (Whenever the tuna object is used, it will take whatever the object's arguments are and substitute it into the string variable called 'name', which was just created in the statement "public tuna (String name)")
- The constructor is going to send whatever value arrives in 'name' to the variable girlName.
- He modifies the tuna object and adds "kelsey" to the arguments. The argument will arrive in 'name', and then be sent to girlName because that's what the constructor is there to do.
- Now whenever the tuna object is called, it will again run 'saying' which just prints out "your first gf was %s " and then returns girlName.
- He makes a second object of tuna to demonstrate that the objects are seperate from each other; whatever goes into the first one will not affect or be affected by the second one. Both have their own arguments, and when those arguments are sent to the class 'tuna', they're handled seperately (but in the exact same way)
And that's what I got for 17. Hope that helps too, ask more questions if you have any or I wasn't clear enough :D