18 April 2005 - java_dev (original) (raw)

Java developers

April 18th, 2005

| | 01:18 am - ex_bluelili I need help understanding where to start with the following study question. If you could give me some tips b/c the book is very vague and I am lost...Thanks_Design a Java interface called Lockable that includes the following methods: setKey, lock, unlock, and locked. the setKey, lock, and unlock methods take an integer parameter that represents the key. The setKey method establishes the key. The lock and unlock methods lock and unlock the object but only if the key passed in is correct. The locked method returns a boolean that indicates whether or not the object is locked. A Lockable object represents an object whose regular methods are protected: if the object is locked, the methods cannot be invoked; if it is unlocked they can be invoked. Redesign and implement a version of the Coin class so that it is Lockable. Submit hard copy of a Rational Rose UML class diagram, the redesigned Coin class and test driver class._ | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

10:12 am - wonkyear - newb question: custom exceptions Hey there. I'm doing a project in Java for one of my comp sci classes, and one of the requirements is to throw and handle a custom exception. I could do this with a predefined exception, but I'm not sure how to define my own. Could anyone give a quick example of syntax/usage for custom exceptions?I know I could find this on my own, but I'm posting the question here in hopes of saving research time.If it affects the answer, the exception is to be thrown if the user attempts to insert a duplicate integer into a binary search tree object. In my implementation, the tree class will throw the exception, and the main method will handle it.Thanks in advance for any help.