Problem Statement: Make a program that conducts the \"Timed 20 m sprint test\" o
ID: 3550016 • Letter: P
Question
Problem Statement:
Make a program that conducts the "Timed 20 m sprint test" on my runners and record the results in their stats. Create an easy tool that will conduct the test and crete a short text statement aboout the result that can be copied and pasted into their records.
Assumptions:
I already know how to conduct the test,tool does not need to teach me about it. It needs to be easy to use and generate accurate text output.
Here are the two programs i wrote:
import java.util.Timer;
import java.util.TimerTask;
import java.util.Scanner;
public class Walk
{
public static void main(String[]args)
{
Scanner myScanner = new Scanner(System.in);
Boolean stillRunning = true;
//while(stillRunning)
{
System.out.println("Welcome to the 10 meter walk test");
System.out.println("Would you like to do a test? Enter [Y/N]");
String userChoice = myScanner.next();
if(userChoice.equalsIgnoreCase("Y") ||
userChoice.equalsIgnoreCase("YES"))
{
//continue;
}
else
{
stillRunning= false;
}
}}}
and
public class StopWatch
{
private long startTime = 0;
private long stopTime = 0;
private boolean running = false;
public void start ()
{
this.stopTime = System.currentTimeMillis();
this.running= false;
}
public long getElaspedTimeSecs()
{
long elapsed;
if (running)
{
elapsed = ((System.currentTimeMillis() - startTime) / 1000);
}
else
{
elapsed = ((stopTime - startTime)/ 1000);
}
return elapsed;
}
public static void main (String[] args)
{
StopWatch s = new StopWatch();
s.start();
//s.stop();
System.out.println("time in seconds:"+s.getElaspedTimeSecs());
}
}
How do i combine the two codes?
Explanation / Answer
// You can combine both the codes as follows.
// first declare StopWatch class without public in same file before Walk class
// and like below.
import java.util.Timer;
import java.util.TimerTask;
import java.util.Scanner;
class StopWatch
{
private long startTime = 0;
private long stopTime = 0;
private boolean running = false;
public void start ()
{
this.stopTime = System.currentTimeMillis();
this.running= false;
}
public long getElaspedTimeSecs()
{
long elapsed;
if (running)
{
elapsed = ((System.currentTimeMillis() - startTime) / 1000);
}
else
{
elapsed = ((stopTime - startTime)/ 1000);
}
return elapsed;
} // Comment out below main code we dont nedd this.
/*public static void main (String[] args)
{
StopWatch s = new StopWatch();
s.start();
//s.stop();
System.out.println("time in seconds:"+s.getElaspedTimeSecs());
}
*/
}
public class Account
{
public static void main(String[]args)
{
Scanner myScanner = new Scanner(System.in);
StopWatch s = new StopWatch();
s.start();
//s.stop();
Boolean stillRunning = true;
//while(stillRunning)
{
System.out.println("Welcome to the 10 meter walk test");
System.out.println("Would you like to do a test? Enter [Y/N]");
String userChoice = myScanner.next();
if(userChoice.equalsIgnoreCase("Y") ||
userChoice.equalsIgnoreCase("YES"))
{
//continue;
}
else
{
stillRunning= false;
}
}
System.out.println("time in seconds:"+s.getElaspedTimeSecs());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.