Let's move on to the basics: "Accessor" and "Mutator" are just fancy names for getters and setters. The getter, "Accessor", returns a class variable or its value. Setter, "Mutator", sets the pointer to a class variable or its value.
So, first you need to set up a class with some variables to get / set:
public class IDCard { private String mName; private String mFileName; private int mID; }
But oh no! If you instantiate this class, the default values ββfor these variables will be meaningless. BTW "instance" is a fancy word for doing:
IDCard test = new IDCard();
So - configure the default constructor, this is the method called when the class is "instantiated".
public IDCard() { mName = ""; mFileName = ""; mID = -1; }
But what if we know the values ββthat we want to give to our variables? Therefore, let's create another constructor that takes parameters:
public IDCard(String name, int ID, String filename) { mName = name; mID = ID; mFileName = filename; }
Wow is good. But stupid. Because we have no way to access (= read) the values ββof our variables. So, add a getter, and while we are on it, add a setter:
public String getName() { return mName; } public void setName( String name ) { mName = name; }
Nice. Now we can access mName . Add the rest of the accessories and mutators, and you are now a certified Java newbie. Good luck.