Click here to Skip to main content
15,922,155 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: I think I might have it now, not sure if its the right way to do it, but it works. Pin
Nathan Minier6-May-16 1:50
professionalNathan Minier6-May-16 1:50 
GeneralRe: I think I might have it now, not sure if its the right way to do it, but it works. Pin
jkirkerx6-May-16 5:27
professionaljkirkerx6-May-16 5:27 
GeneralRe: I think I might have it now, not sure if its the right way to do it, but it works. Pin
Nathan Minier6-May-16 6:14
professionalNathan Minier6-May-16 6:14 
GeneralRe: I think I might have it now, not sure if its the right way to do it, but it works. Pin
jkirkerx6-May-16 7:28
professionaljkirkerx6-May-16 7:28 
QuestionNeed an API similar to YouTube Help popup window Pin
Zaki Gaima5-May-16 3:28
Zaki Gaima5-May-16 3:28 
Questionbrowser error handling using javascript Pin
rorschach2174-May-16 19:25
rorschach2174-May-16 19:25 
SuggestionRe: browser error handling using javascript Pin
Richard MacCutchan4-May-16 20:58
mveRichard MacCutchan4-May-16 20:58 
AnswerRe: browser error handling using javascript Pin
John C Rayan13-May-16 1:18
professionalJohn C Rayan13-May-16 1:18 
QuestionAsynchronouse Call Pin
Syed Rehman27-Apr-16 9:14
Syed Rehman27-Apr-16 9:14 
QuestionRe: Asynchronouse Call Pin
ZurdoDev27-Apr-16 9:29
professionalZurdoDev27-Apr-16 9:29 
AnswerRe: Asynchronouse Call Pin
John C Rayan4-May-16 22:20
professionalJohn C Rayan4-May-16 22:20 
Questionhelp me writing a small program Pin
Member 1248677626-Apr-16 10:36
Member 1248677626-Apr-16 10:36 
AnswerRe: help me writing a small program Pin
Afzaal Ahmad Zeeshan26-Apr-16 11:00
professionalAfzaal Ahmad Zeeshan26-Apr-16 11:00 
AnswerRe: help me writing a small program Pin
Peter_in_278026-Apr-16 21:05
professionalPeter_in_278026-Apr-16 21:05 
GeneralRe: help me writing a small program Pin
Karthik_Mahalingam5-May-16 23:27
professionalKarthik_Mahalingam5-May-16 23:27 
QuestionHelp me to write a small program. Pin
Member 1248677626-Apr-16 10:21
Member 1248677626-Apr-16 10:21 
hi
i wrote a code for the 2nd part in the following.
but i dont know where am i going wrong. need help.


C#
Create a new Java Project in Eclipse named HW6_lastName and complete the following requirements based on the Threads. Several threads will share a single object and contribute their individual result to the shared object. The shared object accumulates the partial results.

Create a package named cs520.hw6. Using this package, create the following classes.

 Create a class named SharedResults as follows. The class keeps track of the shared result.
The instance (or member) private variable – result (int).
A void addToResultmethod which takes the given integer argument and adds it to the shared result. This method then prints to the console the name of the current thread, the value it added, and the cumulative result. Handle the synchronization issue with this method.
The getResult method with no arguments which returns the shared result. Handle the synchronization issue with this method.
 

2.      Create a class named LongTask which extends the Thread class.
 

a.The instance (or member) private variables – sharedData (of type SharedResults), start (integer) and end (integer).

b.A single constructor which takes the above three arguments and stores them in the instance values. Also, create a name for this thread as Thread_<start>_<end>

c.In the run method, add the integer numbers from start to end (both inclusive) using a for loop. Also, sleep for a random time (up to 10 milliseconds) in each iteration of the loop. After the loop, invoke the addToResult method of the shared object and provide this accumulated sum.

 

 

Create a Test class to test the following functionality in its main method.
a.Create the SharedResults object and assign it to a variable.

b.Create five LongTask objects by passing the above shared object and the start and end values for each as (1, 100), (101, 200), (201, 300), (301, 400), and (401, 500) respectively.

c.Start each thread as it is created.

d.Wait for all the threads to complete using the join method.

e.Print the result from the shared object.

Sample Output:

Create an archive of your Eclipse project using the following steps. Select the HW6_lastName project in the Eclipse IDE’s Package Explorer or the Navigator window.

Click File->Export. Select the General->Archive File option. Click Next.

Specify the "To archive file:" entry as say, C:TempHW6_lastName.zip.

The zip file will be created and stored in the C:Temp folder.

Submit this zip file as an attachment in the Assignment Section of Vista.

AnswerRe: Help me to write a small program. Pin
Member 1161095626-Apr-16 10:53
Member 1161095626-Apr-16 10:53 
AnswerRe: Help me to write a small program. Pin
Afzaal Ahmad Zeeshan26-Apr-16 11:09
professionalAfzaal Ahmad Zeeshan26-Apr-16 11:09 
GeneralRe: Help me to write a small program. Pin
Member 1248677626-Apr-16 16:04
Member 1248677626-Apr-16 16:04 
GeneralRe: Help me to write a small program. Pin
Member 1248677626-Apr-16 16:04
Member 1248677626-Apr-16 16:04 
SuggestionRe: Help me to write a small program. Pin
Richard MacCutchan26-Apr-16 20:42
mveRichard MacCutchan26-Apr-16 20:42 
GeneralRe: Help me to write a small program. Pin
Richard MacCutchan26-Apr-16 20:44
mveRichard MacCutchan26-Apr-16 20:44 
QuestionThanks Richard Deeming & RyanDev Pin
tayfunk63 NevCity25-Apr-16 12:22
tayfunk63 NevCity25-Apr-16 12:22 
SuggestionRe: Thanks Richard Deeming & RyanDev Pin
Richard MacCutchan25-Apr-16 21:51
mveRichard MacCutchan25-Apr-16 21:51 
GeneralRe: Thanks Richard Deeming & RyanDev Pin
tayfunk63 NevCity26-Apr-16 2:49
tayfunk63 NevCity26-Apr-16 2:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.