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");
}

Similar Messages

  • I need to get this to work on my website....

    Hey,
    I need to get this http://rapidshare.com/files/126113880/rscasmall.zip.html to work on my website...Its an executable jar file thats ment to work without being on a server I need it to work on a SERVER can you please tell me how to make it work on a server or can you make it work your self please?
    Thanks guys!

    using ajax, javascript u can get it done.
    regards
    Aniruddha

  • Need to get this project exported asap (CS6 (6.0.2)) (all details provided)

    Been working for a while with a slow workflow, I didn't feel like I needed to upgrade anything, because I always got the work done (somehow)..
    The file size is close to 900 MB, but there is no way I'll be able to get this project exported in a good quality (with low/average settings it freezes 5% in).
    I'm going to get a new machine in the near future, but this project need to be delivered now. What steps shall I take? Thanks

    ATI Radeon HD 4670 256 MB
    Mac OS X Lion 10.7.5 (11G63b)
    Yes there are a few open gaps (intended, can be filled by "black videos" obviously- will that help?).
    No third party effects.
    Several effects have been applied. Too many to mention ("transform", "mirror", color changes, contrast changes etc).
    I can render and export each nest separately. I think the encoder "gets overwhelmed" when it has to read the whole project (which is why I think it will be useless to try to get a proper result with my current system). Thanks

  • Trying to get this code working

        So, I'm trying to make some smoke and I really like the way one looks I found online; however, I guess it was made in a previous version and some of the code is no longer support with the version I'm using with is CS3.
    Hopefully this is the right forum for this.  If not, please redirect me.  Any help getting this thing woring would be much appreciated.  The code comes from this site:
    http://www.pixelhivedesign.com/tutorials/Realistic+Flash+Smoke+Effect/
    He creates a movieclip called aPuff and then gives the movieclip an identifier of aPuff as well.  It seems identifiers are no longer used in CS3.
    // Realistic Smoke Effect - www.pixelhivedesign.com
    fadeSpeed = 1;    // Smoke fade speed.
    floatUpSpeed = 2; // Smoke float up speed.
    // Every frame attach a puff of smoke.
    this.onEnterFrame = function(){
      // Get next available depth.
      d = this.getNextHighestDepth();
      // Attach a puff of smoke.
      aPuff = attachMovie('aPuff','aPuff'+d,d);
      // Set initial scale to 10%.
      aPuff._xscale = aPuff._yscale = 10;
      // Put puff where the mouse is. (add small random)
      aPuff._x = Math.random() * 5;
      // Randomizes the starting animation for realism.
      aPuff.gotoAndPlay(Math.round(Math.random()*20));
      // Smoke will animate each frame.
      aPuff.onEnterFrame = function(){
        // Scale smoke up.
        this._xscale = this._yscale += fadeSpeed;
        // Fade smoke.
        this._alpha -= fadeSpeed;
        // Smoke floating up.
        this._y  -= floatUpSpeed;
        // When smoke is 100% scale, remove it.
        if(this._xscale >= 100){
          this.removeMovieClip();
    When I run this in CS3 I get a whole list of errors.  I’m super new to actionscript.
    Thanks again.

    Wrong forum.  That is AS2 code, not AS3 (CS3 can work with either).  Since you say you are getting a bunch of errors, you probably have the file's Publish Settings set up for AS3.  If you change them to AS2 that code might work.

  • Please Help!  Need to get this done soon - Bigger Size slideshow on web

    Hello,
    I need to publish on the web a slideshow of some of my pics, but I need to publish them at a size much bigger than the little iMovie screen size I have now with iLife 06 and .Mac (the little screens that looks like a movie screen and other designs - I think it is at 320X240). I will go buy iLife 08 today if it will allow me to do what I want to do which is publish a slideshow with music of my photos at 640X480 or *preferably even bigger*. Can I do that with iLife 08 and how?

    Have you considered using iWeb to create a photo page and slideshow? It creates slides that are 800 x 600 pixels in size for the slideshow. Here's an example of such a photo page/slideshow.
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 08 libraries and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • Hello, how can i get this code working?

    public class TrivialApplication
    public static void main(String args[]){
    class HelloObject
    String greeting="String Test";
    void speak()
    System.out.println(greeting);
    ?

    At a guess I'd say it wouldn't like that because you've defined the class HelloObject inside main.
    Try like so (formatting is done with [ code ] and [ /code ] tags):
    public class TrivialApplication
        private String greeting;
        public static void main(String[] args)
            TrivialApplication ta = new TrivialApplication();
            ta.speak();
        public TrivialApplication()
            greeting = "String Test";
        public void speak()
            System.out.println(greeting);
    }This is a bit of overkill, I certainly could have done it with less code, but it shows the standard format. How you declare variables, and initialise them in the constructor. How to create an object and call methods of the object.
    Or, if you really wanted the HelloObject class...
    public class TrivialApplication
        public static void main(String[] args)
            HelloObject ho = new HelloObject();
            ho.speak();
        class HelloObject()
            private String greeting;
            public HelloObject()
                greeting = "String Test";
            public void speak()
                System.out.println(greeting);
    }HTH,
    Radish21

  • How can I get this code to display 20 lines

    I need to get this code I have written to display 20 lines at a time, then the 20 using the Enter key.
    How would I approach this?
    I thought of making a RandomAcessFile object, but that seems like overthinking the problem, and I'm not sure that I could get that to work anyway.
    import java.io.*;
    public class ReadIt
    public static void main(String[] args)
         throws IOException
              System.out.println ("Enter The Desired .java Filename.");
              System.out.println ("Do not add the .java extention.");
              String fname;
              EasyIn type = new EasyIn();
              fname = type.readString();
              String fndotjava = new String(fname + ".java");
              //System.out.println (fndotjava);
              File inFile = new File(fndotjava);
              InputStream istream;
              OutputStream ostream;
              istream = new FileInputStream(inFile);
              ostream = System.out;
              int c;
              try
                     while((c = istream.read()) != -1)
                           ostream.write(c);
              catch(IOException e)
                     System.out.println("Error: " + e.getMessage());      
              finally
                    istream.close();
                    ostream.close();                 
    }Thanks
    Brad

    Well, a RandomAccessFile together with a counter should work. However, you can also achieve this by buffering the input rather than writing it directly out
    java.util.Vector vect = new java.util.Vector();
    try{
         while((c = istream.read()) != -1){
             vect.append(c);
    catch(IOException e){
         System.out.println("Error: " + e.getMessage());      
    finally{
         istream.close();                 
    }     with the help of
    java.util.Vector.size() and
    java.util.Vector.elementAt(int index)
    you are able to display only 20 lines at a time, you just need the additional code for reading System.in
    public static void prompt(String s){
        System.out.print(s + " ");
        System.out.flush();
      public static String readData ( BufferedReader in)  {
        boolean verfuegbar = true;
        while ( verfuegbar){
          try{
            S = in.readLine();
            if ( S != null)verfuegbar = false ;
          catch (IOException e){System.out.print (e);}
        return S;
      }now it should work with
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    prompt("return for continuing");
    int twentscount = 0;
    int count = 0;
    do{
       while( count < 20 && twentscount+count < vect.size() ){
           outstream.write(vect.elementAt(twentscount + count).toString() );
           count++;
    prompt("return");
    readData(in);
    twentscount += 20;
    count = 0;
    while(twentscount + count < vect.size());sure, this is code from head, and you can make many changes (e.g. instead of using twentscount use the modulo (%) operator saving one variable (while count % 20 != 0 ).
    I'm also not sure if it will definitly run , since i haven't tested it (especialy for index borders).
    I hope this will give you enough hints for this possible solution.
    Adrian

  • Can somebody please tell me how to fix this. when i try to install appleworks this pops up  so please help me i need to get this on my mac

    can somebody please tell me how to fix this. when i try to install appleworks this pops up
    so please help me i need to get this on my mac

    AppleWorks is a very old application and requires Rosetta to run under recent systems.
    Lion does not include Rosetta.
    If you browse this forum you will find many posts on this issue.

  • I updated my phone and it cleared everything on it and I don't have an icloud or itunes backup. Please help I need to get my pictures and information back

    I updated my phone and it cleared everything on it and I don't have an icloud or itunes backup. Please help I need to get my pictures and information back

    Sorry, but without a backup in iCloud or iTunes on your computer, your data is gone and can't be restored anymore.

  • I have a problem in my iphone 4 with wi-fi after update to IOS6 please can help my how can solve this problem?

    I have a problem in my iphone 4 with wi-fi after update to IOS6 please can help my how can solve this problem?

    Nope
    One needs to press the home and sleep / wake keys together for the phone to reset
    The other thing I could recommend
    Let the battery run out and the phone completely "die"
    It may take a day or two with it not being used
    Then plug it in to charge and see if there is any change in behavior
    If you cannot get this to work - you may need to bring it to an Apple store

  • My phone 5s did the new update and will not come back on. I already tried hard reboot still won't work. Been over a hour now. Please someone help I need my phone.

    My phone 5s 16gb gold did the new update and will not come back on. I already tried hard reboot still won't work. Been over a hour now. Please someone help I need my phone.   This phone is not even 6 months old been in case no scratches. This is driving me crazy.

    Connect your phone to a computer and restore your software using iTunes.

  • I deleted my keynote and downloaded it again but the installer says: You already have an eligible Keynote in the folder: /Applications/iwork 09, I didn't find any keynote. Please someone help me Im stuck in this mess.

    I deleted my keynote and downloaded it again but the installer says: You already have an eligible Keynote in the folder: /Applications/iwork 09, I didn't find any keynote. Please someone help me Im stuck in this mess.

    SkyDaughter29 wrote:
    My current situation: I have soooo many texts on my iphone and I haven't deleted many because I need the information contained in them for future reference and for legal purposes.  I would really like to find a means and way to save them other than on the phone itself. I've done searches for various apps yet I'm not finding what I think I would need.  It appears Apple does not sync the texts between the iphone and my MacBook Pro.
    Try the computer apps PhoneView (Mac) or TouchCopy (Mac & PC):
    http://www.ecamm.com/mac/phoneview/
    http://www.wideanglesoftware.com/touchcopy/index.php
    Best of luck.

  • I am working on a MacBook Pro (13-inch, Mid 2009) with boot camp running Windows 7 pro 64-bit.  Windows crashes quite often now-a-days and I need to get this fixed. I heard that updating boot camp can help.  Currently I am running Version 3.0.4 (322).

    I need to know which update(s) I can apply to help stabalize the system.

    Typing the body of the thread message in the title, huh? -)
    I am working on a MacBook Pro (13-inch, Mid 2009) with boot camp running Windows 7 pro 64-bit.  Windows crashes quite often now-a-days and I need to get this fixed. I heard that updating boot camp can help.  Currently I am running Version 3.0.4 (322).
    Only Apple could hamstring and tie Mac OS to Windows. There isn't any other than whether you can download the drivers into Windows (you can) but Apple puts a block on the installer setup even if your mac does not support it.
    Windows 7 needs at least Boot Camp 3.1 and 3.3 is what you should already have. And you are not getting security updates if you don't have at least 10.6.8 as was pointed out.  --- you arent using Software Update as you should. And you should backup and clone Mac (and Windows) as well.
    You need Mountain Lion to use Boot Camp 5.x which supports Windows 7 & 8 and 64-bit.
    I would upgrade to Lion if you can realizing that Rosetta and PowerPC are no longer supported though.
    Mac 101: Using Windows on your Mac via Boot Camp
    https://support.apple.com/kb/HT1461
    http://www.apple.com/support/bootcamp/
    Helpful Apple Support Resources (Forum Overview)
    Boot Camp Support 
    Boot Camp Manuals
    Boot Camp 5.0 Drivers
    http://support.apple.com/kb/DL1638
    Frequently asked question
    http://support.apple.com/kb/HT4818
    http://manuals.info.apple.com/en_US/boot_camp_install-setup_10.7.pdf
    http://manuals.info.apple.com/en/Boot_Camp_Install-Setup_10.6.pdf
    http://manuals.info.apple.com/en/Boot_Camp_Install-Setup_10.6.pdfcreate a Windows support software (drivers) CD or USB storage media
    http://support.apple.com/kb/HT4407
    The Boot Camp Assistant can burn Boot Camp software (drivers) to a DVD or copy it to a USB storage device, such as a flash drive or hard drive. These are the only media you can use to install Boot Camp software.
    https://support.apple.com/kb/HT4569
    http://manuals.info.apple.com/en_US/boot_camp_install-setup_10.8.pdf
    Instructions for all features and settings.
    Boot Camp 4.0 FAQ Get answers to commonly asked Boot Camp questions.
    Windows 7 FAQ Answers to commonly asked Windows 7 questions.
    http://www.apple.com/support/bootcamp/
    Is there a download of the Boot Camp 5 Support Software if I'm not using OS X Mountain Lion v10.8.3?
    Yes, you can download the Boot Camp 5 Support Software here.
    http://support.apple.com/kb/DL1638
    How do I use the Boot Camp 5 Support Software I downloaded from the web page?
    The download file is a .zip file. Double click it to uncompress it.
    Double-click the Boot Camp disk image.
    Copy the Boot Camp and "$WinPEDriver$" folders to the root level of a USB flash drive or hard drive that is formatted with the FAT file system (see question below for steps on how to format).
    Install Windows, leaving the flash or hard drive attached to the USB port of your Mac.
    Installation of the drivers can take a few minutes. Don't interrupt the installation process. A completion dialog box will appear when everything is installed. Click Finish when the dialog appears.
    When your system restarts your Windows 8 installation is done.
    Note: If the flash drive or hard drive was not attached when you installed Windows and was inserted after restarting into Windows 8, double-click the Boot Camp folder, then locate and double click the "setup.exe" file to start the installation of the Boot Camp 5 Support Software.
    How do I format USB media to the FAT file system?
    Use Disk Utility to format a disk to use with a Windows computer. Here's how:
    Important: Formatting a disk erases all the files on it. Copy any files you want to save to another disk before formatting the disk.
    Open Disk Utility.
    Select the disk you want to format for use with Windows computers.
    Click Erase, and choose one of the following from the Format pop-up menu:
    If the size of the disk is 32 GB or less, choose MS-DOS (FAT).
    If the size of the disk is over 32 GB, choose ExFAT.
    Type a name for the disk. The maximum length is 11 characters.
    Click the Erase button and then click Erase again.
    Which versions of Windows are supported with Boot Camp 5?
    64-bit versions of Windows 8 and Windows 7 are supported using the Boot Camp 5 Support Software. If you need to use a 32-bit version, you need to use Boot Camp 4 Support Software, and you must use Windows 7. 32-bit versions of Windows 8 are not supported via Boot Camp. For a complete list of Windows OS support, click here.

  • Need help getting this code to work

    I am trying to get this code to work using "if else statment" but it will only do the first part and not do the second part in the else statement. Can anyone help me out? Here is the code:
    var R1 = this.getField("Registration Fees1");
    var R2 = this.getField("Registration Fees2");
    var R3 = this.getField("Registration Fees3");
    var R4 = this.getField("Registration Fees4");
    var R0 = 0
    if (R0 == 0)
      event.value = Math.floor(R1.value);
    else
      event.value = Math.floor(R2.value + R3.value + R4.value);
    I did notice that if I fiddled around this this part:
    if (R0 == 0)
    sometimes I can get the second part to work but not the first. I need it to do either or and this is getting frustrating.
    I might also not even need "var R0 = 0". I put that there for the condition part. If that is what is causing the problem, I can take it out. But then what would the condition be? For this form, the default is 0 and then the calculation follows by user clicking on different prices. The first part is if they want to pay for the full conference and the second part is if they want to pay for either Monday, Tuesday or Wednesday or 2 of the 3 days. Is it possible to get this to work with both parts together? I am still stuck on getting just one or the other working. Any help would be greatly appreciated. Thanks in advance.

    I have posted this on another message board and a user by the name of gkaiseril offered this solution but it hasn't worked either.
    // all four days
    var R1 = this.getField("Registration Fees1").value;
    // Monday
    var R2 = this.getField("Registration Fees2").value;
    // Tuesday
    var R3 = this.getField("Registration Fees3").value;
    // Wednesday
    var R4 = this.getField("Registration Fees4").value;
    var Fee = 0
    event.value = ''; // default value
    if (R1 != 'Off') {
      Fee = Number(R1) + Fee;
    } else {
      if(R2 != 'Off') {
         Fee = Number(Fee) + R2;
      if(R3 != 'Off') {
         Fee += Number(R3);
      if(R4 != 'Off') {
         Fee = Number(R4) + Fee;
    event.value = Fee;

  • I want to install WhatsApp on my iphone 16gb, but I need a code of 3 figures! Where can I get this code? i tried looking at my messages folder, but i havent got any 3 digit code. plz help

    I want to install WhatsApp on my iphone 16gb, but I need a code of 3 figures! Where can I get this code? i tried looking at my messages folder, but i havent got any 3 digit code. plz help

    post in the iPhone forum : https://discussions.apple.com/community/iphone/using_iphone

Maybe you are looking for

  • Budget check only after release?

    hi, i maintain cost activity  in project and when i save it, it checks against the budget... is it possible such that it will check the cost activity only upon release of the activity? in other words, i can save it (even if it has greater amount than

  • Payment terms-greyed out field

    Hi, We would like the payment terms field to be in display mode in VA01 and VA02.Basically taking off the access of this field from enduser.How do we do it. Secondly in XD01 or XD02 we want only authorised users to change or create payment terms fiel

  • Display Authorization for MASSD

    Hi, There is a requirement for giving a user only display authorizations for MASSD. I've tried various combinations of objects, however have been unsuccessful so far.. Pls. help. Thanks, Saba.

  • SAP IDM - User Sync to UME Not Working

    Hi All, Currently we're planning to implement IDM 7.1 SP05 for ESS/MSS user Password provisioning. We're done the basic configuration as per the guides and HR Employers has sync to VDS and then to SAP Master Identity Store. Now we wanted to sync thes

  • Downloading contacts from 3110 classic to Ck 600

    Hi, Have installed CK-600 to my car and i cannot transfer the contacts from my phone (3110 classic). Have tried all the instructions in the manual, but still no joy. Please help. Solved! Go to Solution.