As I said, I added a main() method that created an instance of StudentLocker, like this:
public class StudentLocker
{
StudentLocker()
{
Locker mickey = new Locker( "Mickey" );
mickey.setLocker( 100 );
//mickey.combo = {28, 17, 39};
mickey.setBooks( 3 );
Locker donald = new Locker( "Donald" );
donald.setLocker( 275 );
//donald.combo = "35 16 27";
donald.setBooks( 0 );
System.out.println( mickey.getName() );
System.out.println( donald.getName() );
}
public static void main( String[] args )
{
new StudentLocker();
}
}
The StudentLocker() constructor prints the names.
--- Update ---
I just saw the rest of your latest post . . . must have gotten distracted.
OOP is using objects to represent, describe, and act on 'things'. Parallel arrays are a primitive form of a database that cannot efficiently be used as objects.
As for your latest code and use of CombinationLock, not quite. Incorporating the CombinationLock class into the Locker class will look something like this:
Notes: the instance variable combo is of type CombinationLock, the getCombo() and setCombo() methods deal with CombinationLock objects, not ints. The specifics of the CombinationLock class (constructors, etc.) will likely change some of the placeholder combo methods I've included.
// a class to represent a locker
public class Locker
{
// instance variables
String name;
int lockerNumber;
CombinationLock combo;
int books;
// default constructor
public Locker()
{
lockerNumber = 0;
combo = new CombinationLock(); // this default constructor may not exist
books = 0;
name = "";
} // end default constructor
// a constructor that sets the locker owner's name
public Locker( String name )
{
// call the default constructo to initialize instance variables
this();
this.name = name;
} // end constructor
public CombinationLock getCombo()
{
return combo;
}
public void setCombo( CombinationLock combo )
{
this.combo = combo;
}
// etc . . .