Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Integrating a StopWatch?

  1. #1
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Integrating a StopWatch?

    import java.util.Scanner;
     
    public class main {
     
    	public static void main(String args[]){
     
    		Scanner scan = new Scanner(System.in);
     
    		System.out.println("This program is built to generate 2 digit multiplication");
    		System.out.println("The numbers can range from 10-99");
    		System.out.println("Enter the number of equations to work on below:");
     
     
    		int amount = scan.nextInt();	
    		int a = 0;
    		int correct = 0;
    		int wrong = 0;
    		int score = 0;
     
    		while(a < amount){
    		int x = 10 + (int)(Math.random()*89);
    		int y = 10 + (int)(Math.random()*89);
    		int z = x * y;
     
    		System.out.println(x + "x " + y);
     
    		int answer = scan.nextInt();
    		if(answer == z){
    			System.out.println("Correct!");
    			correct++;
    			score += 5;
    		}
    		else{
    			System.out.println("Wrong!");
    			wrong++;
    			score -= 9;
    		}
    		amount--;
    		}
    		System.out.println("\nSTATISTICS:");
    		System.out.println("Correct: " + correct);
    		System.out.println("Wrong: " + wrong);
    		System.out.println("Score: " + score);
    	}
    }

    How could I create a Stopwatch that begins once the user enters the number of equations they would like to use, then have that stopwatch end once the final question is answered. Then finally be able to print out the amount of time the stopwatch was running.
    Simplicity calls for Complexity. Think about it.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Integrating a StopWatch?

    Have a look at the System class.
    Improving the world one idiot at a time!

  3. #3
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: Integrating a StopWatch?

    Found an easy method of doing it. Using System.currentTimeMillis();... Make two double variables to record the time. Subtract them and divide by 1000 to get the time. Thanks Junky for replying quickly.
    Simplicity calls for Complexity. Think about it.

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Integrating a StopWatch?

    Exactly. You're welcome.
    Improving the world one idiot at a time!

Similar Threads

  1. Integrating JAVA and C#
    By ckask in forum Java Native Interface
    Replies: 4
    Last Post: February 28th, 2011, 10:38 AM
  2. StopWatch resume problem??
    By Tobbe129 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 19th, 2011, 02:21 PM