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 8 of 8

Thread: How to put a timer?!?

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation How to put a timer?!?

    Hey guys, i already found it out myself the last thread that means it was solved. But my problem now is how to put a timer in that code. I know that i am a newbie at this but i really love programming. I wanna learn new things. Well, here's the updated code from yesterday:
    import java.util.Random;
    import java.util.Scanner;
     
    public class Easy {
     
        public static void main (String []args){
     
            String words[]={"Love", "Hate", "Truth", "Happy", "Pressure", "Burp", "Vampire"
            , "Surf", "Believe", "Slime", "Dream", "Religion", "Rhythm", "Disco", "Honey",
            "Star", "Armies", "Zombie", "Heart", "Break", "Docks", "Multiply", "Mace", "Moustache"
            , "Wizards", "Sports", "Blind", "Riddle", "Business", "School", "Blood", "Promenade",
            "Vault", "Spray", "Eternal", "Dress", "Abstain", "Controls", "Circuit", "Forever",
            "Dangerous", "Skunk", "House", "Wives", "Flashlight", "Console", "Awesome", "Scared",
            "Hormones", "Promise", "Angel", "Baggage", "Duck", "Destroy", "Tissue", "Ketchup",
            "Picture", "Basket", "Basketball", "Fan", "Dough", "Thief", "Female", "Family", "Normal",
            "Wireless", "Empty", "Cycles", "Banana", "Eggplant", "Samba", "Jumble", "Flush", "Beach",
            "Driver", "Queen", "Mommy", "Fade", "Kitten", "Spring", "Interest", "Debts", "Horse",
            "Tomorrow", "Discount", "Faithful", "Midnight", "Epic", "Calendar", "Roses", "Funeral",
            "Badminton", "Spirit", "Water", "Pizza", "Science", "Cabinet", "Apple", "Television",
            "Profile", "Wine", "Sedan", "Luxury", "Firewall", "Computer", "Tablet", "Giraffe", "Ring",
            "Shut", "Vision", "World", "War", "High", "School", "Fantasy", "Warfare", "Incognito",
            "Loading", "Penguins", "Fright", "Night", "Diary", "Mega", "Submit", "Hold", "Statue",
            "Boat", "Mobile", "Invisible", "Visible", "Ground", "Space", "Dragon", "Spade", "Clover",
            "Senior", "Junior", "Sophomore", "Freshman", "Twilight", "Dawn", "Eclipse", "Moon",
            "Hair", "Spray", "Camp", "Jazz", "Rock", "Eggs", "Hustle"};
     
           Scanner sc = new Scanner(System.in); 
           Random a = new Random();
           int roll = a.nextInt(149);
           String type = "";
           String reply = "yes";
           int error = 0;
     
           System.out.println(words[roll]);
     
        while (!reply.equalsIgnoreCase("no")){
        	if (!reply.equalsIgnoreCase("yes"))
        		System.out.println("Yes and No are the only acceptable answers");
     
        	else {
        		System.out.println("Type the word");
     
     
     
     
        		while (!type.equals(words[roll])){
        			type = sc.next();
        			try {
        				if (!type.equals(words[roll])){
        					System.out.println("Type again");
        					error++;
        					}
        				else {
        					if (!type.equals(words[roll]))
        					System.out.println("next word");
     
        				}
     
        			}catch(Exception e){
     
        				System.out.println("lallalala");
        			}
     
        		}
        	}
        	type = "";
    		System.out.println("Would you like to play again? Yes/No");
    		reply = sc.nextLine();
    		roll = a.nextInt(149);
     
     
     
        }
        System.out.println("Thank you for playing");
        }
    }
    Advanced Thank You Guys!


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: How to put a timer?!?


  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How to put a timer?!?

    Also explain what the timer is supposed to do.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Aug 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to put a timer?!?

    Quote Originally Posted by Norm View Post
    Also explain what the timer is supposed to do.
    The timer will time the game and at the end of the time, the game should stop too and it will display the score. I'm only asking about the timer

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How to put a timer?!?

    time the game
    Are you trying to get the duration of the game? The System class has a method that returns the current time. Get the time at the start and the time at the end and subtract to get the duration.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Aug 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to put a timer?!?

    Quote Originally Posted by Norm View Post
    Are you trying to get the duration of the game? The System class has a method that returns the current time. Get the time at the start and the time at the end and subtract to get the duration.
    am i still gonna import swing timer?

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How to put a timer?!?

    am i still gonna import swing timer?
    What class and methods are you trying to use? You can look in the API doc to see what package the class is in so that you know what import statement you need.
    Java Platform SE 6
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Aug 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to put a timer?!?

    Quote Originally Posted by Norm View Post
    What class and methods are you trying to use? You can look in the API doc to see what package the class is in so that you know what import statement you need.
    Java Platform SE 6
    Thanks for your help!!!

Similar Threads

  1. how to set timer
    By jack_nutt in forum Java Theory & Questions
    Replies: 3
    Last Post: June 23rd, 2011, 08:55 PM
  2. Timer digit
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 2nd, 2011, 08:07 PM
  3. Ticked Off Timer
    By JavaCow in forum Loops & Control Statements
    Replies: 8
    Last Post: October 30th, 2010, 09:18 AM
  4. Timer?
    By TimW in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: October 27th, 2009, 07:43 AM
  5. How to Use Timer in Java
    By neo_2010 in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: September 1st, 2009, 12:10 PM