Tortoise and Hare Race

Hello!
I have the following code working on simulating the race of the "Tortoise and Hare."
Now, I would like to use its output coordinates to actually draw the shape.
What will be the best way to do that? Any new method, either separate of inner, will need access to the two variables, positionT and positionH.
I know the restrictions on the scope of these variables so I do not know where to use the paintComponent method.
Here is my code, thank you in advance:
// This program will simulate the infamous race of the Tortoise and Hare
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import javax.swing.Timer;
public class RacerTester
public static void main (String [] args)
//creates objects to be used by the methods
final Rectangle boxT = new Rectangle (1, 1, 1, 1);
final Rectangle boxH = new Rectangle (1, 1, 1, 1);
class Progress implements ActionListener
public Progress (int tortoise, int hare)
positionT = tortoise;
positionH = hare;
// this is where the action begins!
public void actionPerformed (ActionEvent event)
int t = (int) (1 + Math.random() * 9); // generates random numbers to determine the tortoise's position
// these are the rules for the movement of the tortoise in the race
boolean fastPlod = (t >= 1 && t <= 5);
if (fastPlod) positionT = positionT + 3;
boolean slip = ( t >= 6 && t <= 7);
if (slip && positionT > 0) positionT = positionT - 6;
boolean slowPlod = ( t >= 8 && t <= 10);
if (slowPlod) positionT = positionT + 1;
int h = (int) (1 + Math.random() * 9); // generates random numbers to determine the hare's position
// these are the rules for the movement of the hare in the race
boolean sleep = (h >= 1 && h <= 2);
if (sleep) positionH = positionH + 0;
boolean bigHop = (h >= 3 && h <= 4);
if (bigHop) positionH = positionH + 9;
boolean bigSlip = (h == 5);
if (bigSlip && positionH > 0) positionH = positionH - 12;
boolean smallHop = (h >= 6 && h <= 8);
if (smallHop) positionH = positionH + 1;
boolean smallSlip = (h >= 9 && h <= 10);
if (smallSlip && positionH > 0) positionH = positionH - 2;
// the rectangles will resize depending on the progress of the two contestants
boxT.setSize(1 + positionT, 1 + positionT);
boxH.setSize(1 + positionH, 1 + positionH);
System.out.println (boxT);
System.out.println (boxH);
System.out.println ("progress T:" + positionT + " progress H:" + positionH);
// who ever gets to scoring 70 points (the finish line) wins
if (positionT > 70) System.out.println ("Tortoise Wins!!!");
if (positionH > 70) System.out.println ("Hare Wins!!!");
if (positionT > 70 && positionH > 70) System.out.println ("They are Tied!!!");
if (positionT > 70 || positionH > 70) System.exit(0);
private int positionT;
private int positionH;
// this puts excitement to watch the progress of the tortoise and the hare; delays their motion
Progress listener = new Progress (1, 1);
final int DELAY = 1000;
Timer t = new Timer (DELAY, listener);
t.start ();
JOptionPane.showMessageDialog (null, "Bang!!! And They're Off!!!");
}

Normally I would be happy to help you, but after several years of trying to help here, I've decided not to contribute anymore because of the piss-poor way in which this site is being administered.
Others are still helping, but more may leave if things don't improve. May I recommend devshed or javaranch?
http://www.devshed.com/
http://www.javaranch.com/
If you would like to complain to the admins of this forum, either click the "Report Abuse" link or the "Feedback" link.
-- foofoo (shamelessly stolen the text from jverd).

