Hallo,
this is a program i intend to run in Java,but i get some errors.Can someone please help me to correct it.Thanks
Programcode:
//The class Sqrt calculates the sum of roots
//between the values dblStart and dblEnd.
//The calculation is done within the jobCode() method
//It implements the JobCodeInt interface and implementation
//code is within the jobCode() method
//use the constructor to pass data to the class and to
//initialize resources that are local to the Job
//Dispatcher machine. In this example, the range of numbers
//for which the sum of square roots is to be calculated is
//sent to the class
import java.lang.Thread;
import java.math.*;
public class Sqrt implements JobCodeInt
{
double dblStart, dblEnd, dblPartialSum;
public Sqrt(double Start,double End)
{
dblStart = Start;
dblEnd = End;
}
public Object jobCode()
{
dblPartialSum = 0;
for(double i=dblStart;i<=dblEnd;i++)
//can make calls to standard Java functions and objects.
dblPartialSum += Math.sqrt(i);
//return the result an object of a standard Java class.
return (new Double(dblPartialSum));
}
}
//this class can have any name of your choosing
//the name JobDispatcher has been chosen merely for convenience
public class JobDispatcher
{
public static void main(String args[])
{
double fin = 10000000; //represents 10 raised to 9
double finByTen = fin/10; //represents 10 raised to 8
long nlStartTime = System.currentTimeMillis();
//range is from 1 to 3*10^8
Sqrt sqrt1 = new Sqrt(1,finByTen*3);
//range is from ((3*10^8)+1) to 10^9
Sqrt sqrt2 = new Sqrt((finByTen*3)+1,fin);
//The following creates two instances of PseudoRemThr class.
//The parameters to this constructor are as follows.
//First parameter: An instance of a class representing a subtask
//Second parameter: Remote Host on which this subtask
//will be executed
//Third parameter: A descriptive name for this
//PseudoRemThr instance.
PseudoRemThr psr1 = new
PseudoRemThr(sqrt1,"//192.168.0.1:3333/","Win98"
PseudoRemThr psr2 = new
PseudoRemThr(sqrt2,"//192.168.0.1:3333/","Win2K"
psr1.waitForResult(); //wait for execution to get over
psr2.waitForResult();
//get the result from each thread
Double res1 = (Double)psr1.getResult();
Double res2 = (Double)psr2.getResult();
double finalRes = res1.doubleValue() + res2.doubleValue();
long nlEndTime = System.currentTimeMillis();
System.out.println("Total time taken: " + (nlEndTime-nlStartTime));
System.out.println("Sum: " + finalRes);
}
}
this is a program i intend to run in Java,but i get some errors.Can someone please help me to correct it.Thanks
Programcode:
//The class Sqrt calculates the sum of roots
//between the values dblStart and dblEnd.
//The calculation is done within the jobCode() method
//It implements the JobCodeInt interface and implementation
//code is within the jobCode() method
//use the constructor to pass data to the class and to
//initialize resources that are local to the Job
//Dispatcher machine. In this example, the range of numbers
//for which the sum of square roots is to be calculated is
//sent to the class
import java.lang.Thread;
import java.math.*;
public class Sqrt implements JobCodeInt
{
double dblStart, dblEnd, dblPartialSum;
public Sqrt(double Start,double End)
{
dblStart = Start;
dblEnd = End;
}
public Object jobCode()
{
dblPartialSum = 0;
for(double i=dblStart;i<=dblEnd;i++)
//can make calls to standard Java functions and objects.
dblPartialSum += Math.sqrt(i);
//return the result an object of a standard Java class.
return (new Double(dblPartialSum));
}
}
//this class can have any name of your choosing
//the name JobDispatcher has been chosen merely for convenience
public class JobDispatcher
{
public static void main(String args[])
{
double fin = 10000000; //represents 10 raised to 9
double finByTen = fin/10; //represents 10 raised to 8
long nlStartTime = System.currentTimeMillis();
//range is from 1 to 3*10^8
Sqrt sqrt1 = new Sqrt(1,finByTen*3);
//range is from ((3*10^8)+1) to 10^9
Sqrt sqrt2 = new Sqrt((finByTen*3)+1,fin);
//The following creates two instances of PseudoRemThr class.
//The parameters to this constructor are as follows.
//First parameter: An instance of a class representing a subtask
//Second parameter: Remote Host on which this subtask
//will be executed
//Third parameter: A descriptive name for this
//PseudoRemThr instance.
PseudoRemThr psr1 = new
PseudoRemThr(sqrt1,"//192.168.0.1:3333/","Win98"
PseudoRemThr psr2 = new
PseudoRemThr(sqrt2,"//192.168.0.1:3333/","Win2K"
psr1.waitForResult(); //wait for execution to get over
psr2.waitForResult();
//get the result from each thread
Double res1 = (Double)psr1.getResult();
Double res2 = (Double)psr2.getResult();
double finalRes = res1.doubleValue() + res2.doubleValue();
long nlEndTime = System.currentTimeMillis();
System.out.println("Total time taken: " + (nlEndTime-nlStartTime));
System.out.println("Sum: " + finalRes);
}
}