DOC PREVIEW
UMD CMSC 433 - Quiz Answer

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

433 Quiz Answer, January 30th1. (50 points) Write appropriate operator=, copy constructor, and destructor methods for the followingclass.class SimpleArray {int length;int * data;public:SimpleArray(int len) {length = len;data = new int[len];}SimpleArray(const SimpleArray & that) {length = that.length;data = new int[length];for(int i = 0; i < length; i++)data[i] = that.data[i];}SimpleArray& operator=(const SimpleArray & that) {if (this == &that) return *this;delete [] data;length = that.length;data = new int[length];for(int i = 0; i < length; i++)data[i] = that.data[i];return *this;}~SimpleArray() {delete [] data;}int get(int idx) const {return data[idx];}void set(int idx, int val) {data[idx] = val;}int getLength() const {return length;}};12. (50 points) Java synchronizationDesign a simple one-place buffer for use a multithreaded Java applications. The buffer can hold oneobject; when the buffer is allocated, it is empty. If a thread tries to take from an empty buffer, thethread blocks until it can return something. If a thread tries to put into a full buffer, the thread blocksuntil the buffer has been emptied and the request can be fulfilled. Put your answer on the back of thepage.Your class should implement the following interface:package cmsc433;public interface OnePlaceBuffer {public Object take() throws InterruptedException;public void put(Object o) throws InterruptedException;}In my solution, I’m going to assume that take() should never return null, and that doing put(null) isa no-op.public class Buf implements cmsc433.OnePlaceBuffer {private Object data;public synchronized Object take() throws InterruptedException {while (data == null)wait();Object tmp = data;data = null;notifyAll();return tmp;}public synchronized void put(Object o) throws InterruptedException {while (data != null)wait();data =


View Full Document

UMD CMSC 433 - Quiz Answer

Documents in this Course
Trace 1

Trace 1

62 pages

Reflection

Reflection

137 pages

Testing

Testing

25 pages

Paradigms

Paradigms

10 pages

Testing

Testing

17 pages

Java RMI

Java RMI

17 pages

Java RMI

Java RMI

17 pages

Java RMI

Java RMI

17 pages

Trace 1

Trace 1

46 pages

Jini

Jini

4 pages

Final

Final

15 pages

Java RMI

Java RMI

13 pages

Testing

Testing

16 pages

Load more
Download Quiz Answer
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Quiz Answer and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Quiz Answer 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?