Number game

please help with this, if you can...I need to write a JAVA program to implement the secret number game. the program should create and store a random number between 1 and 10, inclusive. It should then prompt the user to guess the number. accepting user input, it should determine whether or not the guess was correct. If correct, it should print a contratulatory message and terminate. If the guess is incorrect, the program shoulod display a hint indicating that the guress was either too low ot too high. The program must validate user input. If the user enters a non-integer, it should be caught and output. If the user enters a guess outside of the valid range, an appropriate error message should be displayed either way, the user is then reprompted for a new guess.

hi, i am giving you the code, with the specifications you have asked for, check for them, by running the code, and it will look nice if you implement this idea, to transform this code to an user interface using applets.
import java.io.*;
import java.util.Random;
public class numberGame {
     public static void main (String args []) {
          boolean myBoolean = true;
          Random rand = new Random();
          int k = rand.nextInt(11);
          do{
               try {
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          System.out.println("Hi, Welcome to the secret game");
          System.out.println("Guess The Number");
          String str="";
          str = br.readLine();
          str.trim();
          System.out.println("you have entered this "+ str);
          int i =0;
          i = new Integer(str).intValue();
          numberGamePerform(i,k,myBoolean);
     }catch(Exception e){
          System.out.println("Error");
     } while (myBoolean!=false);
     public static void numberGamePerform(int i,int k,boolean myBoolean) {
          //System.out.println("My Guess "+k);
          if( i == k ) {
          System.out.println("Good Guess, Congratulations");
          myBoolean = false;
          System.exit(0);
          else {
               System.out.println("Back Luck , Give it another Try");
               myBoolean = true;
               if(i<=2 && k>=8)
               System.out.println("Input Guess too low");
               else if (i >= 8 && k <= 2)
               System.out.println("Input Guess too high");
               else {
                    if((k>2&&k<=4)&&(i>=5&&i<8))
                    System.out.println("Guess relatively close but lies in the other half");
                    else
                    System.out.println("very close");
               //if(i)

Similar Messages

  • Name of this antique wooden number game

    HI I have this antique number game made by and artist in mosaik wooden piece but i would like to know what is the name of this game. Thanks for any infos.Bruno

    I found one just like it on ebay.com, vintage primitive slide game?  http://www.ebay.com/itm/Vintage-Primitive-Wooden-Slide-Number-Games-2-Wooden-Dice-/191556617224?hash=item2c99aa0408&nma=true&si=6nTws3pKvnhCRsxQJLp2ohcGvlQ%253D&orig_cvip=true&rt=nc&_trksid=p2047675.l2557 

  • Java number game confused help any1!

    The following simple game is played between a player and the computer. At the
    start the player enters either the number one or two on the keyboard (the computer will also
    choose either one or two at random). Then the computer draws two numbers between one and
    one hundred at random. The human player wins if the number in position corresponding to the
    number he selected is bigger than the number in position corresponding to the number chosen by
    the computer. If the two numbers are the same (either because the player and the computer chose
    the same value or because the random numbers in the chosen positions are the same) the game
    ends in a draw. The code doen't work properly it etiher comes up with computer wins and draw at the same time! Also i need to display the numbers that are generated randomly can anyone help my code:
    import java.lang.Object;
    import java.lang.System;
    import java.io.InputStream;
    import java.util.Scanner;
    class javataex1 {
    public static void main(String[] args) {
    // declarations
    Scanner input = new Scanner (System.in);
    int human ;
    int computer;
    int Number1;
    int Number2;
    //instructions
    Number1=(int) Math.ceil(100*Math.random());
    Number2=(int) Math.ceil(100*Math.random());
    computer=(int) Math.ceil(2*Math.random());
    System.out.print("Enter number 1 or 2: ");
    human = (input.nextInt());
    if (human!=1 && human!=2)
    System.out.println("you entered wrong number");
    else
    if (human==computer)
    System.out.print("Draw");
    else
    human=Number1;
    computer=Number2;
    if (human==computer)
    System.out.print("Draw");
    else
    if (human>computer)
    System.out.print("Human wins");
    else
    if (computer>human)
    System.out.print("Computer wins");
    }

    Crosspost
    http://forum.java.sun.com/thread.jspa?threadID=5245168&tstart=0
    Only post on one forum at a time, please. I think someone answered you in the other thread anyway.
    Illu

  • Random number game

    I am writing a random numbre game which produces 6 random numbers which all must be different and within a certain range. Currently all I can get output is 6 numbers where I have duplicates e.g.
    6
    6
    6
    36
    45
    32
    How do I make the 6 numbers different ?
    Here's a small sample of the code to give you the basic idea:
    import java.util.*;
    public class Random
    private String rNumber;
         public Random()
         String[] numlist = new String[2];
    numlist[0] = "1";
    numlist[1] = "2";
    Random rand = new Random();
         int x = (int) (0 + (Math.abs(rand.nextInt()) % 1 )) ;
         rNumber = number[x];
         public String getrNumber()
         return rNumber;
    public static void main(String args[])
         for (int i=0; i<6; i++){
         String rn;
         Random num = new Random();
    rn = num.getrNumber();
    System.out.println(rn);
    }

    Use a simple if statement that calls a method that will return a boolean value based on the random number generated(and now in english).
    (1)Generate your number.
    (2)Use the number as a parameter to a method.(This method checks to see if the number is already in the data structure(array,stack, whatever).
    /** Checks if the given number is already contained in the given array **/
    public boolean isDuplicate(int num,int[] array) {
    // I have passed an array just to make it clearer.
    for(int i=0;i<array.length;i++) {
    if(array[i] == num) return true;
    return false; // if the number is not a duplicate we know it is okay to put in our array.
    // remember to keep some kind of reference to the array position.
    (3) Now we just put this in the next number position in our array.
    Hope this helps, by the way you wouldn't be trying to generate some numbers for a Lottery would you?(I remember when I tried that and guess what-yeah still broke)
    Also call it something like RNGenerator not Random as this is already a Java class and it becomes a nightmare.

  • Connecting my GUI class to my Game class

    Hi guys I build my GUI with netBeans 6.0 and I used a seperate source package for my number game and for my GUI. Now I know I have to make one of the main classes extending an Action Listener but I don't know which one the main class of the game or the main class of the GUI. And is it possible to connect them if they are in seperate packages, although I assume everything is possible. Thanks in advance!

    The problem is solved.

  • Problem reinstalling FB4 premium after installing CS5 MC on windows 7 64-bit

    Hello,
    I was hoping that I could get some help with an issue -- I filed a technical request (ticket)  with Adobe but also wanted to reach out here.
    Background:
    I installed FB4 Premium in March, and had no issues with the download or install -- everyhting had been working fine. Yesterday I installed CS5 MC and in the process of installing it over-wrote the debug versions of flash player that come in FB4 premium with standard flash player. Naturally,that won't work with FB4 so I needed to find a way to reinstall the debug version of flash player plug-in and active x. After trying unsuccessfully for while to do so, I decided it would just be easier to uninstall and reinstall the FB4 download which I still had on my machine, as this comes with the debug players I need. Big mistake. Now I can't get FB4 to reinstall. I am getting the following error messages while running the install set-up (see uploaded image of error message below). Any thoughts at all on how I can resolve this? I did try several reboots, new installs and even re-downlaoded FB4 again from the Adobe store. It appears the presecne of MC5 has caused this somehow?? I run windows 7 64-bit pro. By the way, I did figure out (too late) the way to reinstall the debug flash player -- I first needed to run a script to delete the existing flash player rather than just uninstall it; if anyone needs the script or help on that let me know.
    hanks very much -- this has me stumped.
    Bob

    Hello Chris,
    Thank you very much for this insight. It worked. Now I just have a few issues around getting a shortcut for FB4 on the desktop and fixing the FB4 app icon (which now shows up as blank). But it is running as FB4 premium -- Thank you so much!! I have also sent an email to the Adobe engineers working on this case.
    I realized that my big mistake was thinking that I needed to reinstall FB4 premium standalone to get FB4 premium to work -- but this was not possible (due to how CS5 installer works) and not needed (because CS5 has all of the code needed to run FB4 premium). The answer (as you described) was simply to go abck to the CS5 installer let it install FB4. While CS5 would initially install FB4 as standard, the serial number "games" described here and in other posts would allow me to upgrade to to FB4 premium. It now works as FB4 premium!
    Thank you Chris,
    Bob Avena

  • Question i can't answer

    QUESTION
    write an APPLET that plays the "guess the number" game as follows: the program chooses the number to be guessed at by selecting a random integer in the range 1 to 1000. The applet displays the prompt 'Guess a number between 1 and 1000' next to a JTextField. The player types a first guess into the JTextField and presses the Enter key. If the player's guess is incorrect, your program should display "Too high. Try again" or "Too low. Try again" in the status bar to help the player 'zero in' on the correct answer and should clear the JtextField so the user can enter the next guess.
    When the player enters the correct answer, display one of the following messages, depending on how many attempts the player took to get the answer right: If the number of guesses was fewer than 10, print "Congratulations. You guessed the number in n guesses - either you know the secret or got lucky!" where n is the actual number of attempts taken. If the number of guesses was exactly 10, print "Congratulations. You guessed the number in 10 guesses". If the player takes more than 10 guesses, print "You took n guesses. You should be able to do better!" again, where n is the actual number of attempts taken.
    once the application is working, modify it to allow the player to enter their first name and the number range to use (e.g., 1 - 100, 20 - 2000, etc...) Change the output to display the player's name as well as the appropriate output message. Calculate the number of guesses that a player should take to find the random number given the inputted range, and use this value, rather than 10, when deciding which of the three final output messages to display when the player successfully guesses the random number.
    COMMENT
    i have tried starting but have gotten in a muddle, this is how it is, if anyone is able to finish it off for me would b really grateful
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    public class guessnumber extends Applet implements Runnable, ActionListener
    int Count = 0;
    String msg;
    Thread t = null;
    int state;
    boolean stopflag;
    private Label l1, l2;
    private TextField t1, t2;
    private Button b1;
    private int num, mynum, diff, red, blue, green, chance = 0;
    private Color c;
    public void init()
    c = new Color( 0, 80, 0 );
    setForeground( c );
    l1 = new Label("I have kept a number between 1 and 1000.");
    l2 = new Label("Can you guess this number?");
    t1 = new TextField(10);
    t2 = new TextField(10);
    b1 = new Button("Play Again");
    t2.setEditable(false);
    add(l1);
    add(l2);
    add(t1);
    add(t2);
    add(b1);
    t1.addActionListener(this);
    b1.addActionListener(this);
    num = 1 + (int) (Math.random()*1000);
    public void start()
    msg = getParameter( "Guess The Number?" );
    if(msg == null)
    msg = "Martin Surridge";
    msg = " " + msg;
    t = new Thread( this );
    stopflag = false;
    t.start();
    public void run()
    char ch;
    for( ; ; )
    try
    repaint();
    Thread.sleep(200);
    ch = msg.charAt(0);
    msg = msg.substring( 1, msg.length() );
    msg += ch;
    if(stopflag)
    break;
    catch( InterruptedException e)
    System.out.println( "Exception" + e );
    public void stop()
    stopflag = true;
    t = null;
    public void paint(Graphics g)
    setForeground(java.awt.Color.black);
    g.drawString( msg, 70, 130 );
    public void actionPerformed( ActionEvent ae )
    if( ae.getSource() == b1 )
    red = 255;
    blue = 255;
    green = 255;
    c = new Color(red, green, blue);
    setBackground(c);
    num = 0;
    num = 1 + (int) (Math.random()*1000);
    chance = 0;
    showStatus( "" );
    t1.setEditable(true);
    t2.setEditable(false);
    t1.setText("");
    t2.setText("");
    else
    mynum = Integer.parseInt(t1.getText());
    chance++;
    if( chance == 1 )
    showStatus( chance + " chance over" );
    else
    showStatus( chance + " chances over" );
    if( chance >= 9 )
    t1.setText( String.valueOf(num) );
    showStatus( "Your 9 chances are up" );
    t1.setEditable( false );
    diff = num - mynum;
    if(diff == 0)
    setBackground(Color.pink);
    t1.setEditable(false);
    t2.setText("You've done it");
    t2.setEditable(false);
    else if(Math.abs(diff)>200)
    if(diff>0)
    t2.setText("Too Low");
    else
    t2.setText("Too High");
    else if(Math.abs(diff)<200)
    if(diff>0)
    red = 255-diff;
    green = 0;
    blue = 0;
    c = new Color(red, green, blue);
    t2.setText("");
    setBackground(c);
    else if(diff<0)
    red = 0;
    green = 0;
    blue = 255 + diff;
    c = new Color(red, green, blue);
    t2.setText("");
    setBackground(c);
    if (Count < 10) System.out.print ("Congrats.. you took less than 10 chances");
    else
    if (Count == 10) System.out.print ("Congrats .. you just made it");
    else
    System.out.print ("you need practice");
    }

    No, not really, i have done most of it, i just wanted someone to check it over for me if there is anything MISSING or left out

  • How to change the Hello Portlet in Jetspeed2 Demo

    hi ppl,
    I am having a big problem..
    I can't change the portlet title, hello portlet, in the jetspeed 2 demo.
    The strange things is that i am able to change the title of the pickANumber portlet.
    @ Portlet.xml
    <portlet id="PickANumberPortlet">
    <init-param>
    <name>ViewPage</name>
    <value>/WEB-INF/demo/simple/PickANumber.jsp</value>
    </init-param>
    <init-param>
    <name>HelpPage</name>
    <value>/WEB-INF/demo/simple/PickANumberHelp.jsp</value>
    </init-param>
    <init-param>
    <name>EditPage</name>
    <value>/WEB-INF/demo/simple/PickANumberEdit.jsp</value>
    </init-param>
    <portlet-name>PickANumberPortlet</portlet-name>
    <display-name>Pick a number game</display-name>
    <portlet-class>org.apache.jetspeed.demo.simple.PickANumberPortlet</portlet-class>
    <expiration-cache>-1</expiration-cache>
    <supports>
    <mime-type>text/html</mime-type>
    <portlet-mode>VIEW</portlet-mode>
    <portlet-mode>HELP</portlet-mode>
    <portlet-mode>EDIT</portlet-mode>
    </supports>
    <supported-locale>en</supported-locale>
    <supported-locale>fr</supported-locale>
    <supported-locale>ja</supported-locale>
    <resource-bundle>org.apache.jetspeed.demo.simple.resources.PickANumberResources</resource-bundle>
    <portlet-info>
    <title>Change TITLE</title>
    </portlet-info>
    <portlet-preferences>
    <preference>
    <name>TopRange</name>
    <value>100</value>
    </preference>
    </portlet-preferences>
    </portlet>
    See.. i just replace that data in the portel-info/title.. and it changes the title in the pickANumber portlet change..
    But strange! i can't do the same way for the hello portlet
    Can someone tell me how to change the title in the hello portlet...
    Pls help.. i am running out of time!

    The hello portlet uses the title string in property file, thus you may need to modify the file "demo\WEB-INF\classes\org\apache\jetspeed\portlet\helloworld\resources\HelloWorldResources_en.properties" to change its title.

  • User input in loop

    For some reason I could not find information about user input in the first chapters of my programming book, therefore I decided to find out on my own. using google gave me a few hints, but I cannot figure out how to solve this problem: when trying to assign the same variable a new value I get a error. how would you solve this?
    program:
    package henke;
    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
           System.out.println("\n\n\t\t\tWelcome to the 'guess my number' game!\n");
           while(true){
               System.out.println("\nChose your option: \n" +
                   "1\) Guess the random number!\n" +
                   "2\) Make the computer guess your number!\n" +
                   "3\) Exit\n");
               int option;
               Scanner in = new Scanner(System.in);
               System.out.print("Your option: ");
               option = in.nextInt();
               in.close();
               if(option == 1){
                   System.out.println("Not built yet. ");
               else if(option == 2){
                   System.out.println("Will be built last. ");
               else if(option == 3){
                   break;
               else{
                   System.out.println("Illegal option.. ");
    }output including error messages:
    run:
                            Welcome to the 'guess my number' game!
    Chose your option:
    1) Guess the random number!
    2) Make the computer guess your number!
    3) Exit
    Your option: 1
    Not built yet.
    Chose your option:
    1) Guess the random number!
    2) Make the computer guess your number!
    3) Exit
    Exception in thread "main" java.util.NoSuchElementException
            at java.util.Scanner.throwFor(Scanner.java:838)
            at java.util.Scanner.next(Scanner.java:1461)
            at java.util.Scanner.nextInt(Scanner.java:2091)
            at java.util.Scanner.nextInt(Scanner.java:2050)
            at henke.Main.main(Main.java:18)
    Your option: Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)

    thanks for the links. some googling made it possible for me to finish this script. It might be somewhat messy since I have just written it (no complaints about the output though). and oh, I didn't finish the 'while ... and ...' loop somwhere in there since I didn't have the energy. I should really go to sleep now. bye
    package javaapplication;
    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
        System.out.println("\n\n\t\t\tWelcome to the 'guess my number' game!\n");
    //    Startup delay
        System.out.print("|");
            for(int i = 0; i <= 30; i++) {
                 System.out.print("=");
                 try {
                     Thread.sleep(300);
                 catch (InterruptedException ie){
        System.out.println("|\nJob's done!");
                //Den stora loopen
           while(true){
               System.out.println("\nChose your option: \n" +
                   "1) Guess the random number!\n" +
                   "2) Make the computer guess your number!\n" +
                   "3) Quit\n");
               Scanner in = new Scanner(System.in);
               System.out.print("Your option: ");
               int option = in.nextInt();
               //in.close();
               //Guess the random number!
               if(option == 1){
                   System.out.print("Number of possibilities: ");
                   int numPosA = in.nextInt();
                   int secretA = (int)(Math.random()*numPosA);
                   int iA = 0;
                   while(true){
                       iA++;
                       System.out.print("Your guess: (between 0 and "+ (numPosA -1)+ ") ");
                       int guessA = in.nextInt();
                       if(guessA == secretA){
                           System.out.println("Correct! The secret number is "+ secretA+
                                   " - you guessed "+ guessA+ "! It only took you "+ iA+
                                   " guesses!");
                           System.out.println("\nPress enter to return to the main menu. ");
                           try {
                               System.in.read();
                           } catch (java.io.IOException ie) {}
                           break;
                   else if(guessA > secretA){
                       System.out.println("To high. Try again. ");
                   else if(guessA < secretA){
                       System.out.println("To low. Try again. ");
                   else{
                       System.out.println("Illegal option. ");
               //Make the computer guess your number!
               else if(option == 2){
                   System.out.print("Number of possibilities: ");
                   int numPosB = in.nextInt();
                   //while(secretB >= 1) and (secretB <= numPosB){
                   System.out.print("The secret number: (has to be between 1 and "
                           + numPosB+ ") ");
                   int secretB = in.nextInt();
                   int iB = 0;
                   while(true){
                       iB++;
                       int guessB = (int)(Math.random()*numPosB+1);
                       if(guessB == secretB){
                           System.out.println("The computer figured out your secret number! "+
                                   "The computer guessed "+ guessB+ " - and your secret number is "+
                                   secretB+ ". It took "+ iB+ " random numbers!");
                           System.out.println("\nPress enter to return to the main menu. ");
                           try {
                               System.in.read();
                           } catch (java.io.IOException ie) {}
                           break;
                       else if(iB >= numPosB * 2){
                           System.out.print("The computer has guessed "+ (numPosB * 2)+ " times."+
                                   "no more chances!");
                           System.out.println("\nPress enter to return to the main menu. ");
                           try {
                               System.in.read();
                           } catch (java.io.IOException ie) {}
                           break;
               //Quit
               else if(option == 3){
                   break;
               //Else
               else{
                   System.out.println("Illegal option.. ");
    }

  • Please please help. I need to get this code working ASAp

    hi! right, I am a java dunce. I am doing a web design degree at uni and annoyingly have to take a programming module. I just don't get it one bit and the lecturer is a sadist and won't help. I have tried countless books and what not but it all goes over my head.... to the problem
    We were given some code for a "guess the number" game. it generates a random number between 1 and 1000. You then have to guess the number. If you guess higher it should output "you ned to guess higher" and visa versa. Also if you enter 0 it should exit the program (which it does)
    The code had logical and syntax erros in it most of which I think I have managed to find but it still does not work and I have been at this for hours now (even my headache has a headache)
    It compiles now but when you enter a number the program just spits out the line "Enter your guess, from 1 to 1000 inclusive (0 to quit):" again but doesn't tell you if you should go higher or lower.
    I can only get it to spit out the "you need to guess lower" line if you enter a number above 1000 which is wrong.
    please please help me. Just point me in the right direction or something but please use novice language or I think I might have to go jump of the nearest peir.
    The code I have so far is:
    import java.util.*;
    public class guessgame2
    public static void main(String[] args)
    // Declare variables, setup keyboard input and the
    // random number generator
    int game_number, user_number;
    String continue_pref;
    Scanner data_input = new Scanner(System.in);
    Random generate = new Random();
    do
    // Generate game number
    game_number = generate.nextInt(999) + 1;
    // The following line is a debug line, comment out
    // for real game.
    // System.out.printf("Game number:%d%n", game_number);
    // Get users first guess
    System.out.print("The computer has generated a number.");
    do
    System.out.printf("%nEnter your guess, from 1 to 1000 inclusive (0 to quit):");
    user_number = data_input.nextInt();
    } while ((user_number >= 1) && (user_number <= 1000));
    // While user has not guessed right and does not want to quit
    while ((user_number == game_number) || (user_number != 0))
    if (user_number > game_number)
    System.out.printf("You need to guess lower%n");
    else
    System.out.printf("You need to guess higher%n");
    // Get users next guess
    do
    System.out.printf("%nEnter your guess, from 1 to 1000 inclusive (0 to quit):");
    user_number = data_input.nextInt();
    } while ((user_number >= 1) && (user_number <= 1000));
    if (user_number == game_number);
    // User has guessed right
    System.out.printf("%nYou guessed correctly, well done.%nDo you want to play again (y/Y)=Yes: ");
    continue_pref = new String(data_input.next());
    if (user_number == 0)
    // User wants to quit
    continue_pref = new String("No");
    } while (continue_pref.equalsIgnoreCase("N"));
    } (thankyou)

    Is this posted in two different sections of the forum? Oh well... here you
    are, would be a good idea to do as WIlfred_Death suggested and write
    out what you need your program to do, then put them in the order for
    them to work, and then convert your notes to code, and then you get
    like so....
    import java.util.*;
    import java.io.*;
    public class guessgame2{
         public static void main(String[] args) throws IOException{
              BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in));
              Scanner data_input = new Scanner(System.in);
              Random generate = new Random();
              int game_number, user_number;
              String continue_pref = "Y";
              Boolean done = false;
              int max = 1000;
              int min = 1;
              System.out.println("Would you like to play my guessing game?(y/n) ");
              continue_pref = userIn.readLine();
              continue_pref = continue_pref.trim();
              game_number = generate.nextInt(999) + 1;
              //System.out.println(game_number);//--->UNCOMMENT THIS IF YOU WANT TO DISPLAY game_number<---
              /*-----Run program while user agrees to-----*/
              while(continue_pref.equalsIgnoreCase("Y")){
                   /*-----Let user guess until they win or choose to quit-----*/
                   while(!done){
                        System.out.println("Enter your guess, from 1 to 1000 inclusive(0 to quit):");
                        user_number = data_input.nextInt();
                        /*-----check if user wants to quit-----*/
                        if(user_number==0){
                             continue_pref = "n";
                             done=true;
                        else{
                             /*-----Check if user won-----*/
                             if(user_number==game_number){
                                  System.out.println("Congradulations you've won! Would you like to continue(y/n)?");
                                  continue_pref = userIn.readLine();
                                  continue_pref = continue_pref.trim();
                                  /*-----If user wants to play again,
                                            regenerate game_number-----*/
                                  if(continue_pref.equalsIgnoreCase("n")){
                                       done=true;
                                  else{
                                       game_number = generate.nextInt(999)+1;
                                       //System.out.println(game_number);//--->UNCOMMENT THIS IF YOU WANT TO DISPLAY game_number<---
                             }/*-----Check if user number is lower-----*/
                             else if(user_number<game_number){
                                  System.out.println("You need to guess higher!\n");
                             else{/*-----Number must be higher-----*/
                                  System.out.println("You need to guess lower!\n");
    }

  • Applescript beginner help

    Hi
    I am a new to applescript. I thought making a mini game using applescript might be a good starter. I know some of the basic commands.
    Anyway, I thought of creating a mini game that generates a random number and then asks the user a basic mathmatical question regarding that number. Here is my script:
    display alert "Lets play The random number game"
    say "generating random number between 10 and 20" using "zarvox"
    set firstVariable to random number from 10 to 20
    display alert firstVariable
    set Num1 to 42 - firstVariable
    set answer1 to text returned of (display dialog "First question - 42 - random number" default answer (0))
    if answer1 is Num1 then
              display alert "You are correct"
    else
              display alert "You are incorret"
    end if
    end
    When the user types in the correct answer an alert box should come up saying: You are correct. Instead is says: Your are incorrect. I
    don't know where I have gone wrong. I have tried different things but still no go.
    As I said, I am new to applescript I just created this basic script so I can practice managing inputs from the user. If someone can help me that
    would be great.

    Use the following line:
    if (answer1 as number) is Num1 then
    (95182)

  • Resource for VIRSAHR 530_700 Installation

    Hi Gurus,
    I am new to SAP Security / GRC.
    I referred the notes 1133167 which gives details about VIRSANH 530_700. But, if my SAP System has already have SAP_HR then first Ineed to install the SAPNH 530_700 and THEN , I need to Install VIRSAHR 530_700. I don't see any reference even in the Lates Installation Guide about how to install
    this VIRSAHR 530_700.
    May be the procedure would almost the same as that of VIRSANH 530_700. But, still to get the in-depth I would like to see some SAP Notes / PDFs on this VIRSAHR 530_700 Install.
    Can anybody suggests the link / sources about this ?
    Any / All Help is most welcome and would be rewarded without failure with suitable points.
    Many Thanks in Advance,
    - Ishan

    Hi Faisal,
    Thanks a Lot, this is really helpful. However, being newbie in this GRC Area, I would further refine my Q :
    1. I meant to say 4 Separate Servers for each meaning One Single Server for EACH OF ENTIRE GRC PRODUCT SUITE i.e. VIRSA 
       5.2 - with all the 4Components of  Virsa  on 1st Server, Process Control on 2nd Server , Risk Management on 3rd Server and Global
       Trade Services on 4th Server  --Even under this backdrop, Can I go with one single server  ? If yes, where would I find the Sizing
       Guidelines for such scenario ? If no,  then having one separate server for EACH Component of GRC Product Suite ( and NOT only
       Virsa 5.2 ) would be advisable , right ?
    2. Presuming you have given your inputs applicable only to Virsa 5.2, I got the following idea ...Pl. Correct me if I am wrong  :
       #1 and #2 : I need one ABAP and one J2EE Server i.e. I need one SAP NW04s System ( e.g. ECC 5.0/6.0 or SCM 5.0 or CRM
                         5. - if this is Single Stack ABAP Only System then it's Ok...)  with latest SPkg  Level on this ABAP System as per
                        Virsa 5.2 Installation Guide's Pre Reqs. In short, this would my common ABAP based Comp. as mentioned in VIRSA
                        SWDC page
       #3 : Install VIRSA NH and VIRSA HR ( RTAs) on ABAP System i.e. if I have ECC 6.0, I would install VIRSA HR , VIRSA NHR with  
              Latest Patches on this ECC 6.0
       #4 : Deploy All JAVA Archives on J2EE Server which forms the front end through which you can access all your components .....
              - i.e. : I deploy all the VIRSA Components on a Separte J2EE Server ( which would be standalone J2EE Server - other than the
                above mentioned example ABAP only or ABAP+JAVA ECC 6.0 Server - right ?) *in addiiton to the Front End Components on
                it*.  In short, this would be my common JAVA based Component
               - : i.e. Deploy all the JAVA Archives Related to the ALL 4 Components of VIRSA 5.2  sequentially ( e.g.  .sda and
                 .ear files for Role Expert , Deploy/ Install it, Apply the Patches for it , Next move to Second Component i.e.                      
                 Compliance Calibrator and so on.. on this same stand alone J2EE server  )
                  - If this is correct, Do I need to Follow the Specific Sequence as you have mentioned i.e. Role Expert,CC, AE, FF
                 ....'Cause the sequence is somewhat different in Latest Acess Control 5.3 ?  I can't find it for VIRSA so, I  would go by
                 whatever sequence you suggest..
       #5 : Deploy all these Archives on Single J2EE Server i.e. as I understood / mentioned above in #4 : on a Standalone Java Server
       #6 : You access these front ends to access each application
               i.e. The frontend AND the 4 Components would be installed on a same Separate Single Java Server as mentioned in #4,5 and
                     this Java Server with VIRSA + Front End Components on it would be connected to back end systems : ECC 6.0 and other
                     SAP Systems ( e.g CRM, SCM, XI, EP ) through JCo
    Sorry to bother you again this much, but kindly correct me If I am wrong anywhere above .
    Best Regards,
    - Ishan
    p.s. Actually, the Option ' Very Helpful Answer' is not available now for me as it was already used , hence I have opted 'Helpful Answer'
    while assigning points to you... Once I get the basic idea about this, I will mark the Q as answered and would assign full points to you... - JUST FYI .. I undestand the inputs you give me is far more 'life savers'  for me, then the number game of points ...THANKS AGAIN.

  • Please Please help me!

    hi! right, I am a java dunce. I am doing a web design degree at uni and annoyingly have to take a programming module. I just don't get it one bit and the lecturer is a sadist and won't help. I have tried countless books and what not but it all goes over my head.... to the problem
    We were given some code for a "guess the number" game. it generates a random number between 1 and 1000. You then have to guess the number. If you guess higher it should output "you ned to guess higher" and visa versa. Also if you enter 0 it should exit the program (which it does)
    The code had logical and syntax erros in it most of which I think I have managed to find but it still does not work and I have been at this for hours now (even my headache has a headache)
    It compiles now but when you enter a number the program just spits out the line "Enter your guess, from 1 to 1000 inclusive (0 to quit):" again but doesn't tell you if you should go higher or lower.
    I can only get it to spit out the "you need to guess lower" line if you enter a number above 1000 which is wrong.
    please please help me. Just point me in the right direction or something but please use novice language or I think I might have to go jump of the nearest peir.
    The code I have so far is:
    import java.util.*;
    public class guessgame2
    public static void main(String[] args)
    // Declare variables, setup keyboard input and the
    // random number generator
    int game_number, user_number;
    String continue_pref;
    Scanner data_input = new Scanner(System.in);
    Random generate = new Random();
    do
    // Generate game number
    game_number = generate.nextInt(999) + 1;
    // The following line is a debug line, comment out
    // for real game.
    // System.out.printf("Game number:%d%n", game_number);
    // Get users first guess
    System.out.print("The computer has generated a number.");
    do
    System.out.printf("%nEnter your guess, from 1 to 1000 inclusive (0 to quit):");
    user_number = data_input.nextInt();
    } while ((user_number >= 1) && (user_number <= 1000));
    // While user has not guessed right and does not want to quit
    while ((user_number == game_number) || (user_number != 0))
    if (user_number > game_number)
    System.out.printf("You need to guess lower%n");
    else
    System.out.printf("You need to guess higher%n");
    // Get users next guess
    do
    System.out.printf("%nEnter your guess, from 1 to 1000 inclusive (0 to quit):");
    user_number = data_input.nextInt();
    } while ((user_number >= 1) && (user_number <= 1000));
    if (user_number == game_number);
    // User has guessed right
    System.out.printf("%nYou guessed correctly, well done.%nDo you want to play again (y/Y)=Yes: ");
    continue_pref = new String(data_input.next());
    if (user_number == 0)
    // User wants to quit
    continue_pref = new String("No");
    } while (continue_pref.equalsIgnoreCase("N"));
    } (thankyou and sorry about the lack of indenting)

    You may want to try and write out what you want your program to do on paper and then sort the steps in which order you need them done. And then convert your notes to code.... here's a working version for you
    import java.util.*;
    import java.io.*;
    public class guessgame2{
         public static void main(String[] args) throws IOException{
              BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in));
              Scanner data_input = new Scanner(System.in);
              Random generate = new Random();
              int game_number, user_number;
              String continue_pref = "Y";
              Boolean done = false;
              int max = 1000;
              int min = 1;
              System.out.println("Would you like to play my guessing game?(y/n) ");
              continue_pref = userIn.readLine();
              continue_pref = continue_pref.trim();
              game_number = generate.nextInt(999) + 1;
              //System.out.println(game_number);//--->UNCOMMENT THIS IF YOU WANT TO DISPLAY game_number<---
              /*-----Run program while user agrees to-----*/
              while(continue_pref.equalsIgnoreCase("Y")){
                   /*-----Let user guess until they win or choose to quit-----*/
                   while(!done){
                        System.out.println("Enter your guess, from 1 to 1000 inclusive(0 to quit):");
                        user_number = data_input.nextInt();
                        /*-----check if user wants to quit-----*/
                        if(user_number==0){
                             continue_pref = "n";
                             done=true;
                        else{
                             /*-----Check if user won-----*/
                             if(user_number==game_number){
                                  System.out.println("Congradulations you've won! Would you like to continue(y/n)?");
                                  continue_pref = userIn.readLine();
                                  continue_pref = continue_pref.trim();
                                  /*-----If user wants to play again,
                                            regenerate game_number-----*/
                                  if(continue_pref.equalsIgnoreCase("n")){
                                       done=true;
                                  else{
                                       game_number = generate.nextInt(999)+1;
                                       System.out.println(game_number);
                             }/*-----Check if user number is lower-----*/
                             else if(user_number<game_number){
                                  System.out.println("You need to guess higher!\n");
                             else{/*-----Number must be higher-----*/
                                  System.out.println("You need to guess lower!\n");
    }

  • GUI class question

    Hi guys I use the NetBeans 6.0 and i build a project which has 2 Source packages on is my number game and the other I called GUI. In the GUI source package I drew a diagram which I want to use as my GUI to my number game but I don't know how to connect them. Now my question is this is it possible to connect them since they are in different packages? And my second queston is where should I code the action listenrs and where the event handler couse I am really new to gUI and that is my first one. Btw does net beans 6 provide some form of facility to join them both without much code? Thanks in advance!

    1.I would say that using packages in this case is bad, but i wont since everyone else here thinks its always good. I would just use plain .java/.class files in the same directory so that they have free access to each other and the other files.
    2. To use actions listener you first make your main class implement ActionListener, then addActionListener(this) to all your components that catch events, then use public void actionPerformed(ActionEvent e) to handle any events.

  • Coloring

    I am doing a programming in guessing number. And, i got it run properly.Now , i want to add some flavour on this program ; i would to have a red colour return if my userInput is higher than my random number. HOW SHOULD i code IT ??
       import java.awt.*;
       import javax.swing.*;
       import java.awt.event.*;
       import java.io.*;
       import java.lang.*;
        public class guessingGame extends JFrame implements ActionListener
          private JLabel instructionLabel,outputField;
          private JTextField inputFields;
          private JTextArea textArea;
          private Container contentPane;
          private static int randomNumber;
          private static int userInput;
            private int counter = 0;
              private boolean goodInput = false;  
          private Color colorChange = Color.RED;
              public guessingGame ()
             super ("Guessing Number Game");
             componentOfPane();
             randomNumber = (int) (Math.random()*100 +1);
             System.out.println("The random number generated was " + randomNumber+".");
           private void componentOfPane ( )
             contentPane = getContentPane();
             contentPane.setLayout(new FlowLayout());
             contentPane.setBackground(Color.white);
             instructionLabel = new JLabel ( );
             instructionLabel.setText ("Enter a number between 1 and 100:");
             contentPane.add(instructionLabel);
          // set up the textfield for user entry
             inputFields = new JTextField (2);
             inputFields.setText("0");
             contentPane.add(inputFields);
             inputFields.addActionListener(this);
          //set up the label where reply will be displayed
             outputField = new JLabel ( );
             outputField.setText (" ");
             contentPane.add(outputField);
             textArea = new JTextArea("Welcome",1,40 );          
             contentPane.add(textArea);
          // set properties of window
             setSize(450,100);
             setVisible(true);
          }// ends creatGUI method.
           public void actionPerformed (ActionEvent event)
          //  statements get executed here when ENTER is pressed in inputFields
            try {
             userInput = Integer.parseInt(inputFields.getText( ) );
                 counter++;
              if ( ( userInput <1) || ( userInput >100) )
                   textArea.setText("You entered an incorrect number. Please try again.");
              else if ( userInput == randomNumber)
                   if (counter > 10) {
                      textArea.setText("You guessed right but I hope you guess my number sooner next time. It took you " + counter + " tries.");
                   } else
                        textArea.setText("You did great...keep up the good work! It took you only " + counter + " tries.");
              //inputFields.removeActionListener(this);
              else if ( userInput > randomNumber)
                     textArea.setText("You guessed too high. Pick a number less than " + userInput);
              else
                   textArea.setText("You guessed too low. Pick a number greater than " + userInput);
                catch (Exception exception) {
                   // textArea.setText("userInput " + exception.toString());
                                textArea.setText("Your input is not a proper input. Please enter an integer " );
           public static void main( String[] args )
             guessingGame basicGui = new guessingGame();
             basicGui.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
       }// ends program

    how can i fix it ! could you tell me directly ?? i don`t get it

Maybe you are looking for

  • Having problem running Lightroom 5 with my MacBook Pro

    A salesperson from Bestbuy told me if I get a macbook Pro 13" with 2.5Ghz i5 and 4 GB RAM, I would be able to use Lightroom 5. I used the trial version, but it was slow on my Mac. Does that mean I need to upgrade my RAM?

  • The software update failed !!Help Please

    Hi every one. I tried to update my xpria z1. it downloaded software but installing has failed. I can not use PCC because when I connect my phone,PCC does not work properly. When I connect it to wall sharger , it constantly powering on and powering of

  • IMovie messing up the contents

    Ok, I have got a website going, and make movies i iMovie 08 and publish it to iWeb. But the movie itself often gets "rearranged" by itself. I am NOT kidding. I can save the project upload it and everything seems fine, but the next time I open iMovie,

  • Sharepoint Custom List Mobile view all field values showing empty

    I have a custom list where I have multiple fields like employee id, name, title, department, manager. When I browse this form in PC VIEW all fields are showing properly and read only using 1.7.2.min.js & 0.7.2.js , it is working like a charm, I have

  • YELLOW TINT FIX

    i heard a lot of people that their iphone is with a warmer color and is yellow tinted. week ago I got a 64Gb white iPhone 4s and when i compared with the 16 gb white iphone 4s i just see the difference , my 64gb was more with a warmer color and yello