Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help. I must complete the following java code: public class StopWatch { i

ID: 3632040 • Letter: P

Question

Please help. I must complete the following java code:

public class StopWatch {
int timeLeft;

// sets default value for timeLeft of 60
public StopWatch () {

}

// sets default value to absolute value of argument
public StopWatch(int value) {

}
// returns value of timeLeft
public int getTime () {

}

// sets timeLeft to absolute value of newTime
public void setTime (int newTime) {

}

// subtracts 1 from timeLeft if timeLeft is positive;
// if timeLeft is 0, does nothing
public void tick () {

}
}

I also need to write a class that includes a main method that tests the stopwatch. It should create an instance of StopWatch (supply a random number as the argument to the constructor), write a loop that displays the time and ticks down to 0, asks the user for a new time, using setTime(), and go through another countdown loop.

Thank you!!!

Explanation / Answer

Here is the tester class code import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Random; public class TestStopWatch { public static void main(String[] args) throws IOException { InputStreamReader inp = new InputStreamReader(System.in); BufferedReader input = new BufferedReader(inp); Random rand=new Random(); StopWatch swTest = new StopWatch(rand.nextInt(100)); while(swTest.getTime() > 0) { System.out.println(swTest); swTest.tick(); if(swTest.getTime()==0) { System.out.println("Enter new Time (-1 or 0 to exit) >"); int newTime = Integer.parseInt(input.readLine()); swTest.setTime(newTime); } } } }