Results 1 to 2 of 2
  1. #1
    Hector is offline Member
    Join Date
    Feb 2014
    Location
    Seattle, Washington
    Posts
    9
    Rep Power
    0

    Default Driver for lockable coin class

    im having trouble creating a driver for the following program. im new to creating interfaces and i need to make this work. i jus need a push in the right direction, so any help is appreciated. thanks in advance

    Lockable interface:
    Java Code:
    public interface Lockable {
    	  boolean locked();
    	  public void setKey(int key);
    	  public void lock(int key);
    	  public void unlock(int key);
    }
    Coin class:
    Java Code:
    public class Coin implements Lockable {
    	 private boolean locked;     
    	 private int key ;       
    	 public Coin(){         
    		 locked = false;        
    		 key = 0 ;     
    		 }          
    	 public boolean locked(){         
    		 return locked ;     
    		 }       
    	 public void setKey(int key){         
    		 this.key = key ;     
    		 }       
    	 public void unlock(int key){         
    		 if(this.key == key){            
    			 locked = false ;         
    		 }    
    		 }       
    	 public void lock(int key){         
    		 if(this.key == key){             
    			 locked = true ;         
    		 }        
    		 }       
    	 public void messageReturn(){        
    		 if(locked == false) 
    			System.out.println("unlocked") ;
      }
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default Re: Driver for lockable coin class

    Start with a main() method that creates an instance of Coin and calls the functions on that instance. Do the functions do what you expect them to do?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Lockable interface and driver
    By Hector in forum Advanced Java
    Replies: 1
    Last Post: 02-18-2014, 07:08 PM
  2. Driver Class Program Help
    By smarty84handsome in forum New To Java
    Replies: 13
    Last Post: 12-08-2013, 11:04 AM
  3. Replies: 0
    Last Post: 03-03-2012, 02:01 AM
  4. Replies: 6
    Last Post: 02-08-2012, 07:42 PM
  5. using a driver with a class
    By vendetta in forum New To Java
    Replies: 7
    Last Post: 01-11-2010, 07:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •