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

Please help. I need to write a tester class for the code that follows below. The

ID: 3632095 • Letter: P

Question

Please help. I need to write a tester class for the code that follows below. The name of the tester class should be TestStopWatch. TestStopWatch should contain a main method that: creates an instance of StopWatch (supply a random number as the argument to the constructor), write a loop that displays time and ticks the StopWatch down to 0, asks the user for a new time and use setTime() to set the StopWatch and go through the countdown again.

public class StopWatch
{
int timeLeft;
// sets default value for timeLeft of 60
public StopWatch ()
{
timeLeft=60;
}
// sets default value to absolute value of argument
public StopWatch(int value)
{
timeLeft=value;
}
// returns value of timeLeft
public int getTime()
{
return timeLeft;
}
// sets timeLeft to absolute value of newTime
public void setTime (int newTime)
{
timeLeft=newTime;
}
// subtracts 1 from timeLeft if timeLeft is positive;
// if timeLeft is 0, does nothing
public void tick ()
{
if(timeLeft>0)
timeLeft=timeLeft-1;
}
public String toString()
{
return "Time:"+timeLeft;
}
}

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); } } } }