Quote:
import java.util.*;
public class LockTester
{
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
}
}
Quote:
public class Lock
{
//instance variables
char word;
char password;
boolean status;
public Lock(char x ,char y ,char z )
{
password = (char) (x + y + z);
}
public void set(char x)
{
word = (char)(x);
.
}
public void pull()
{
if (word == password)
status = true;
}
public boolean isOpen()
{
if (status = true)
{System.out.println ("true") ;}
else
{System.out.println ("false") ;}
return status;
}
public void close()
{
status = false ;
}
}
/////////////////////// the out put is always true when the word is not even equal to password, how do i make it prints false when the word is not equal to password????///////////////////
[/quote]