Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Guessing Game

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Guessing Game

    I am in an intro to computer programming class and we are using java. Our next assignment has trumped me. I have tried to work out some code for hours and I cant figure it out. The chapter is called creating and invoking methods Here are the assignments:
    Program 6.1

    Write a program named FeetToInches that contains a function named ConvertFeetToInches. This function should accept a number of feet as an argument and returns the number of inches in that many feet. Use the function in a program that prompts the user to enter a number and then displays the number of inches in that many feet.

    --------------------------------------------------------------------------------

    Program 6.2

    Write a program named GuessingGame that generates a random number in the range of 1 through 100 and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." If the user guesses the correct number, the application should congratulate the user and then generate a new random number so the game can start over. Keep a count of the number of guesses that the user makes. When the user correctly guesses the random number, the program should display the number of guesses it took. When the user wins the game, ask if he/she wants to play again. If the answer is yes, then generate a new random number and start over.

    For this program, create the following functions:
    •A function to generate and return a random number in the range of 1 through 100.
    •A function that asks the user for a guess and returns the value.
    •A function that evaluates the user's guess and returns a message indicating whether it is too high, too low, or a match.

    Your program should have a game loop that continues as long as the user wants to keep playing. Within this outer loop will be an inner loop responsible to keep asking the user for guesses until the user gets the number right. In these loops call the appropriate functions you've created as needed.

    --------------------------------------------------------------------------------

    Program 6.3

    The following formula gives the distance between two points (x1, y1) and (x2, y2) in the Cartesian plane:



    Given a center point and a point on a circle, you can use this formula to find the radius of a circle. Write a program named CircleCalculator that prompts the user to enter two points - a center and a point on the circle. The program should then output the circle's radius, diameter, circumference, and area. Your program must have at least the following functions:
    •GetRadius: This method takes as its parameters four numbers. The first two numbers are the x,y coordinate o the center of the circle. The second two numbers are the x,y coordinates of a point on the edge of the circle. Calculate the distance between these two points, which is the circle's radius, and return the value to the caller.
    •GetCircumference: This method takes as its parameter a number that represents the radius of a circle and returns the circle's circumference. (If r is the radius, the circumference is 2 * 3.1416 * r)
    •GetArea: This method takes as its parameter a number that represents the radius of the circle and returns the circle's area. (If r is the radius, the area is 3.1416 * r * r)


    I hope somehow you can help me.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Guessing Game

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Reverse Number guessing game
    By rarman555 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 23rd, 2011, 10:39 PM
  2. Number Guessing Game
    By JayK in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 16th, 2011, 09:46 PM
  3. Guessing Number Game Help
    By Shadow20 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 4th, 2011, 12:41 PM
  4. Guessing Game begginner question
    By okupa in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 20th, 2010, 07:31 AM
  5. begginer wondering why his guessing game won't work
    By Ligawulf in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 8th, 2010, 12:22 AM

Tags for this Thread