After setting the time where it should start, you enter "y".. the timer will start..
It's supposed to stop whenever you want it to by pressing "n"
but I don't know how..
The only way I know how to get it to ask for "y" or "n" again is to set what day it should prompt you..
but that's not what we're supposed to make.. D:
What should I do.. so you won't have to set when it should prompt you to enter "y" or "n"? Is it even possible?
I tried putting the 2nd prompt inside the loop but then it makes it stop each time the time is incremented..****
myClock CLASS
/**
* @(#)myClock.java
*
*
* @author
* @version 1.00 2012/5/8
*/
import java.io.*;
import java.util.*;
public class myClock
{
static Scanner scan = new Scanner (System.in);
private int hr;
private int min;
private int sec;
private int da;
private String startStop;
public myClock()
{
setTime(0 , 0, 0 , 0);
}
public myClock(int d, int h, int m , int s)
{
setTime(d, h , m , s);
}
public void setTime(int day , int hour , int minute , int second )
{
if (0 <= day )
da = day;
else
da = 0;
if (0 <= hour && hour < 24 )
hr = hour;
else
hr = 0;
if (0 <= minute && minute < 60)
min = minute ;
else
min = 0;
if (0 <= second && second < 60 )
sec = second;
else sec = 0;
}
public void AskstartStop()
{
System.out.println ("Enter \"y\" to start clock.");
startStop = scan.next();
}
public int getDay()
{return da;}
public int getHour()
{ return hr;}
public int setMin()
{return min; }
public int getSec()
{return sec;}
public void printTime()
{
if(da <= 10)
System.out.print("0");
System.out.print(da + ":");
if(hr < 10)
System.out.print("0");
System.out.print(hr + ":");
if (min <10)
System.out.print("0");
System.out.print (min + ":");
if (sec < 10)
System.out.print("0");
System.out.print(sec + ":");
}
public void incrementSecond()
{
while (startStop.equalsIgnoreCase("y")) // AT THE BEGINING AskstartStop() WILL ASK TO ENTER "y" TO START THE TIMER.
{
sec++; // THEN THE TIMER STARTS....
System.out.println();
printTime();
if (sec > 59)
{
sec = 0 ;
incrementMinute();
}
if (startStop.equalsIgnoreCase("n") == true ) // WHERE CAN I PUT ANOTHER PROMPT;
//startStop = scan.next();
//WHERE THE USER CAN ENTER "n"
{System.exit(0);} // AND STOP THE TIMER?
}
}
public void incrementMinute()
{
min++;
if ( min > 59)
{min = 0;
incrementHour();
}
}
public void incrementHour()
{
hr++;
if (hr > 23)
{hr = 0;
incrementDay();}
}
public void incrementDay()
{
da++;
}
}
myClockTest
import java.io.*;
import java.util.*;
public class myClockTest{
static Scanner setset = new Scanner(System.in);
public static void main (String[]args) {
myClock mc = new myClock (00 ,00, 00, 00);
System.out.print( "Set Seconds:");
int secondsSet = setset.nextInt();
System.out.println();
System.out.print( "Set Minutes:");
int minutesSet = setset.nextInt();
System.out.println();
System.out.print( "Set Hours:");
int hoursSet = setset.nextInt();
System.out.println();
System.out.print( "Set Days:");
int daysSet = setset.nextInt();
mc.AskstartStop();
mc.printTime();
mc.setTime( daysSet,hoursSet, minutesSet, secondsSet);
mc.incrementSecond();
System.out.println();
mc.printTime();
}}