Click here to Skip to main content
15,890,512 members
Home / Discussions / JavaScript
   

JavaScript

 
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 
AnswerRe: Thanks Richard Deeming & RyanDev Pin
ZurdoDev26-Apr-16 3:23
professionalZurdoDev26-Apr-16 3:23 
QuestionHalf Chart turned into a black box plotted using d3.js java script library Pin
KittoKy25-Apr-16 6:48
KittoKy25-Apr-16 6:48 
AnswerRe: Half Chart turned into a black box plotted using d3.js java script library Pin
Richard Deeming26-Apr-16 1:43
mveRichard Deeming26-Apr-16 1:43 
Questionjavascript Pin
Member 1215513524-Apr-16 22:45
Member 1215513524-Apr-16 22:45 
QuestionRe: javascript Pin
ZurdoDev25-Apr-16 1:38
professionalZurdoDev25-Apr-16 1:38 
Questionhelp me to make a small program Pin
Mohammad Billal Hossain16-Apr-16 0:24
Mohammad Billal Hossain16-Apr-16 0:24 
AnswerRe: help me to make a small program Pin
Richard MacCutchan16-Apr-16 0:50
mveRichard MacCutchan16-Apr-16 0:50 
GeneralRe: help me to make a small program Pin
Mohammad Billal Hossain16-Apr-16 1:14
Mohammad Billal Hossain16-Apr-16 1:14 

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.