Click here to Skip to main content
15,906,269 members
Home / Discussions / JavaScript
   

JavaScript

 
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 
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 
package cs520.hw6.part1;

public class LongTask extends Thread {
// instances of sharedData start and end
@SuppressWarnings("unused")
private static SharedResults sharedData = new SharedResults();
public int start;
public int end;

// Constructor with three arguments
public LongTask(SharedResults sd, int start1, int end1) {
Thread t = Thread.currentThread();
t.setName("Thread_"+start1+"_"+end1); // creating name for thread
start = start1;
end = end1;
System.out.print(t.getName() + "is Adding:- ");
//run(start, end);
}


public void run(){
try{
int sum = 0;
// adding integers from start to end
for(int i = start; i <= end; i++)
{
try {
Thread.sleep(10);// sleep for 10 milliseconds
} catch (InterruptedException e) {
e.printStackTrace();
}
sum += i;
}

System.out.println(sum);
SharedResults.addToResults(sum); // invoking addtoresults method
}catch(NullPointerException e) {
e.printStackTrace();
}

}
}




package cs520.hw6.part1;

import java.util.ArrayList;

public class SharedResults {

// arraylist results instance
private static ArrayList<integer> results = new ArrayList<>();

// default constructor
public SharedResults()
{

}

// void method that takes in integer and adds it to results
public static void addToResults( int values){
//printing values
results.add(values);
results.size();
System.out.println("Cumulative Results are: " + results);
}

// get result method
public static int getResult(){
int sum = 0;
for(int i = 0; i < results.size(); i++)
{
sum += results.get(i);
}
System.out.println("Final Result = " + sum);
return sum;

}
}






package cs520.hw6.part1;

public class Test {

public static void main(String[] args) {

// creating shared results object
SharedResults sr = new SharedResults();

// creating five long task objects
LongTask lt1 = new LongTask(sr,1,100);
lt1.run(); // starting object as it is created
LongTask lt2 = new LongTask(sr,101,200);
lt2.run();
LongTask lt3 = new LongTask(sr,201,300);
lt3.run();
LongTask lt4 = new LongTask(sr,301,400);
lt4.run();
LongTask lt5 = new LongTask(sr,401,500);
lt5.run();

// printing results
SharedResults.getResult();
}

}
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 
GeneralRe: help me to make a small program Pin
Richard MacCutchan16-Apr-16 1:51
mveRichard MacCutchan16-Apr-16 1:51 
AnswerRe: help me to make a small program Pin
Peter Leow16-Apr-16 0:57
professionalPeter Leow16-Apr-16 0:57 
GeneralRe: help me to make a small program Pin
Mohammad Billal Hossain16-Apr-16 1:16
Mohammad Billal Hossain16-Apr-16 1:16 

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.