last section of code has to a static class

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2004
Posts: 14
Reputation: Bill T is an unknown quantity at this point 
Solved Threads: 0
Bill T Bill T is offline Offline
Newbie Poster

last section of code has to a static class

 
0
  #1
Aug 13th, 2004
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;
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2003
Posts: 117
Reputation: Iron_Cross is an unknown quantity at this point 
Solved Threads: 2
Iron_Cross's Avatar
Iron_Cross Iron_Cross is offline Offline
Junior Poster

Re: last section of code has to a static class

 
0
  #2
Aug 14th, 2004
Ok dude, first you need to use the [*code] and [/code] tags...
  1. // import java.io package and utility packages
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. class Stopwatch{
  6.  
  7. //declared outside of all methods
  8. private long startTime;
  9. public void start() {
  10. GregorianCalendar now = new GregorianCalendar();
  11. startTime = now.getTimeInMillis();
  12. }
  13.  
  14. public void showElapsedTime() {
  15. GregorianCalendar now = new GregorianCalendar();
  16. long currTime = now.getTimeInMillis();
  17. long difference = (currTime - startTime)/1000;
  18. System.out.print(difference);
  19. System.out.println(" seconds have elapsed.");
  20. }
  21. }
  22.  
  23. class Irritating_stopwatch {
  24. public static void main(String arg[]) throws Exception {
  25. BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
  26. Stopwatch timer = new Stopwatch();
  27. for (int i=9; i>=0; i--){
  28. System.out.println("Hit the Enter key to Start timer");
  29. keyboard.readLine();
  30. timer.start();
  31. System.out.println("Hit the Enter key to Stop timer");
  32. keyboard.readLine();
  33. timer.showElapsedTime();
  34. Counter.decrease();
  35. System.out.print(Counter.getValue());
  36. System.out.println(" More Tries");
  37. System.out.println();
  38. System.out.println("Hit the Enter key to initialize timer");
  39. keyboard.readLine();
  40. }
  41. System.out.println("Due to planned obsolescence, this Stopwatch is no longer perational");
  42. System.out.println();
  43. }
  44. }
  45.  
  46. class Counter {
  47. private static int callCount = 10;
  48.  
  49. public static void decrease() {
  50. callCount --;
  51. }
  52.  
  53. public static int getValue() {
  54. return callCount;
  55. }
  56. }
Basically, just instead of creating an instance of Counter, you just call the methods direct... Counter.decrease(); and so on and so forth.
elitehackers.info
Today's Penny-Arcade!
Pain is weakness leaving the body!
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 14
Reputation: Bill T is an unknown quantity at this point 
Solved Threads: 0
Bill T Bill T is offline Offline
Newbie Poster

Re: last section of code has to a static class

 
0
  #3
Aug 15th, 2004
TY very much it works great.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC