Quote:
/**
This is class tests the Lock objects.
*/
import java.util.* ;
public class Main
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in) ;
Lock lock = new Lock('C', 'A', 'K') ;
lock.set('C') ; // first turn
System.out.print("The lock will open? ") ;
lock.pull() ; // try
System.out.println(lock.isOpen()) ;
System.out.println("Expected: false") ; // only one turn
lock.set('A') ; // second turn
System.out.print("The lock will open? ") ;
lock.pull() ; // try
System.out.println(lock.isOpen()) ;
System.out.println("Expected: false") ; // only two turns
lock.set('K') ; // third turn
System.out.print("The lock is open? ") ;
System.out.println(lock.isOpen()) ;
System.out.println("Expected: false") ; // haven't pulled yet
System.out.print("The lock will open? ") ;
lock.pull() ; // try
System.out.println(lock.isOpen()) ;
System.out.println("Expected: true") ; // correct combination
lock.set('L') ; // turning dial while lock is open
System.out.print("The lock is open? ") ;
System.out.println(lock.isOpen()) ;
System.out.println("Expected: true") ; // it is still open
lock.close() ; // closing the lock resets dials
System.out.print("The lock is open? ") ;
System.out.println(lock.isOpen()) ;
System.out.println("Expected: false") ; // we just closed it
System.out.println("Give the combination of a new lock as a 3 letter string") ;
String combo = scanner.next() ;
System.out.println("Give the tolerance of this lock as an int") ;
int tolerance = scanner.nextInt() ;
Lock lock = new Lock(combo.charAt(0), combo.charAt(1),
combo.charAt(2), tolerance) ;
System.out.println("Give a 5 letter string which represents an effort to open the lock.") ;
combo = scanner.next() ;
lock.set(combo.charAt(0)) ;
lock.set(combo.charAt(1)) ;
lock.set(combo.charAt(2)) ;
lock.set(combo.charAt(3)) ;
lock.set(combo.charAt(4)) ;
System.out.print("The lock will open? ") ;
lock.pull() ; // try
System.out.println(lock.isOpen()) ;
}
}
this is the method
Quote:
public class Lock
{
private string letter1,letter2,letter3 ;
public Lock (string letter1,letter2,letter3)
{
this.letter1 = letter1;
this.letter2 = letter2;
this.letter3 = letter3;
}
public string set()
{
}
public string pull()
{
if (letter1 = letter2
}
public boolean isOpen()
{
}
public string close()
{
}
}
Anyone can give me a hand???[/quote]