package squishgame;

/*
 * The stop watch class will allow a program to start and stop a stopwatch as
 * well as return the stopwatch as a string, a total ms's, or the hour, min, and
 * seconds separately.
 *
 * The System.currentTimeMillis() returns the number of milliseconds since
*/


public class Stopwatch {
private long myStarttime;    // in milliseconds
private long myStoptime;
private boolean isTiming;
public Stopwatch() {
    myStarttime = 0;
    myStoptime = 0;
    isTiming = false;
}
public void Start() {
    // starts the clock by getting system time
    myStarttime = System.currentTimeMillis();
    isTiming = true;
}
public void Stop() {
    // stops the clock by getting the system time
    if (isTiming) {
        myStoptime = System.currentTimeMillis();
        isTiming = false;
    }
}
public int getHour(){
    // returns the hours of the current time (if not timing)
}
public int getMinutes(){
    // returns the minutes of the current time (if not timing)
}
public int getSeconds(){
    // returns the seconds of the current time (if not timing)
}
public int getMillis(){
    // returns the millis of the current time (if not timing)
}
public String toString() {
    // returns a string of the time in hours:minutes:seconds.millis
}
}

Hi!

You didn't ask a question. You might want to read thehomework policy if you run into problems and want to ask for help here.

i need help finishing the code

I will give you some help. Then you must be able to write other functions.

public int getHour()
{
	if(isTiming)
		return -999;    //returns that the timer is running
	else
	{
 	       int timeDiff= myStoptime - myStarttime ;
	       return (timeDiff/1000)/(60*60);
	}
}

public int getMinutes()
{
	if(isTiming)
		return -999;
	else
	{
		int timeDiff= myStoptime - myStarttime ;
		return (timeDiff/(1000*60)) % 60;
	}
}

public String toString() 
{
	if(isTiming)
		return -999;
	else
	{
		String output = getHour() + ":" + getMinutes() + ":" + getSeconds() + ":" + getMillis() ;
		return output;
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.