Similar Messages

  • Ipad   apps black out after sync..just  games  ..when i  tap on  it ,just   flicker and it wont continue(black out),,other apps is  ok..pls  help..now  my  daugther is crying she cant play her smurf and hd race..pls help

    pls  help  us..   just   try  to   transfer   a  one movie   on ipad2 ,sync   it  thru itunes  and  when i finished    i cant    open any more my  games   or all
    applications,,   standard   apps     is ok   except  to all  games   we    purchase like   smurf  and   hd  race..screen  flicker   and  crash and  it wont  continue   ..pls   help  us
    tnx in advance

    Try downloading another app - any app - pick a free app and download it. See if that helps reset the iPad.
    If that doesn't work, then reboot the iPad. Hold down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple logo appears - ignore the red slider - let go of the buttons.

  • Differance between Oracle 9i RAC and 10g RAC

    Hello,
    I am almost new to RAC. I have worked on Oracle 9i RAC since longtime back. Now I am trying to find what is difference between Oracle 9i and 10g RAC structure ? Before it was CM and now it's clusterware. But what it makes different ? Any good explanation or web link.
    thanks
    ~Keyur
    null

    The main difference is 10g RAC is almost completely platform independent, and 9i RAC isn't.
    This means it has changed tremendously.
    As 9i is desupported I wouldn't spend any time in 9i RAC if you have yet to learn it.
    Sybrand Bakker
    Senior Oracle DBA

  • BODS and Oracle RAC

    Do we know of any problems with BODS and Oracle Real Application Clusters architecture? For example, a RAC TNS entry would specify one service name but multiple hosts for load balancing and failover. In BODS the connections are specified in many places (web console, datastores, job server). As far as I remember in some of those places we do have to enter the host name. Would this disqualify BODS from benefiting from RAC or would it (even worse) cause problems? Any official note by SAP on BODS and Oracle RAC?
    Thanks.

    Hi Mahir,
    As far as I know it's only the web console that requires the hostname, however I am using DS XI 3.1 and when selecting database type Oracle in the web console there is a checkbox for 'Oracle RAC'. If you check this box then you do not require to enter the hostname.

  • How to stop and start RAC Database

    Hi,
    Can anybody tell me How to stop and start RAC Database.
    Pls give me the exact procedure for OS - IBM Aix 5.3.
    Rajkumar

    Burleson,
    It so appears, as from the numerous times you have been published incorrect, untested information, and non-working scripts, you are not an Oracle guru,
    but only a self-proclaimed one.
    It also appears nothing on your 'CV' can be easily verified.
    You state you are an 'adjunct professor emeritus', however anyone who was kicked out after a few months can call himself a 'professor emeritus'.
    Looking at the enormous amount insults and slander you have posted directed to me and others on this forum, showing a highly unprofessional attitude toward your peers,violating this forums rules of conduct, don't you think you deserved to be banned completely?
    After all, you are always promoting your own publications here, which is also in violation of the rules for this forum.
    What makes you think that "Sybrand" is a man's name? How many male Sybrand's do you know? I don't know any, not one.
    That's your problem. I'm as much as male, as you are a fat, ugly, self-proclaimed Oracle-guru, which you are clearly not, you are only a fraud, and this glares from all of your publications.,
    Sybrand Bakker
    Senior Oracle DBA

  • 11gR2 Grid Infrastructure and 11gR2 RAC install as separate users (RH 5)

    We are about to set up a few new RH 5 clusters and are trying to make a decision if we should install 11gR2 Grid Infrastructure and 11gR2 RAC as the same user (oracle) or as separate users (grid and oracle) as per Oracle documentation.
    I would like to know what other people are doing and their experiences with this.
    Here are some concerns that we have:
    1) Does Oracle support has an 11gR2 cluster environment where grid infrastructure and oracle database are installed as separate users ? I have been to a few Oracle 11gR2 demos and they always have a simple install where everything is installed as a single user.
    2) Potential permission issues that we might hit iif we use separate users, for example
    - grid control agent - which user do we install it as and will it be able to access both grid and oracle files ?
    - database listener will run as grid user. Is this going to cause any permission issues ?
    Thanks in advance for your answers

    It is all dependent on your business whether your business needs to separate between privileged user for storage administrator (ASM) or database level. It is recommended to have user separation but not mandatory.
    see http://download.oracle.com/docs/cd/E11882_01/install.112/e17212/toc.htm for the details
    permission issues might happen if the configuration is not correct. for example you might see ORA-12537 when configuring the system
    Hope this helps

  • Can we run 11g RAC and 12c RAC in the same server?

    There is a requirement to run 11g RAC and 12C RAC in the same server for a year or so and then remove 11g RAC?
    Current setup:
    HP-unix 3 node RAC on 11g R2
    4CPU
    64 GB RAM
    3 TB SAN storage
    no ASM
    Upgrade setup:
    HP-unix 3 node RAC on 12C RAC
    8CPU
    128 GB RAM
    6+ TB SAN storage
    ASM
    We are asked to use the same server and upgrade Hardware to install and run 12C RAC. What are the implications of running RAC in the same server/nodes?
    Thank you for your time!

    Hi,
    The following table shows you the compatibility between various versions:
    Clusterware
    ASM
    DB
    Certified
    12.1
    12.1
    12.1
    Y
    12.1
    12.1
    11.2(a)
    Y
    12.1
    12.1
    11.1(a)
    Y
    12.1
    12.1
    10.2(a)
    Y
    11.2
    11.2(b)
    11.2
    Y
    11.2
    11.2(b)
    11.1
    Y
    11.2
    11.2(b)
    10.2
    Y
    11.1
    11.1
    11.1(c)
    Y
    11.1
    11.1
    10.2
    Y
    11.1
    11.1
    10.1
    Y
    11.1
    10.2
    11.1
    Y
    11.1
    10.2
    10.2
    Y
    11.1
    10.2
    10.1
    Y
    11.1
    10.1(d)
    11.1
    Y
    11.1
    10.1(d)
    10.2
    Y
    11.1
    10.1
    10.1
    Y
    10.2
    10.2
    10.2
    Y
    10.2
    10.2
    10.1
    Y
    10.2
    10.1(d)
    10.2
    Y
    10.2
    10.1
    10.1
    Y
    10.1
    10.1
    10.1
    Y
    (a) Pre-12.1 database instances require an ASM instance resident on the same node as the database instance. Pre-12.1 database instances cannot leverage the implicit HA of Flex ASM.
    Oracle Clusterware (CRS/GI) - ASM - Database Version Compatibility (Doc ID 337737.1)

  • I am unable to open some of apps, even one inbuilt app like camera, Example : regarding apps like Clash of clans and  Bike race TFG.whenever I try to open these games, it start opening and in middle of opening , it sent me back to home page of my mobile.

    I am unable to open some of apps, even one inbuilt app like camera, Example : regarding apps like Clash of clans and  Bike race TFG.whenever I try to open these games, it start opening and in middle of opening , it sent me back to home page of my mobile.Please help what to do ? and with camera when open it it open a blank Black page, please help ?

    You should really read the manual.  Click Support at the top fo this page, then click Manuals.
    You should be syncing to your computer regularly. Your game data is backed up when you sync.
    First try a restart.  This eraes nothing.
    If that does not solve, then try a reset.  This erases nothing.
    If this fails then try a restore

  • Want to upgrade 8.1.5 database into 10.2.0.2 and implement RAC.

    Hi,
    I have two different databases running on 8.1.5.0 and 8.1.7.4 and the size of databases are 110GB and 130GB.
    Now we want to upgrade this database into 10.2.0.2 and implement RAC.
    Could any one suggest the best way/document to upgrade database into 10g.
    Existing Platform is Sun Solaris 5.8(32 bits)
    New Platform is AIX 5.2(64 bits).
    Thanks

    Since the database is being migrated from Solaris to AIX, you cannot physically copy the database to the new server. You can choose to use Oracle's export and import utilities. This depends on much downtime you can afford. You can also create a new database on the AIX server and use CTAS (create table as select) to bring over your tables. This requires some additional post-migration work on your part to re-create the indexes, constraints, default values, etc. Export/import will do most of this for you.
    If you have the option to upgrade to Oracle 10gR2, another possibility is to upgrade your database on the Solaris server and use transportable tablespaces to create a new 10g database on the AIX server. Transportable tablespaces in 10gR2 allow you to migrate across operating systems. Be sure to review Oracle's certification matrix to ensure that you are installing Oracle database software on a certified platform.

  • Can Oracle 11g RAC and 10g RAC co-exists on same host

    Can somebody tell me if it is possible to have Oracle 11g and 10g RAC installed and configured on same host.
    Thanks,
    -Zubair

    user10948684 wrote:
    Can somebody tell me if it is possible to have Oracle 11g and 10g RAC installed and configured on same host.
    Thanks,
    -ZubairYou have to use 11G Clusterware , if you want to use 11g Database and you can use 10g Database as well.
    (You can not use 10g Clusterware and 11g Clusterware on the same host...)
    But you can use 10g Database and 11g Database on the same host, But you have to use 11G Clusterware.

  • Horse and bird race

    hi guys ,
    i've done a race between horse and bird , but the animation isn't repeatitive ,horse and bird race normaly but don't rebegin automatically
    the code is that:
    import flash.text.*;
    var largeur:uint = stage.stageWidth;
    var hauteur:uint = stage.stageHeight;
    // Calculer un ecart de 5% de la largeur de la fenêtre
    var ecart:uint = 40;
    //definir un container pour gerer la liste d'affochage
    var terrainCourse:Sprite=new Sprite();
    addChild(terrainCourse);
    // Définir un format d'écriture, police "Impact", coprs 20, couleur rouge
    var format:TextFormat = new TextFormat("Impact", 16, 0xffffff);
    // Définir le compteur de participants
    var cptrParticipant:uint=0;
    // Boucle do-while
    // Définir le nombre d'horse maximum
    var nbhorse:uint = 3;
    // Définir le compteur d'horsex
    var cpthorse:uint = 0;
    // Faire
    do {
        // Créer une occurrence horse
        var horse:horseClp = new horseClp();
        // Positionner  l'horse en dehors de la scène, à gauche
        //  La position des horse est calculée au hasard dans un intervalle de
        //  0 à 40 pixels pour x
        //  hauteur / 4 et  3*hauteur/4 pixels pour y
        horse.x = horse.width+ Math.random()*ecart;
        horse.y =  hauteur/4 + Math.random()*hauteur/2;
        // Chaque horse possède sa propre vitesse calculée au hasard entre 2 et7
        horse.vitesse = Math.random()*20+5;
        //  Les horsex ne sont pas synchronisés, on calcule au hasard l'image de départ de l'animation du clip
        var imageDeDepart:uint = Math.random()*horse.totalFrames;
        horse.gotoAndPlay(imageDeDepart);
        // Afficher l'horse
         terrainCourse.addChild(horse);
        // Placer un numéro sur l'horse et l'afficher sur l'horse
        //  Créer un champ de texte
        var dossard:TextField = new TextField();
        // Modifier le format de texte par défaut
        dossard.defaultTextFormat = format;
        // Positionner le champ de texte au centre du clip
        dossard.x=-horse;
        dossard.y=-5;
        //  Numéroter l'horse en fonction du compteur de participant
        dossard.text =cptrParticipant ;
        // Afficher le champ de texte sur l'horse
        horse.addChild(dossard);
        //le cheval se deplace sur event.ENETR_FRAME
        //horse.addEventListener(Event.ENTER_FRAME,bouge);
        //le cheval affiche son numerosur event.complete
        horse.addEventListener(Event.COMPLETE,arrete);
        // Passer à l'horse suivant
        cpthorse++;
        cptrParticipant++;
    // Tant que le compteur d'horse est plus petit que le nombre maximum  d'horse
    } while ( cpthorse < nbhorse);
    // Boucle while - initialisation du compteur
    var cptoiseau:uint = 0;
    var nboiseau:uint =3;
    // Tant que le compteur d'oiseau est plus petit que le nombre maximum  d'oiseau
    while (cptoiseau < nboiseau) {
        // Créer une occurrence oiseau
        var oiseau:oiseauClp = new oiseauClp();
        // Positionner  l'agneau en dehors de la scène, à gauche
        //  La position des agneau est calculée au hasard dans un intervalle de
        //  0 à 40 pixels pour x
        //  ecat et hauteur / 4 et  3*hauteur/4 pixels pour y
        oiseau.x = oiseau.width +Math.random()*ecart ;
        oiseau.y = Math.random()*hauteur+ecart;
        // Chaque oiseau possède sa propre vitesse calculée au hasard entre 2 et7
        oiseau.vitesse = Math.random()*7+2;
            //  Les agneaux ne sont pas synchronisés, on calcule au hasard l'image de départ de l'animation du clip
         imageDeDepart = Math.random()*oiseau.totalFrames;
        oiseau.gotoAndPlay(imageDeDepart);
        // Afficher l'agneau
        terrainCourse.addChild(oiseau);
        //  Numéroter l'oiseau en fonction du compteur de participant
        //  Créer un champ de texte
        dossard = new TextField();
        // Modifier le format de texte par défaut
        dossard.defaultTextFormat = format;
        // Positionner le champ de texte au centre du clip
        dossard.x=oiseau.width/4-10;
        dossard.y=-10;
        //  Numéroter l'agneau en fonction du compteur de participant
        dossard.text =cptrParticipant ;
        // Afficher le dossard sur l'agneau
        oiseau.addChild(dossard);
        //le cheval se deplace sur event.ENETR_FRAME
        oiseau.addEventListener(Event.ENTER_FRAME,bouge);
        //le cheval affiche son numerosur event.complete
        oiseau.addEventListener(Event.COMPLETE,arrete);
        // Passer à l'oseau suivant et au participant suivant
        cptoiseau++;
        cptrParticipant++;
    //definir un gestionaire d'evenement
        function bouge (e:Event):void {
            var cible:MovieClip=e.currentTarget as MovieClip;
            //la position du clip se deplace sur l'axe des x de vitesseAgneau a chaque fois
            cible.x +=cible.vitesse;
            if (cible.x>largeur) {
                cible.dispatchEvent(new Event(Event.COMPLETE));
    function arrete (e:Event) {
        var cible:MovieClip=e.currentTarget as MovieClip;
        trace("je suis sorti   !!!");
    for (var i:uint = 0; i < terrainCourse.numChildren; i++) {
            //  Récupérer le clip  enregistré au niveau i,  l'enregistrer dans tmp
            var tmp:MovieClip = terrainCourse.getChildAt(i);
            //  Supprimer l'écouteur d'événement Event.ENTER_FRAME
            tmp.removeEventListener(Event.ENTER_FRAME, seDeplace);
            //  Supprimer l'écouteur d'événement Event.COMPLETE
            tmp.removeEventListener(Event.COMPLETE,sArrete);
            // Placer  le clip en bas à gauche et stopper l'animation
            tmp.x = tmp.width +Math.random()*ecart ;
            tmp.y =  hauteur - tmp.height  -Math.random()*ecart;
            tmp.gotoAndStop(0);
        // La cible est le premier élément qui a reçu l'événement Event.COMPLETE,
        // Tous  les clips étant stoppés et  déplacés en bas à gauche, ils ne pourront  plus émettre d'événement Event.COMPLETE
        //  Placer la cible au centre et jouer son animation
        cible.x = largeur/2;
        cible.y = hauteur/2;
        cible.play();
        // Afficher  un message pour le gagnant
        var gagnant:BulleClp = new BulleClp();
        gagnant.labelOut.text = "J'ai gagné ! \nJ'ai gaaaaaa...\n ....   gnéééé !! ";
        gagnant.x =  largeur/2;
        gagnant.y =  hauteur/2-10;
        addChild(gagnant);
        // Afficher un message pour le perdant
        var perdant:BulleClp = new BulleClp();
        perdant.labelOut.text = "Booouhouu ...\n... hou ...\n ...  hooou !!!";
        perdant.x = 3.5* ecart ;
        perdant.y =  hauteur - 3.5*ecart ;
        addChild(perdant);
    [Moved by moderator to more appropriate forum]

    When the "race" is over do you reposition the actors? (horse & bird)
    as far as I've seen you are just moving those but not repositioning when the race is over.
    Sorry my french is bad so I couldn't really understand all your code comments

  • HT5858 I am unable to open some of my apps, apps which I am unable to open were Clash of clans and  Bike race TFG.whenever I try to open these games, it start opening and in middle of opening , it sent me back to home page of my mobile. Please help what t

      I am unable to open some of apps, even one inbuilt app like camera, Example : regarding apps like Clash of clans and  Bike race TFG.whenever I try to open these games, it start opening and in middle of opening , it sent me back to home page of my mobile. Please help what to do ?and with camera it open a blank black page ...... Please help ?

    AmishCake has given you the correct steps for this issue.  What is probably happening is you have too many apps running in the background or the ones that you have open are conflicting in some way with the one you are trying to use, so closing everything out and a good reboot should resolve it.
    Also, make sure your device is updated and all the apps are updated.   Sometimes when the app is updated and the iOS is not, can cause behaviour like this.
    If it continues, back up your device and restore it.
    http://support.apple.com/kb/ht1414

  • Running 9i RAC and 10g RAC on the same physical cluster

    We are planning to run 9i RAC ( with OCFS2 ) and 10g RAC ( ASM ) on the same cluster with 4-Nodes.
    I will really appreciate if any of the forum members can share the information and experiences if the have done such implementation. We are currently running six 9i R2 clusters and are in the process of migrating them. The current need is to make the 9i and 10g cluster co-exist up to a certain point.
    Thank You,
    Madhu

    Yes this is possible.. you may want to check out some papers relating to this on OTN and on the RAC SIG website at www.oracleracsig.org.

  • Accessing and Managing RAC 10g database with 9i OEM

    can i Access and Manage RAC 10g database with 9i OEM? If yes How?

    9i EM can 'see' a 10g database and perform some basic functions (rsp. all what is known to 9i). But it cannot manage any 10g functionality , because it doesn't know it. So such a constellation doesn't make really sense. On the other hand 10g EM can manage 8i,9i and 10g databases.
    Werner

  • Install SAP ERP 6.0 with Linux and Oracle RAC

    Hi Guru,
    I want to install SAP ERP 6.0 with Linux and Oracle RAC. Is this possible?
    Where do I find information?
    Thanks,
    Hugo.

    Hello Hugo,
    You can use either RAC or dataguard. On note [105047|http://service.sap.com/sap/support/notes/105047]:
    14. Data Guard
        o  You can use "Physical Standby".
        o  You cannot use "Logical Standby".
        o  You can use Data Guard Broker.
        o  You can use Maximum Performance Mode, Maximum Availability Mode and Maximum Protection Mode.
        o  In the case of Maximum Availability and Maximum Protection, you must pay particular attention to a fast network connection in order to avoid performance problems.
        o  Maximum Protection causes the primary database to terminate if problems occur in the standby database.
    60. Real Application Cluster (RAC)
        o  You can use this feature in accordance with Note 527843.
    Regards,
    Eduardo Rezende

Maybe you are looking for

  • Using Instr in Cursors or Loops...?

    Can anyone suggest me how to use "Instr" to find one parameter string in another parameter string, finding if one string is present in another using loops..?? Edited by: user11339127 on Jul 1, 2009 11:04 PM

  • Compatibility APPLE TV (2ndG) & AIRPORT EXPRESS (A1084) ??

    Just to make sure: I have iTunes library on the MacBook. AEX is model A1084 (old model) Select my AEX wifi network from my MacBook Airport AppleTV will detect the same wifi network provided by my old AEX A1084 model?? So my MacBook and AppleTV would

  • Tagging TextFrames With InDesign Server - not showign in desktop?

    Hi all, Ive come across a weird issue with marking up text frames with InDesign Server (CS3) whilst processing xml rules during an xml import. I run the following code on desktop it works fine. When run on server, it works apart from the frames will

  • Event map problem in 10.1.2.0.2

    I'm trying to post two messages with identical structures to an AQ adapter. In iStudio I can select event map to direct the message to the correct event based on the content of one field (Action, 'I' for insert, 'U' for update). The problem is that w

  • Reverse Engineering Synonym from Oracle data base

    Hi All I am using ODI 10.1 i want to reverse engineer synonames from my oracle database . When i am reverse engineering the tables and views the datastore is showing the Columns in Columns tab. But for Synonyms the the Column names are not available.