Uni project methods & negative numbers arrghhh

Hi there i have written a program for uni it creates a random number & gives the user 3 guesses at getting the number before giving them a message saying they have lost and revealing the actual number. So far so good . I managed to get this working but the next part of the project requires me to use a method which gives the user a message giving them a hint. The hint tells them whether they are hot, warm, cold etc.
I have tried to implement this in my program using this code but its not working im getting 3 messages like
ERROR: 'class' or 'interface expected
Also i think my use of negative numbers is wrong i can remember someone telling me you have to change the negative number into a positive before u can manipulate it or something like that.
Anyway any help would be greatly appreciated.
import javax.swing.*;
import java.util.*;
public class Coursework1{
     public static void main(String args[]){
          int randomnumber,usersguessint,checkguess,guessvalid,attempts;
          String usersguess,output,close;
          boolean match;
          //create random number generator
          Random numGenerator = new Random();
          //generate a random number between 1 & 10 inclusive
          randomnumber = Math.abs(numGenerator.nextInt(9))+1;
               //ask user for his first guess
               usersguess=JOptionPane.showInputDialog("Please enter your guess between 1 & 10");
               //convert users guess to integer
               usersguessint = Integer.parseInt(usersguess);
                    //initialize variable attempts
                    for ( attempts = 0; attempts < 2; attempts++ ) {
                    //validate input
                    while (usersguessint<1||usersguessint>10){
                    usersguess=JOptionPane.showInputDialog("You entered an incorrect number \nPlease enter a numberbetween 1 & 10");
                     //convert users guess to integer
                    usersguessint = Integer.parseInt(usersguess);
                    } //end while loop
                         //call boolean method
                         match = checkGuess(usersguessint, randomnumber);
                         if (match==true){
                         //display text area in JoptionPane
                         output="You won";
                         JOptionPane.showMessageDialog(null,output,"You Won",JOptionPane.INFORMATION_MESSAGE);
                         break;}
                         else{
                         //call boolean method
                         close = howClose( usersguessint, randomnumber);
                         output="You were"+close;
                         JOptionPane.showMessageDialog(null,output,"hint",JOptionPane.INFORMATION_MESSAGE);
                         output="Try again";     
                         usersguess=JOptionPane.showInputDialog("Try again");
                         usersguessint = Integer.parseInt(usersguess);
                              }     //end if
               } //end for
          }//end main
                         //user defined method (chechguess)
                         public static boolean checkGuess(int usersguessint,int randomnumber){
                         boolean match = false;
                         if (usersguessint == randomnumber){
                         match = true;
                         return match;
                         }//end method
                         //user defined method (howClose)
                         public static String howClose(int usersguessint,int randomnumber){
                         String close
                         int difference;
                         difference = randomnumber-userguessint
                         if((difference<2)&&(difference>-2)){
                              if((difference<3)&&(difference>-3)){
                                   if((difference<4)&&(difference>-4)){
                                        close="cold";
                                   }//end if
                              else{
                                   close="warm";
                              }//end if     
                         else{
                              close="hot";
                         return close;     
                         }//end method
     }//endclass

Yep, faulty as designed.
try this:public static String howClose(int usersguessint, int randomnumber) {
          int difference;
          difference = randomnumber - usersguessint; // <---
          if ((difference < 2) && (difference > -2)) {
               return "hot";
          if ((difference < 3) && (difference > -3)) {
               return "warm";
          return "cold";
     }// end method

Similar Messages

  • Flex 2 Stacked Bars with Negative Numbers?

    Hi guys, the strangest thing: I have a client requesting
    sacked bars for bar charts/column charts however, I can't seem to
    get the negative numbers to go below a positive x-axis.
    Do these bug logs suggest I need Flex 3?
    https://bugs.adobe.com/jira/browse/FLEXDMV-921
    https://bugs.adobe.com/jira/browse/FLEXDMV-1181
    and if that's the case, how will upgrading effect my current
    project?
    Thank you.

    Great, as in another thread defined and discused, i am
    a scripter, not a programmer, but i like oaying with math.
    Daves method is easy, but what about Random( -300,1200).
    that must be a huge array to initialize.
    my function has a restriction:
    it works only, if there is a zero in the range or you'll
    never get the highest number of the range. Also it can only have a
    linear range.
    Dave can input a list like this gRandomChoises = [
    1,3,5,7,11,13,17] , what can be very usefull in some cases.
    Cheers,
    Wolfgang

  • Why does Random.nextInt() generating negative numbers?

    As mentioned in the documentation, Random.nextInt() should return a pseudorandom, uniformly distributed int value between 0 (inclusive) and n (exclusive), and n must be positive. This means that we shouldn't expect any negative random number as an outcome. However, the fact is that when I was implementing this method to my program, negative numbers was generated. Why is it so? And how do I fix this problem if I need only positive random integers? Thanx!

    As mentioned in the documentation, Random.nextInt() should return a pseudorandom, uniformly distributed int value
    between 0 (inclusive) and n (exclusive), and n must be positive.You're confusing Random.nextInt() and Random.nextInt(int n).

  • Is anyone having trouble using parenthesis to show negative numbers in excel after upgrading to Yosemite?

    Since upgrading to Yosemite, I can no longer reflect negative numbers with parenthesis using excel.  All of my existing spreadsheets also no longer show parenthesis, creating formatting problems.  Is anyone else experiencing this and is there a solution?

    I suggest you post your question to Microsofts own forums for their Mac software as it's their product you're having issues with
    http://answers.microsoft.com/en-us/mac

  • How do I disallow negative numbers in a selected group of cells (i.e. only allow values greater than or equal to zero)?

    I have a table of calculated values in Numbers, and I want to disallow negative numbers in the entire table. Any numbers that would be negative I would like changed to/displayed as zeroes, that way future calculations that may be based on this cell use the value of 0 for the calculation rather than the negative value. I have seen ways of doing this to single cells at a time, but I am interested in applying it to a large selection of cells.
    There is the Conditional Format option when you bring up the inspector, but I cannot get a custom rule to work for me. I select "Greater than or equal to" and I enter 0 in the box, but nothing changes. Can anyone help with this?
    Thanks

    A step toward simplifying the application of MAX to the issue, Jerry.
    This part, though:
    Now apply your long, animal-modeling, expressions to this new, interposing, table rather than the original.
    may still leave several references to be change from the original data table to the new one.
    One way to get around that is to use the Duplicate ("DATA-1) as the new table for raw data, and the Original (DATA) as the interposing table, using the formula =MAX(DATA-1::A2) as above, starting in DATA::A2.
    This way, the long expressions could continue to reference the original table (with its content now modified).
    ALTERNATE process:
    Find/Replace could also be used to speed the process of reassigning the modeling expressions to the duplicate table, as suggested by Jerry. But some cautions apply here.
    Find/Replace can be limited to Formulas only, but not to Some formulas only.
    Find/Replace can be limited to the Current Sheet only, but this can't be combined with Formulas only.
    More on this later, when I've had a chance to check some possibilities.
    Regards,
    Barry

  • Negative numbers in export to excel

    Hi,
    We have two servers, one (X) without SP1 and the other (Y) with SP1.
    When I make export to excel in X, the negative numbers sometimes saved as @ or the actual negative number (e.g. -42), in both cases it is saved as text.
    The positive numbers are saved as numbers.
    We saw that SAP fixed it in SP1, we tried it on Y, we got that the negative numbers always show (e.g. -42), but all the numbers, positive and negative are saved as text.
    We need to see all the actual numbers(without @), and to be saved as numbers (so we can make calculations on them).
    Does anyone have any idea?
    Thanks.

    I am on SP1 and noticed that sometimes they are saved as numbers and some are texts:
    So I am not sure of any logic or what is going on.
    Maybe as a work around you could format everything to numbers so you can do the calculation?

  • Negative Numbers importing wrong

    I have a Stored Procedure on my SQL Server 6.5 DB that returns a list of decimal values (sql datatype is decimal(5,2)), of which most are Negative numbers. When the procedure is run in a SQL tool (MS Query or ISQL) the values are returned correctly. When the stored procedure is called in Java, all values (negative or positive) are showing up as zero.
    I have tried all of the following ...
    double d = rs.getDouble(1);
    Float f = rs.getFloat(1);
    Double d2 = new Double(rs.getDouble(1));
    BigDecimal b = rs.getBigDecimal(1);
    String s = rs.getString(1);The value returned by the procedure should look something like -14.75 but when using System.out.println(f.toString()); it is shown as ".00". I have even tried exporting the data out of Java into MS Excel to see if it is just something funny with the System.out.println() statement but it shows all zeros in Excel also.
    Is there anything special or a specific data type that must be used for negative numbers to read correctly in Java? I've searched the forum, tutorials and API (1.3) and haven't found anything like this.
    Any help would be greatly appreciated!!!

    So why do you say the error has something to do with negative numbers when (in your own words): "all values (negative or positive) are showing up as zero"? I don't know what your problem is, but negative numbers probably ain't it.

  • HFM 9.3 - FR Studio - can't format negative numbers with minus sign prefix?

    How can negative numbers on an account balance report be made to appear with a leading minus sign??
    This is a necessary requirement for generating an export file for loading to our new Tax software, but does not appear to be a format option.

    Have you tried going into Format Cells - Number - Negative Number Symbols - and typing a minus sign in the prefix box?

  • Negative numbers in Parentheses() in Interactive Reports in Apex 4.1

    Hi,
    I want to display the negative numbers in parentheses() in all the interactive reports in my application eg: (367,432,203.07).
    I tried using the PR format "999G999G999G999G990D00PR" in my number/date format option in 'Column Definition'. But it gives the negative number '-367432203.06895' like this '<367,432,203.07>', which is not my exact requirement.
    Is there any other number format/option to get negative numbers in parentheses in my reports.
    Can anyone please help me on this?

    divya wrote:
    I want to display the negative numbers in parentheses() in all the interactive reports in my application eg: (367,432,203.07).
    I tried using the PR format "999G999G999G999G990D00PR" in my number/date format option in 'Column Definition'. But it gives the negative number '-367432203.06895' like this '<367,432,203.07>', which is not my exact requirement.
    Is there any other number format/option to get negative numbers in parentheses in my reports.No. In 4.1 the only way to do this that preserves IR sort/aggregation/calculation functionality is to manipulate the values using a Dynamic Action/JavaScript after the page is rendered. This is not really satisfactory.
    In 4.2 I think it might be possible using a lot of extra columns, HTML Expressions, and CSS.

  • Negative Numbers considered as VARCHAR while uploading CSV file under Data Load in APEX

    I am trying to upload a CSV file which contains negative numbers. These negative numbers are being considered as VARCHAR2 while uploading. And if I change the Column Type to Numbers the upload fails.
    Any solutions the problem will highly be appreciated.

    select * from nls_database_parameters
    where parameter = 'NLS_NUMERIC_CHARACTERS'
    shows you which characters your database believes represent the decimal place and the thousands separator. So, if your database expects 1,234.123 and you present a 'number' as 1 234,123 it will complain.
    Also, in your case... your comma-separated-values contain commas? Or are the individual fields enclosed with quotes?

  • Entering negative numbers into a field

    How do I allow an item (non-base table) to accept negative numbers that are entered in the following way, "x-". I know that you can have a format mask with "x-". But that will not help me in this situation. Thanks in advance for your help!

    I dont kno what is your exact requirement. But if you are trying to accept a -ve number you can just enter -30 in a number field. but if you want 30- to be entered in a field then you can not do it directly. The workarround may be create a character field let the user enter the 30-. Possibility is that he may enter alphabetic or alpha numeric ,in this case take the substring of the field and check if it is a number field or not. if its not then do raise a message and raise form_trigger_failure to force the user to enter a valid number.
    like
    If NOT isnum(substr(:field1,1,length(:field1)-1) Then
    message ('Please enter a valid number');
    Raise Form_Trigger_failure;
    End If;
    Hope this will help.

  • Can anyone tell me how to Format cell values in numbers? I am wanting to make any negative numbers in brackets.

    Anyone able to help?

    You might want to post questions like this over on the Numbers community since it's more likely you'll find expertise there.
    However, this one I can help with.  If not already showing, you need to turn on the Inspector in Numbers.  You do that by clicking on the Inspector icon in the upper right, showing the inspector box highlighted in red below:
    Now select the cell(s) you want to format and click on the fourth tab (the one with the "42" in a box).  If want no currency sign, select number as your format, while if you want a currency symbol select currency as the format.
    Next to the "Decimals" option is the box in which you can select your "negative" format--you have four options for showing negative numbers, two of which will place negative numbers in parenthesis.
    Note that the inspector box controls a number of options and settings in Numbers. 
    If you used to working with Excel you have to understand that Numbers works entirely differently and will have more than a bit of a learning curve. 
    Generally I find Numbers is the weakest of the iWork offerings.  It is a useful program if you need a heaviliy formatted presentation of pure spreadsheet data, though if you want formatted spreadsheets in a mainly text report the Word/Excel combination works better.
    The program also falls short in a number of areas vs. Excel if your spreadsheet needs go beyond the basic.  It certainly isn't the most efficent at dealing with a large spreadsheet (and, in fact, the fact the default templates all have only a few rows is a good hint that this might not be the product for that megasheet :-) ).
    But if you just have basic spreadsheet needs it certainly can do the job.

  • Can a sequence generate negative numbers?

    Hi
    Thank you for reading my post
    i think my sequence generate negative numbers , is it possible ?or somewhere in my application is incorrect ?
      CREATE SEQUENCE  "HR"."GLOB_SEQ"  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 5 NOCACHE  ORDER  NOCYCLE ;is there anything that i made wrong which caused the negative numbers in my edit box ?
    type of my category_ID is number.
    Thanks

    Generally speaking yes you can generate negative numbers:
    SQL> create sequence seq1 increment by -1;
    Sequence created.
    SQL> select seq1.nextval from dual;
    NEXTVAL
    -1
    SQL> /
    NEXTVAL
    -2
    But if you have defined minvalue as 1 it is impossible because:
    SQL> create sequence seq1 increment by -1 minvalue 1 maxvalue 1000000 start with 1;
    Sequence created.
    SQL> select seq1.nextval from dual;
    NEXTVAL
    1
    SQL> /
    select seq1.nextval from dual
    ERROR at line 1:
    ORA-08004: sequence SEQ1.NEXTVAL goes below MINVALUE and cannot be instantiated
    SQL>
    So most probably someone simply inserted a row with negative values knowing that they'll never be in conflict with sequence generated values, or your code is buggy :)
    Generally for surrogate keys (assuming this is your case) you don't care what values they have.
    Gints Plivna
    http://www.gplivna.eu

  • Logical shift negative numbers

    So, I think i have found a bug in Labview.  I am using Labview 8.5
    I have a very very simple Vi Where i want to Right shift a negative number.  For example:
    -16 >> 2 = -4
    What i get is 16380.  If I mismatch the data types.  Meaning I right shift from a 16 integar and place the result into a 8 bit integar I get -4.  
    It would appear that the function is padding with leading zeros and not ones when handling negative numbers.   
    Is this an issue that has been fixed already?  Or am i using the function incorrectly?
    Attachments:
    Logical Shift bug.vi ‏7 KB

    Gruntboy,
         What I think you're looking for is an arithmetic shift function, while the function in Labview is a logical shift.  The difference is in the leading bit of the result when they shift a number to the right.  A logical shift right pads the numbers with '0's and an arithmetic shift right pads the numbers with their copies of their most significant bit.  This is very important when dealing with signed numbers, because the most significant bit (in standard two's complement notation) denotes whether or not a number is negative. 
         The number four (4) represented in six bits would be: 000100, and in two's complement negative four (-4) would be 111100.
    A logical shift right, which pads the numbers with a '0' on the left would be:
    000100 --> 000010  (4 --> 2)
    111100 --> 011110  (-4 --> 30)
    An arithmetic shift right, which pads the numbers with whatever their most significant bit is would be: 
    000100 --> 000010  (4 --> 2)
    111100 --> 111110  (-4 --> -2) 
    I don't see  an arithmetic shift function in Labview, but you could build one by converting the number to an array of booleans and shifting to your heart's content.
    When operating on signed numbers Arithmetic shift operations tend to be more useful, but I'm sure there would be quite a bit of confusion if the unsigned number 60 ("111110") gets right shifted and becomes 127! ("111111").
    Finally, there is "one" (heh I'm so punny) special case for arithmetic shifting.  Consider how right shifting (logical and arithmetic) 8 results in 4, then 2, then 1, then 0.  What about arithmetic right shifting of -8?  The results would be -4, then -2, then -1...... then -1, then -1, then -1, etc. 
    Worthwhile resources:
    Two's compliment notation for negative binary numbers: http://en.wikipedia.org/wiki/Two's_complement
    Logical shift explanation (w/ pictures!): http://en.wikipedia.org/wiki/Logical_shift
    Arithmetic shift explanation (w/ pictures!): http://en.wikipedia.org/wiki/Arithmetic_shift
    I hope this helps!
    Hugs,
    memoryleak 
    P.S. I noticed that you mentioned you were modeling number operations of an ASIC.  This book (ISBN: 978-0534378042) was used in the Intro to Digital Logic class I took way too long ago, and I remember it hitting very hard on binary, signs and bit operations.  Looks like a used copy can be had on Amazon for less than $40 
    Message Edited by memoryleak on 10-09-2009 11:00 AM

  • After Yosemite install I can no longer get negative numbers in parenthesis in excel. Any one else having this issue?

    Excel negative numbers not appearing in parenthesis

    I have had similar problems.  I uninstalled Office and with the help of Microsoft reinstalled Office.  Excel still won't let me format negative numbers.  I called Apple and they sent me to this discussion.  I have not seen any answer.

Maybe you are looking for

  • Reinstalling Photoshop CS6 on a macbook pro

    It's taking forever for the installers to download Adobe Creative Suite 6 Design Standard Student and Teacher Edition I need to download Photoshop and Illustrator. Any suggestions to download older programs faster? Thanks

  • Changes to Real-time cube through input-field entry

    Hello, I have created query on Real-time cube (which has some data ) and enabled input-entry field for one of the key figures. 2).Created a "Push-button" to save the changes made in query. Issue : changes are not saved at cube level , when i press "P

  • Error when creating a STO DEL for material

    I am trying to find the reason why when my client creates a STODEL itgives them the error message "Not Possible to determine shipping data for material"  The Material type is Raw Material (ROH).  The gentlemen before me said he implemented note note

  • Problems w/ nomad zen x

    i have a 30 gb zen xtra and just recently, my computer will not read the player. it knows when its plugged into the computer but i can not access the files. i dont want to format the dri've because i cannot afford to lose all my data. is there someth

  • How to convert rm/rmvb to ipod palyable format?

    I download many chinese TV shows, but unfortunately, they're all in rm or rmvb format. Is there any way or any program that can help me to convert these to an ipod playable format or at least avi or mpg4 ? PS it should not be expensive (freeware woul