public class Lock {
private int code=0;
private int pass;
private int alarm=0;;
/**
* @param args
*/
public Lock (int key)
{
this.pass=1;
this.code=key;
this.alarm=0;
}
public void close ()
{
this.pass=0;
}
public boolean isOpen()
{
if (pass==1);
{
System.out.println("True");
return true;
}
}
public boolean open (int key)
{
if (this.code==key)
{
System.out.println("True");
return true;
}
if (code!=key && pass==0)
{
alarm++;
System.out.println("alarm");
}
return false;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Lock f = new Lock(1333);
f.isOpen();
f.open(3);
f.open(5);
f.open(6);
f.close();
f.open(3);
f.open(5);
f.open(6);
f.open(1333);
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.