my own little program

Sharky Forums


Results 1 to 8 of 8

Thread: my own little program

  1. #1
    Tiger Shark munchy1988's Avatar
    Join Date
    Sep 2002
    Location
    The Dirty Jerz
    Posts
    932

    Talking my own little program

    well, i got bored in class, and made my own little "destry the world program", u kno, the usual.

    heres to code for it. im just a beginner so its not that advanced.

    Code:
    class countries
    {
    	
    	public static void main(String[] args)
    	{		
    		int seconds = 0;
    		int countries = 0;
    		int count = 0;
    		String msg = "";
    		String msg1= "";
    		seconds = IO.getInt("How many seconds will the process take?");
    		
    		while ((seconds<1) || (seconds>50))
    		{
    			seconds = IO.getInt("Process is either too long or undefinable.  Please re-enter process time");
    		}
    		
                    countries = IO.getInt("How many countries?");
    		
    		if (countries == 1)
    		{
    			msg1+= ("1 Billion Chinese People ");
    		}
    		
    		if (countries == 2)
    		{
    			msg1+= ("China and Germany ");
    		}
    		
    		if (countries == 3)
    		{
    			msg1+= ("China, Germany, and The Pinko Commies ");
    		}
    		
    		if (countries == 4)
    		{
    			msg1+= ("China, Germany, Russia, and Japan ");
    		}
    		
    		if (countries == 5)
    		{
    			msg1+= ("China, Germany, Russia, Japan, and another third world country with terrorists ");
    		}
    		
    		if (countries == 6)
    		{
    			msg1+= ("China, Germany, Russia, Japan, France, and Mongolia ");
    		}
    		
    		if (countries > 6)
    		{
    			msg1+= (countries + " countries ");
    		}
    		
    		for (count = seconds; count > 0; count--)
    		{
    			msg +=(msg1 +"will be demolished in: " + count + '\n');
    			IO.showMsg(msg);
    			msg = new String("");
    		}
    		
    		IO.showMsg(msg1 + "are now destroyed" + '\n' + '\n' +
    					"The U.S. government has officially pwn3d you." + '\n' + '\n' +
    					"**** Cheney now owns all of your assets.  Thank you for your participation in this program.");
    		
    		System.exit(0);
    	}
    }
    well, what i want to kno is, instead of making a new IO.showMsg box appear, how can i make it count down to 0 with only the 1 box shoing up? is it even possible to do a thing like this with a time second delay?

    **i probably should have mentioned this is in java...srry about that guys.
    Last edited by munchy1988; 10-21-2004 at 07:34 PM.
    Asus S96J | ATi Mobility Radeon X1600 | T2500 Core Duo | 2 GB DDR2 667 Mhz

  2. #2
    Tiger Shark munchy1988's Avatar
    Join Date
    Sep 2002
    Location
    The Dirty Jerz
    Posts
    932
    anybody know how to make it count down in the same IO.showMsg?
    Asus S96J | ATi Mobility Radeon X1600 | T2500 Core Duo | 2 GB DDR2 667 Mhz

  3. #3
    Expensive Sushi cjohnson's Avatar
    Join Date
    Oct 2002
    Location
    North Carolina
    Posts
    35
    What is this "IO" class you refer to in your code? There's no import in what you posted, and no "IO" in java.lang, so telling whether or not you can do whatever it is you want to do with "one IO.showMsg box", is kind of hard.
    <wik> /bin/finger that girl in the back row of machines

  4. #4
    Tiger Shark munchy1988's Avatar
    Join Date
    Sep 2002
    Location
    The Dirty Jerz
    Posts
    932
    oo sorry....i forgot to mention that our school uses an IO.java file that is needed to compile so we can run windows, instead of using System.out.println().

    if u want the code for it, PM me, because the program is LONG and ill post it for you to compile. basically, i want only 1 System.out.println to change the seconds to what the current value would be after a 1 second delay.

    is there a delay function in java?
    Asus S96J | ATi Mobility Radeon X1600 | T2500 Core Duo | 2 GB DDR2 667 Mhz

  5. #5
    NullPointerException rock's Avatar
    Join Date
    Sep 2000
    Location
    York, PA
    Posts
    6,203
    What kind of delay? You can use Thread.sleep(int millis) to pause execution for a little while.

    Open Source is free like a puppy is free.

    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.

    Understanding Evolution

  6. #6
    Tiger Shark munchy1988's Avatar
    Join Date
    Sep 2002
    Location
    The Dirty Jerz
    Posts
    932
    i put in that thread.sleep to pause the IO.showMsg box, but it tells me "unreported exception java.lang.InterruptedException; must be caught or declared to be thrown". what do i need to run that thread.sleep function in my IO.showMsg box??

    ** this is what i did, and this is the only thing i did

    Code:
    for (count = seconds; count > 0; count--)
    		{
    			msg +=(msg1 +"will be demolished in: " + count);
    			IO.showMsg(msg);
    			Thread.sleep(50);
    			msg = "";
    		
    		}
    should i declare an int in the beginning ( int millis = 50; ), and then intead of 50, just put millis in the parenthesis?
    Last edited by munchy1988; 10-26-2004 at 05:20 PM.
    Asus S96J | ATi Mobility Radeon X1600 | T2500 Core Duo | 2 GB DDR2 667 Mhz

  7. #7
    NullPointerException rock's Avatar
    Join Date
    Sep 2000
    Location
    York, PA
    Posts
    6,203
    Thread.sleep() can throw an exception (a java.lang.InterruptedException to be specific). So you need to catch that exception in case it's thrown:

    Code:
    try {
        Thread.sleep(50);
    } catch (Exception e) {}
    This is allow it to compile. If it's interrupted, the empty catch block just lets execution to progress.

    Open Source is free like a puppy is free.

    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.

    Understanding Evolution

  8. #8
    Tiger Shark munchy1988's Avatar
    Join Date
    Sep 2002
    Location
    The Dirty Jerz
    Posts
    932
    Originally posted by rock
    Thread.sleep() can throw an exception (a java.lang.InterruptedException to be specific). So you need to catch that exception in case it's thrown:

    Code:
    try {
        Thread.sleep(50);
    } catch (Exception e) {}
    This is allow it to compile. If it's interrupted, the empty catch block just lets execution to progress.
    yay it works but only for a System.out.println() message...oh well. ill try to find why it doesnt work with an IO.showMsg box. im guessing because u have to click "ok" to go to the next box is why it wont work? ill try asking how to automatically click ok with the thread.sleep method.

    just as a question, when the System.out.println() prints the message, how do i get the box to clear before it goes to the next message? it just gets cluttered and confusing for the simple-minded when i show them this program
    Asus S96J | ATi Mobility Radeon X1600 | T2500 Core Duo | 2 GB DDR2 667 Mhz

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •