The Artima Developer Community
Sponsored Link

Java Answers Forum
Thread, Vector, Inheritance Problem

1 reply on 1 page. Most recent reply: Jul 19, 2005 3:31 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
ogeela

Posts: 5
Nickname: oggy
Registered: Jul, 2005

Thread, Vector, Inheritance Problem Posted: Jul 19, 2005 2:41 AM
Reply to this message Reply
Advertisement
Class Inheritance, Thread, Vector, Exception Handling

Two arrays of integers as shown below are to be merged and the result of this merge is to appear in vector as shown:

Array 1
7 11 22 35 93

Array 2

15 40 69


Vector of integers:
7 11 15 22 35 40 69 93


Write a java program which uses thread to implement this specification. The length of the arrays used does not exceed 100.


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Thread, Vector, Inheritance Problem Posted: Jul 19, 2005 3:31 AM
Reply to this message Reply
Are you giving us your assignment or what??
Anyways an Algorithmic suggestion:

create A class that extends Thread.
The job of this Thread when started will be to add up the two Arrays and return a Vector, and another Thread that will
sort them. Fool around with it to implement your own kill
methods when each Thread has finished its job.

suggestion: use interrupt.



public class AddArrays extends Thread{
private Vector myVec;

public void run(){
myVec = new Vector();
for (i to array1.length)
myVec.add(array1[i];
repeat for loop for array2
}

public Vector getVector(){
return myVec;
}
}

public class SortVector extends Thread{
Vector myVec;
public SortVector(Vector myVec){
this.myVec = myVec;
}

public void run(){
sortTheVector;
}

// include a Method toReturn Vector;
}



This should take you a long way. Obviously
you will need to use try/catches when toying
with the calling and interruption of your
threads:

catch(InterruptedException e)

print its stack trace:

e.printStackTrace();

Flat View: This topic has 1 reply on 1 page
Topic: Japanese text validation Previous Topic   Next Topic Topic: Array Exception

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use