Preview

Software Development

Good Essays
Open Document
Open Document
554 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Software Development
Name ID

CS2901 Software Development and
CS3000 Object-Oriented Software Development
Laboratory Assignment: Event Driven Programming.
Due Date: Thu 10th January 2013
Lab Exercise — Guess Game

The program template represents a complete working Java program, with one or more key lines of code replaced with comments. Read the problem description and examine the sample output; then study the template code. Using the problem-solving tips as a guide, replace the /* */ comments with Java code. Compile and execute the program. Compare your output with the sample output provided. Then answer the follow-up questions. The source code for the template is available at the course website (sclass).

Problem Description
Write an application that plays “guess the number” as follows: Your application chooses the number to be guessed by selecting an integer at random in the range 1–1000. The application then displays the following in a label:

I have a number between 1 and 1000. Can you guess my number?
Please enter your first guess.

A JTextField should be used to input the guess. As each guess is input, the background color should change to either red or blue. Red indicates that the user is getting “warmer,” and blue indicates that the user is getting “colder.” A JLabel should display either "Too High" or "Too Low" to help the user zero in on the correct answer. When the user gets the correct answer, "Correct!" should be displayed, and the JTextField used for input should be changed to be uneditable. A JButton should be provided to allow the user to play the game again. When the JButton is clicked, a new random number should be generated and the input JTextField changed to be editable.

Sample Output
[pic]
Problem-Solving Tips
1. Use methods from the JTextField class to manipulate all JTextField components. For instance, method setText will set the text of the text field, and method setEditable will

You May Also Find These Documents Helpful

  • Satisfactory Essays

    a1 script win213

    • 380 Words
    • 2 Pages

    If the user does not enter a numeric value the program should prompt for a numeric value…

    • 380 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    To fully test my program, test data needs to be created that can fully push the program to its boundaries or even further by causing a crash or error during execution. This will ensure that all errors and bugs are discovered so they can then be corrected.. The whole program will be played several times to make sure it works from the start to the end without any errors or bugs being encountered and to ensure it gives the correct outputs.…

    • 1040 Words
    • 5 Pages
    Good Essays
  • Good Essays

    It210 Week 4 Psuedocode

    • 584 Words
    • 3 Pages

    Write: “Enter 6 if you would like to Quit now.” Input Display_Selection While Display_Selection ! = 1 || 2|| 3 || 4…

    • 584 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Prg421 Week 2 Ia

    • 565 Words
    • 3 Pages

    JOptionPane; import javax.swing. JPanel; import javax.swing. JScrollPane; import javax.swing. JTextArea; import javax.swing. JTextField; import javax.swing.…

    • 565 Words
    • 3 Pages
    Satisfactory Essays
  • Better Essays

    Unit 22 Asseement

    • 1496 Words
    • 6 Pages

    |Unit Title: |Unit Number: | |Developing computer games |22 | |Level of Award: 3 |Centre Number: 16405 | |Candidate Name: |Candidate Number: | |Learning Hours: 60 |Duration of Academic Year: 1 Term | |Unit Deadline: | |Assignment Brief Author: Mr Badhasha | |Tutor/Assessor | |Signed: |Date: | |Final Grade: |Date: | |Assignment Internal Verifier: | |Signed: |Date: | |Tutor/Assessor Comments: | |…

    • 1496 Words
    • 6 Pages
    Better Essays
  • Good Essays

    7) The program will allow the user to have three attempts to guess the Substitute Word correctly. However, if the user doesn’t guess correctly the Substitute Word during those three attempts, the game will not proceed and a suitable ‘fail’ message will be shown on the…

    • 553 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    This Is a Paper

    • 469 Words
    • 2 Pages

    * The design is not robust as there are no statements for error handling and handling exceptions. To make this code more robust I would add error handling statements like the user can only enter numbers that are between 0 and 100. Also the user cannot enter any strings like winding and other data types, for other numbers and data types the system will display "invalid input. Please enter a number between 0 and 100." Also notice that it doesn't handle the case of entering 49. You need <= 49, as it is now, when you enter 49 all it will say is "how did u do?" same thing with entering 100 and for anything over 100.…

    • 469 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Discrete Mathematics

    • 954 Words
    • 4 Pages

    Part II: The implementation of the program that runs the game involves testing. One of the necessary tests is to see if the simulated spins are random. Create an n-ary relation, in table form, that depicts possible results of 10 trials of the game. Include the following results of the game:…

    • 954 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    Prg420 Syllabus

    • 1691 Words
    • 7 Pages

    Horton, I. (2005). Ivor Horton’s Beginning Java 2, JDK (5th ed.). Indianapolis, IN: Wiley Publishing.…

    • 1691 Words
    • 7 Pages
    Satisfactory Essays
  • Good Essays

    The game we played is an “ABC Fishing Game”. There are six uppercase magnetic letters – A, C, N, R, S, and T – in an aquarium. We have five game cards; each card has a simple picture of an item on it. Underneath the item, the word/name is written in big, uppercase letters, big enough to put the magnetic letter on it. The items/words on these cards are: ANT, CAR, STAR, CAT, and CAN. The child picks a card and a fishing pole with a magnetic end and starts to catch letters from the aquarium. The purpose of the game is to catch the letters that are needed to write, or build, the appropriate word. If the child catches a letter that is part of that word, he or she will put the magnetic letter on the letter outline on the card, if he or she catches a letter that is not part of…

    • 680 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Pi Day Research Paper

    • 513 Words
    • 3 Pages

    I had practiced the first 250 digits so many times that it was like the alphabet to me as I only knew the rhythm not the numbers. Whenever someone challenged me to prove my claim I would sound like a kindergarten class singing along with their ABC’s. Faced with the accusation that I was merely spewing out random strings of digits I challenge back by asking the person to say random number that quickly without breaking into a pattern. Turns out that is more difficult than just…

    • 513 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    The Game of Pig Portfolio

    • 642 Words
    • 3 Pages

    To play the game you need a regular 6-sided die. Each turn of the game consists of one or more rolls of the die. You keep rolling until you get a 1 or decide to stop. You may choose to stop rolling at any time. If you stop rolling before you get a 1 your score for that turn, your score is the sum of all of the numbers you rolled that turn (e.g. if you roll a 4, 6, 3, and 2 your score is 15 pts.). But, if you roll a 1 in that turn your turn is over and you receive 0 pts. for that turn. The central problem in the unit is finding strategies for several different probability games.…

    • 642 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Tic Tac Toe

    • 1474 Words
    • 4 Pages

    As soon as either of the human player or the computer wins, a message congratulating the winner should be displayed. If neither player manages to get three consecutive marks along a straight line,and all the squares on the board are filled up, then the game is drawn. The computer always tries to win a game.…

    • 1474 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    Title Proposal

    • 658 Words
    • 5 Pages

    After you have entered your answer on the textbox, press enter to submit your answer the game will verify your answer if it is correct or wrong, the game will display the correct answer and give a short description of the picture presented.…

    • 658 Words
    • 5 Pages
    Satisfactory Essays
  • Good Essays

    In simple words, this program takes into account recent winning numbers, hot and cold numbers, and overdue numbers to determine which combinations are most likely to be winners.…

    • 968 Words
    • 4 Pages
    Good Essays

Related Topics