public class Lock{
// ADD ATTRIBUTES HERE
/** Create a lock for the specified box
* <p>
* The lock must be initially locked (closed) when created.
* The lock must be given a UNIQUE ID value when created.
*
* @param box is a Box that will have this lock to keep is shut.
*/
public Lock(Box box){}
/** Retrieve the key for this lock.
* <p>
* This method can be called multiple times but is only allowed to
* return its mathcing key the first time it is called. Every time
* after the mehtod will return null.
*
* @return the key that matches this lock (i.e., the key that can unlock it)
* if it is the first time called. Returns null otherwise.
*/
public Key getKey(){return null;}
/** Check if this lock is locked or not.
*
* @return true if this lock is locked and false otherwise.
*/
public boolean isLocked(){ return false;}
/** Locks this lock (regardless if it was already locked or not). */
public void lock(){}
/** Unlocks the lock if the input key matches the lock.
* <p>
* If this lock is already unlocked this method will return true and
* do nothing else.
* If this lock is locked and input key matches this lock, then it
* unlocks the lock and returns true.
* If this lock is locked and the input key does not match this lock,
* then returns false and does nothing else.
*
* @param key is key.
* @return true if the lock was already unlocked OR if the key matches the
* lock. Returns false otherwise.
*/
public boolean unlock(Key key){return false;}
/** retrieves the ID of the lock
*
* @return the ID of this lock.
*/
public int getID(){return -1;}
}class Lock {
// ADD ATTRIBUTES HERE
private Box box;
private int id;
private static HashSet<Integer> ids;
private boolean locked;
private Key key;
private boolean keyReturned;
/**
* Create a lock for the specified box
* <p>
* The lock must be initially locked (closed) when created. The lock must be
* given a UNIQUE ID value when created.
*
* @param box is a Box that will have this lock to keep is shut.
*/
public Lock(Box box) {
this.box = box;
this.id = (int) (Math.random() * 10000);
while (ids.contains(this.id)) {
this.id = (int) (Math.random() * 10000);
}
ids.add(this.id);
this.locked = true;
this.key = new Key(this);
this.keyReturned = false;
}
/**
* Retrieve the key for this lock.
* <p>
* This method can be called multiple times but is only allowed to return its
* mathcing key the first time it is called. Every time after the mehtod will
* return null.
*
* @return the key that matches this lock (i.e., the key that can unlock it) if
* it is the first time called. Returns null otherwise.
*/
public Key getKey() {
if(!keyReturned) {
keyReturned = true;
return key;
}
return null;
}
/**
* Check if this lock is locked or not.
*
* @return true if this lock is locked and false otherwise.
*/
public boolean isLocked() {
return locked;
}
/** Locks this lock (regardless if it was already locked or not). */
public void lock() {
locked = true;
}
/**
* Unlocks the lock if the input key matches the lock.
* <p>
* If this lock is already unlocked this method will return true and do nothing
* else. If this lock is locked and input key matches this lock, then it unlocks
* the lock and returns true. If this lock is locked and the input key does not
* match this lock, then returns false and does nothing else.
*
* @param key is key.
* @return true if the lock was already unlocked OR if the key matches the lock.
* Returns false otherwise.
*/
public boolean unlock(Key key) {
if(key.lockID() == id) {
locked = false;
}
return !locked;
}
/**
* retrieves the ID of the lock
*
* @return the ID of this lock.
*/
public int getID() {
return id;
}
}
please upvote. Thanks!
public class Lock{ // ADD ATTRIBUTES HERE /** Create a lock for the specified box *...
In this problem, you will complete several classes involving boxes, locks, keys and secrets. Follow the specifications in the starter files for the classes. You can run the javadoc program to generate the API (see Tutorial 2) for the classes. A box has a secret inside it (and maybe a key!) and can be locked. In order to open a box, you need the right key to unlock the lock. Secrets.java will be a program that takes an array of...
java problem
here is the combination class
class Combination
{
int first,second,third, fourth;
public Combination(int first, int second, int
third,int fourth)
{
this.first=first;
this.second=second;
this.third=third;
this.fourth=fourth;
}
public boolean equals(Combination other)
{
if ((this.first==other.first)
&& (this.second==other.second) &&
(this.third==other.third) &&
(this.fourth==other.fourth))
return
true;
else
return
false;
}
public String toString()
{
...
public class Node { public int data; public Node next; public Node(int d, Node n) { data = d; next = n; } } Please complete the following 5 tasks. 1./** * * @param start * @param low * @param high * @return the sum of all values starting at start that are * in the range [low...high] (inclusive on both sides). 0 if none. * start -> 10 -> 70 -> 20 -> 80 -> null * low =...
Implement the missing methods in java! Thanks! import java.util.Iterator; import java.util.NoSuchElementException; public class HashTableOpenAddressing<K, V> implements DictionaryInterface<K, V> { private int numEntries; private static final int DEFAULT_CAPACITY = 5; private static final int MAX_CAPACITY = 10000; private TableEntry<K, V>[] table; private double loadFactor; private static final double DEFAULT_LOAD_FACTOR = 0.75; public HashTableOpenAddressing() { this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR); } public HashTableOpenAddressing(int initialCapacity, double loadFactorIn) { numEntries = 0; if (loadFactorIn <= 0 || initialCapacity <= 0) { throw new IllegalArgumentException("Initial capacity and load...
Create a method based program to find if a number is prime and then print all the prime numbers from 1 through 500 Method Name: isPrime(int num) and returns a boolean Use for loop to capture all the prime numbers (1 through 500) Create a file to add the list of prime numbers Working Files: public class IsPrimeMethod { public static void main(String[] args) { String input; // To hold keyboard input String message; // Message...
In Java. How would this method look?
LinkedBinaryTree.java
import java.util.Iterator;
public class LinkedBinaryTree implements BinaryTreeADT {
private BinaryTreeNode root;
/**
* Creates an empty binary tree.
*/
public LinkedBinaryTree() {
root = null;
}
/**
* Creates a binary tree from an existing root.
*/
public LinkedBinaryTree(BinaryTreeNode root) {
this.root = root;
}
/**
* Creates a binary tree with the specified element...
Java Quadratic Probing Hash table HELP! Complete the Map and Entry class provided in Map.java. Create a tester/driver class to show the Map class is working as intended. Methods/Constructor correctly completed (2pt) This is the Map class methods Map(), put(key, value), get(key), isEmpty(), makeEmpty() Private class correctly completed (2pt) This is the Entry class methods Add the methods that are required for this to work correctly when stored in the QuadraticProbingHashTable Tester class (1pt) Show the methods of the Map...
In this problem, you will complete several classes involving boxes, locks, keys and secrets. Follow the specifications in the starter files for the classes. You can run the javadoc program to generate the API (see Tutorial 2) for the classes. A box has a secret inside it (and maybe a key!) and can be locked. In order to open a box, you need the right key to unlock the lock. Secrets.java will be a program that takes an array of...
Here is the indexOf method that I wrote: public static int indexOf(char[] arr, char ch) { if(arr == null || arr.length == 0) { return -1; } for (int i = 0; i < arr.length; i++) { if(arr[i] == ch) { return i; } } return -1; ...
5. There are several getter methods for class Node: public Integer getIDO //PRE:- // POST: Returns node ID public Integer getEO /7PRE //POST: Returns value of e in this node's function f) public Integer getkO /PRE: //POST: Returns value of K in this node's function f) public Boolean transmittedMessage) 7PRE:- /POST: Returns true if this node has transmitted a message, false otherwise public String getMsg) /PRE: // POST: Returns the current received (non-augmented) message, null if no received message
5....