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

Similar Messages

  • So here's a question Apple can't answer.!

    So here’s a question Apple can’t answer. ‘How do you scale a sequence of images that have scaling effects and import them into a master sequence and rescale the sequence to a quarter of the size’? This needs do be done without exporting the sequence as a movie and nesting as the information in the sequence needs to remain intact.
    I’m off-line editing a super wide screen programme that is 2,016 X 576 pixels, The program has a central image that is 768 X 576 with three panels left and right showing a montage of stills. Now in order to edit the panels and see the content make I have edited separate sequences – I do not want to make a movie because this is an off-line and making nested sequences does not let you scale the sequence. Anyone got a solution?

    I can nest the sequence and re-scale but will this
    give me an off-line that will retain the original
    source footage i.e. Tiff files. This is going to be
    finished in AE and I’ll be using the the DUCK XML
    programme to make the EDL.
    I'd do your image sequence in FCP at full resolution. use Duck to move that into AE and then do your scale, resize, etc, etc in AE.
    It can be done all in one sequence in FCP but you'd create more headaches. Just nest them (or comp-in-comp in AE).

  • TS3297 I tunes is askin me 2 security questions to purchase apps however I haven't set up any security questions before, the questions are set questions so can't answer them, how do I purchase?

    I tunes is askin me 2 security questions to purchase apps however I haven't set up any security questions before, the questions are set questions so can't answer them, how do I purchase?

    Call Apple Care for your country and the 1st tier agent should be able to assist you or transfer your call to the Account Security team.

  • Reconnect question? Can anyone answer this?

    Can anyone answer a this question about using Reconnect:
    I have over 400 pictures that didn't restore out of a 202GB Full Backup. The catalog contains over 5 years of pictures. The Full Backup file is on K: external drive. If I use the reconnect and it reconnects those pictures to that K: external backup file, then do I always have to keep that external drive plugged in while I use that catalog that reconnected those pictures to the external drive?
    If the answer is yes, then is it possible to make a copy of that Full Backup and put it on the C: drive so I can disconnect that external drive and keep it in a safe place? I have plenty of room on the C: drive since I upgraded to a 2TB main drive.
    If it is possible to make a copy of that Full Backup and move it to the C: drive can you please tell me the proper procedure. Thank you!

    Why are you asking this in a user-to-user iPhone forum? The ONLY source for a definitive answer about the brand new, not yet implemented AT&T data plans is AT&T. You need to contact them. Any "answer" you get here is purely guesswork.

  • Sample BW certification questions..can you answer these questions ? please.

    Hi Experts,
    im gonna take SAP BI (C_TBW45_70) certication exam at the end of this month..i found some questions but without answers..
    can anyone answer these questions ?
    1.What are the main motivations for using BI Statistics and the BI Administrator Cockpit
    a)Central point of entry for SAP Netweaver BI Monitoring
    b)Remodeling of IC
    c)improved performance tuning using complete and detailed runtime information on processing in SAP Netweaver BI
    d)İmproved monitoring on Mart Data consistincy using new Technical Content
    2.Within DataSource maintenance in an SAP source system...
    a)...infoobjects can be assigned to the extract structure fields.
    b)...fields can be hidden.During Datasource replication ,these fields are not transferred into SAP Netweaver BI
    c)...the initialization selection can be deleted
    d)...fields can be selected for selection.these fields can be used to request selected data from the SAP source system in an infopacket
    e)...fields can be hidden..In other words , these fiedls are remowed from the extract structure and can only be used for calculation within the user exit during data transfer
    3.Which of the following statements are true regarding the BI Accelerator
    a)BI Accelerator indexes are loaded into the memory of the BI Accelerator
    b)A BI Accelerator index contains all the data of an infocube in a compressed but not aggregated format
    c)One BI Accelerator index is created per aggregate of an infocube
    d)The BI Accelerator is used to improve the read performance of queries on IC and DSO
    e)The BI Accelerator is built using TREX technology but is a seperate installation that cannot be used for standart knowledge management functionality
    4.The APD(Analysis Proses Designer) in sap netweaver provides a mechanism for reading data from a source and then transferring the analytical resource back out to a data target.in this scenerio which of the following are possible data targets of the APD ?
    a)DataSource Object for direct update
    b)Standart DataSource Object
    c)Metadata repository
    d)infoObject master data tables
    e)VirtualProviders
    5.Which of the following statements is true regarding the BI Administration Cockpit architecture ?
    a)Bı Statistic collect runtime and status information on various object in your SAP Netweaver BI system.The technical contect extracts these statistics or accesses them directly for central display in  the BI BI Administration Cockpit
    b)After installation of the technical content datasources on your mySAP ERP source system, you are able to load performance data on mySap ERP transactions to the BI Administration Cockpit.
    c) the BI Administration Cockpit triggers periodci BI Statistics calculation , the results of which are displayed in te Data Warehousing Workbench
    6.in which of the following business scenerios should using Real time Data Acquisition be considered ?
    a) your customer need timely data in their operatinal reporst in SAP Netweaver BI.Direct access is not a viable option because of high resource consumption and high data volumes in the SAP Source system.
    b)the data availability in your customer's source system cannot be foreseen.upon availability the source system shall push the data to a web service DataSource (using SAP Netweaver XI or by directly calling the web service).
    c)your customer uses a single dialog process for transferring data from their SAP source system to SAP Netweaver BI.Because of long processing time during data transfer to SAP Netweaver BI , they want to increase the upload frequency since smaller amount of...
    d)your customer needs current flat file data in their operational reports.the file contain approx. 500 records.at regular 5 minute time interval , the flat file shall be extracted to a DataStore Object for delta calculation for further data targets.
    thanks in advance.
    Apo

    As far I know, what is possible (P), impossible (I) and can be reached from database (DB):
    DB - you would have to create query of groups, where such member was (there are Group History Report
    and Group Membership Change Report out of the box, so suitable data is in DB)
    P - you can specify the Member Resource ID in
    Group Membership Change Report
    P - OOB - Group Membership Change Report
    P/DB - rather searched by query in DB than realizable through OOB Report
    & 6. - OOB it would be hard I think - as you would have to join informations about owners, members of some Sets and MPRs - maybe it could be realizable through DB query, but I am not sure about that.
    If you found my post helpful, please give it a Helpful vote. If it answered your question, remember to mark it as an Answer.

  • General log4j question I can't answer myself

    I have developed an app using Eclipse that uses log4j and everything seems to work fine. But when I copy the code to our Unix box and run it with Ant (just upgraded to 1.7 if that makes a difference), all the logging gets redirected to stdout. It WAS working at some point, but now I can't seem to get it to work correctly and I think it has something to do with the location of my log4j.properties file. Where does this darn thing go? I jar the project if that makes any difference.
    Should it go in the same directory as the Main class? same dir as the base dir? current dir? Inside the jar? outside? etc...
    my directory structure is:
    ls .
    build.xml
    classes (dir)
    build (dir)
    src(dir)
    ls build
    MyProgram.jar
    so I call Ant from .
    And as a second question, does eclipse do any voodoo to get the pull the config file?

    I have developed an app using Eclipse that uses log4j
    and everything seems to work fine. But when I copy
    the code to our Unix box and run it with Ant (just
    upgraded to 1.7 if that makes a difference), all the
    logging gets redirected to stdout. It WAS working at
    some point, but now I can't seem to get it to work
    correctly and I think it has something to do with the
    location of my log4j.properties file. Where does
    this darn thing go? I jar the project if that makes
    any difference.
    Should it go in the same directory as the Main class?
    same dir as the base dir? current dir? Inside the
    jar? outside? etc...Question the first: What are we talking about here, a web app, desktop (swing) app or something else?
    >
    my directory structure is:
    ls .
    build.xml
    classes (dir)
    build (dir)
    src(dir)
    ls build
    MyProgram.jar
    so I call Ant from .
    And as a second question, does eclipse do any voodoo
    to get the pull the config file?No it doesn't. It only does what you tell it to though you may do so inadvertantly.
    The rough answer to your first question is that it doesn't really matter so long as the file system can find it. Likely this can be corrected with a handy path entry though you need to be wary that you don't have multiple files referenced in your path that have the same name.
    Knowing more about what you're deploying, and how you're deploying it would be helpful in trying to give you better answers.
    PS.

  • My old email account was disabled and I can't remember my password - how can I reset my password or move $ to a new itunes/email account?  It seems I must have mis-typed my information because I can't answer the security questions correctly...

    My old email account is disabled and I can't remember my itunes password - how can I reset my password or move $ to a new itunes/email account?  It seems I must have mis-typed my account information because I can't answer the security questions correctly...

    ➡ https://iforgot.apple.com/

  • On my ipod, how can i unredeem an itunes gift card because i had to do these security questions i forgot the answers to. I NEED HELP!!!!!!!!

    on my ipod, how can i unredeem an itunes gift card because i had to do these security questions i forgot the answers to. I NEED HELP!!!!!!!!

    Maybe:
    How to manage unused iTunes Gift Card and Gift Certificate balances
    Have you tried this to try to reset the security questions.
    See Kappy's previous discussion.
    HT5312 How to recover security...: Apple Support Communities
    Contact iTunes by:
    Contact iTunes

  • Seen this question before but no answer, how can I change my email address from all caps into a more proper upper-lower style.

    Seen this question before but no answer, how can I change my email address from all caps into a more proper upper-lower style.

    You should be able to change your e-mail address from your provider ... then edit it to meet the Apple requirements.   Unfortunately you've given us no profile details so we can't tell what device you have.

  • How do I change my password if I can't answer one of the security questions. iCloud does not give me a reset option of questions or email to my account to start over

    I want to change password of my ICould. It keeps asking me security questions which I never remember setting up and thus can't answer them correctly. There is no option to reset questions or for email to my account for reset. Any help?

    I found it, but only on the "outside"...before you sign in. Once you are signed in, it is not there. (Now, I might be overlooking it or be crazy, but I can't find it)
    I know many people love all the bells and whistles of modern computing...but I want it as simple as I can have it, and more and more I find these this simple task becoming more difficult.
    Oh well, thanks for your kind response.

  • Trying to download songs on iTunes and it's asking for "my 1st car I owned" and other questions that I never answered. It won't let me download anything til I answer them. Can you help me?

    Trying to download songs on iTunes and it's asking for "my 1st car I owned" and other questions that I never answered. It won't let me download anything til I answer them. Can you help me?

    You need to contact Apple to get the questions reset. Click here, phone them, and ask for the Account Security team, or fill out and submit this form.
    (94816)

  • HT201363 Good evening ...  I have an account in appel and I have purchased a card  But I can not buy applications because the applications you want to push it under the answers to security questions and I forgot the answers to these questions  How can I c

    Good evening ...
    I have an account in appel and I have purchased a card
    But I can not buy applications because the applications you want to push it under the answers to security questions and I forgot the answers to these questions
    How can I change my answers to security questions??

    Hello, yazanalmasri0.
    If you need to reset your security questions and have a rescue email attached to your Apple ID, this article will help you with this issue.
    Rescue email address and how to reset Apple ID security questions
    http://support.apple.com/kb/HT5312
    If you are still unable to reset your security questions or do not have a rescue email associated with your account, you will need to reach out to our account security team. 
    Apple ID: Contacting Apple for help with Apple ID account security
    http://support.apple.com/kb/HT5699
    Cheers,
    Jason H.

  • Questions regarding FaceTime: When I call someone, it rings but they can't answer and when someone calls me via FaceTime it won't even ring.

    Questions regarding FaceTime: When I call someone, it rings but they can't answer and when someone calls me via FaceTime it won't even ring.

    Using FaceTime http://support.apple.com/kb/ht4319
    Troubleshooting FaceTime http://support.apple.com/kb/TS3367
    The Complete Guide to FaceTime: Set-up, Use, and Troubleshooting Problems
    http://tinyurl.com/32drz3d
     Cheers, Tom

  • I forgot my security answer to the question How can I change my security question

    I forgot my security answer to the question How can I change my security question

    http://support.apple.com/kb/HT5312
    -If you established a rescue email address, there will be a link on the "Passwords & Security" page of id.apple.com.  Clicking the link will send the reset to your rescue email address (NOTE:  This is not the same address as your Apple ID email)
    -If there is no link on the page, then you didn't establish a rescue email address.  Contact AppleCare at 800.694.7466 (If you are in the US), and ask for account security.  You will need to answer some questions to verify your identity, AND you will need access to a computer to generate a temporary support pin.
    -If you are not in the US, click http://support.apple.com/kb/HT5699 - Apple ID: Contacting Apple for help with Apple ID account security
    HTH

  • Hello! my problem at jump of paid games I can't remember answers to confidential questions. you can cancel or step by step describe what to do? thanks

    hello! my problem at jump of paid games I can't remember answers to confidential questions. you can cancel or step by
    step describe what to do? thanks

    The Best Alternatives for Security Questions and Rescue Mail
        a. Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
        b. Call Apple Support in your country: Customer Service: Contacting Apple for
            support and service.
        c. Rescue email address and how to reset Apple ID security questions

Maybe you are looking for