This is a three part question. The classes at the links below give timing inform
ID: 3539100 • Letter: T
Question
This is a three part question.
The classes at the links below give timing information for 10 million addition operations. JobTimer is an abstract class,AddTimer is a subclass of JobTimer that provides an implementation for the doJob method involving repeated additions, and TestJobTimer is a driver class that exercises the AddTimer code.
Now we want to create a new subclass of JobTimer, the MultTimer class, to time the "job" of multiplication.
In the box below write the code that will complete the doJob method with multiplication.
public class MultTimer extends JobTimer {
//how many times should the operation be performed
public long numOperations = 10000000;
//implementation of the abstract method
public void doJob(){
long k = 0;
int result = 0, operand = 12345;
while(k<numOperations){
// Insert code here
}
}
}
Now we want to create a new subclass of JobTimer, the SqrtTimer class, to time the "job" of taking the square root of a number. In the box below, complete the doJob method by calling the square root function numOperations number of times.
Hint: use the Math.sqrt function.
public class SqrtTimer extends JobTimer {
//how many times should the operation be performed
public long numOperations = 10000000;
//implementation of the abstract method
public void doJob(){
// Insert code here
}
}
Now we want to create a new subclass of JobTimer, the TanTimer class, to time the "job" of finding the tangent (the trig function) of a number. In the box below write the entire body of the TanTimer class using the tangent function. As in the previous examples, your implementation of doJob should call Math.tan 10000000 times. (Note: use the Math.tanfunction; you can call it for any numerical value, but for the timing to work out, we suggest a value between 0 and 1. As you will see, the tangent function requires a lot more time than addition.)
public class TanTimer extends JobTimer {
// Insert code here
}
Explanation / Answer
public class MultTimer extends JobTimer {
//how many times should the operation be performed
public long numOperations = 10000000;
//implementation of the abstract method
public void doJob(){
long k = 0;
int result = 0, operand = 12345;
while(k<numOperations){
}
}
}
public class SqrtTimer extends JobTimer {
//how many times should the operation be performed
public long numOperations = 10000000;
//implementation of the abstract method
public void doJob(){
}
}
public class TanTimer extends JobTimer {
//how many times should the operation be performed
public long numOperations = 10000000;
//implementation of the abstract method
public void doJob(){
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.