Question: Type Sum, Summation and Driver classes given in the textbook, page 164 test the code with three integer values, take a screen shot of all
Type Sum, Summation and Driver classes given in the textbook, page 164 test the code with three integer values, take a screen shot of all three output in one image. zip .java files and the image
class Sum
{
}
private int sum;
public int getSum() {
return sum;
}
public void setSum(int sum) {
this.sum sum;
}
class Summation implements Runnable
{
}
private int upper;
private Sum sumValue;
public Summation(int upper, Sum sumValue) {
this.upper = upper;
this.sumValue = sumValue;
}
public void run() {
int sum = 0;
}
for (int i = 0; i <= upper; i++)
sum += i;
sumValue.setSum(sum);
public class Driver
{
}
public static void main(String[] args) {
if (args.length > 0) {
}
if (Integer.parseint(args[O]) < 0)
System.err.println(args[O] + "must be>= 0.");
else {
II create the object to be shared
Sum sumObject = new Sum();
int upper= Integer.parseint(args[O]);
Thread thrd =new Thread(new Summation(upper, sumObject));
thrd.start();
try {
thrd. join () ;
System.out.println
("The sum of "+upper+" is "+sumObject.getSum());
} catch (InterruptedException ie) { }
}
else
System.err.println("Usage: Summation
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
