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

1. ## 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.  Reply With Quote

3. ## Re: Guessing Game  Reply With Quote 