| | |
last section of code has to a static class
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2004
Posts: 14
Reputation:
Solved Threads: 0
I have a stopwatch program and the last of the code has to be a static class
can someone help running out of time.
I've tried all i know examples aren't helping.
Here is the code I've written.
I hope someone can help. TY...
// import java.io package and utility packages
import java.io.*;
import java.util.*;
class Stopwatch{
public void start() {
GregorianCalendar now = new GregorianCalendar();
startTime = now.getTimeInMillis();
}
public void showElapsedTime() {
GregorianCalendar now = new GregorianCalendar();
long currTime = now.getTimeInMillis();
long difference = (currTime - startTime)/1000;
System.out.print(difference);
System.out.println(" seconds have elapsed.");
}
//declared outside of all methods
private long startTime;
}
class Irritating_stopwatch {
public static void main(String arg[]) throws Exception {
BufferedReader keyboard = new BufferedReader(
new InputStreamReader(System.in));
Stopwatch timer = new Stopwatch();
Counter countDown = new Counter();
for (int i=9; i>=0; i--){
System.out.println("Hit the Enter key to Start timer");
keyboard.readLine();
timer.start();
System.out.println("Hit the Enter key to Stop timer");
keyboard.readLine();
timer.showElapsedTime();
countDown.decrease();
System.out.print(countDown.getValue());
System.out.println(" More Tries");
System.out.println();
System.out.println("Hit the Enter key to initialize timer");
keyboard.readLine();
}
System.out.println("Due to planned obsolescence, this Stopwatch is no longer operational");
System.out.println();
}
}
class Counter {
public void decrease() {
callCount --;
}public int getValue() {
return callCount;
}
private int callCount = 10;
}
can someone help running out of time.
I've tried all i know examples aren't helping.
Here is the code I've written.
I hope someone can help. TY...
// import java.io package and utility packages
import java.io.*;
import java.util.*;
class Stopwatch{
public void start() {
GregorianCalendar now = new GregorianCalendar();
startTime = now.getTimeInMillis();
}
public void showElapsedTime() {
GregorianCalendar now = new GregorianCalendar();
long currTime = now.getTimeInMillis();
long difference = (currTime - startTime)/1000;
System.out.print(difference);
System.out.println(" seconds have elapsed.");
}
//declared outside of all methods
private long startTime;
}
class Irritating_stopwatch {
public static void main(String arg[]) throws Exception {
BufferedReader keyboard = new BufferedReader(
new InputStreamReader(System.in));
Stopwatch timer = new Stopwatch();
Counter countDown = new Counter();
for (int i=9; i>=0; i--){
System.out.println("Hit the Enter key to Start timer");
keyboard.readLine();
timer.start();
System.out.println("Hit the Enter key to Stop timer");
keyboard.readLine();
timer.showElapsedTime();
countDown.decrease();
System.out.print(countDown.getValue());
System.out.println(" More Tries");
System.out.println();
System.out.println("Hit the Enter key to initialize timer");
keyboard.readLine();
}
System.out.println("Due to planned obsolescence, this Stopwatch is no longer operational");
System.out.println();
}
}
class Counter {
public void decrease() {
callCount --;
}public int getValue() {
return callCount;
}
private int callCount = 10;
}
Ok dude, first you need to use the [*code] and [/code] tags...
Basically, just instead of creating an instance of Counter, you just call the methods direct... Counter.decrease(); and so on and so forth.
Java Syntax (Toggle Plain Text)
// import java.io package and utility packages import java.io.*; import java.util.*; class Stopwatch{ //declared outside of all methods private long startTime; public void start() { GregorianCalendar now = new GregorianCalendar(); startTime = now.getTimeInMillis(); } public void showElapsedTime() { GregorianCalendar now = new GregorianCalendar(); long currTime = now.getTimeInMillis(); long difference = (currTime - startTime)/1000; System.out.print(difference); System.out.println(" seconds have elapsed."); } } class Irritating_stopwatch { public static void main(String arg[]) throws Exception { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); Stopwatch timer = new Stopwatch(); for (int i=9; i>=0; i--){ System.out.println("Hit the Enter key to Start timer"); keyboard.readLine(); timer.start(); System.out.println("Hit the Enter key to Stop timer"); keyboard.readLine(); timer.showElapsedTime(); Counter.decrease(); System.out.print(Counter.getValue()); System.out.println(" More Tries"); System.out.println(); System.out.println("Hit the Enter key to initialize timer"); keyboard.readLine(); } System.out.println("Due to planned obsolescence, this Stopwatch is no longer perational"); System.out.println(); } } class Counter { private static int callCount = 10; public static void decrease() { callCount --; } public static int getValue() { return callCount; } }
![]() |
Similar Threads
- Passing static class member as argument? (Java)
- Generics with static inner class... (Java)
- Double declaration of static class Members (C++)
- C++ static class (C++)
- Visual Studio 6: Initializing static class member (C++)
Other Threads in the Java Forum
- Previous Thread: changing colours
- Next Thread: I can't implement a word count into my text editor (JAVA)
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui health html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor





