This site requires JavaScript, please enable it in your browser!
Greenfoot back
ajabo11
ajabo11 wrote ...

2017/4/10

Input Output

ajabo11 ajabo11

2017/4/10

#
I am having issues with an assignment I was given on greenfoot and the instructions are as follows "The three programs should be named "In Class Input Output 1a", "In Class Input Output 1b", "In Class Input Output 1c". In Class Input Output 1a: You will generate a random number and the user will try to guess it. Ask the user to input a number between 1 and 10. Generate a random number between 1 and 10. If the user guesses the correct number show the following output - "WINNER - Your Number: n - Actual Number: n" (where n is replaced by the appropriate numbers) in the center of the world. If the user does not guess the correct number show the same output, but replace the word "WINNER" with "LOSER". In Class Input Output 1b: Ask the user to input the number of singles, doubles, triples, and home runs (each asked individually). Call a method to calculate the number of total bases, where a single is worth one, a double worth two, a triple worth three, and a home run worth four. These values will be added together to get the final number of total bases. We created the logic for this in a previous written exercise. The output should be centered in the screen and look like this: Singles: n Doubles: n Triples: n Home Runs: n Total Bases: n In Class Input Output 1c: Ask the user to input the number of hours worked and the hourly rate of pay. Call a method to calculate the total pay where any hours over 40 will be paid at 1.5 times the hourly rate. Use the DecimalFormat class to make sure a dollar sign and two decimal points are displayed. Center the output in the world to look like this: Total Pay: $650.00" If someone could help point me in the right direction it would be greatly appreciated.
danpost danpost

2017/4/10

#
For 1a, write a method that will take the two int parameters for the actual and guessed values. Have it place the appropriate text at the center of the screen. You can start it like this:
1
2
3
4
5
6
7
8
9
10
/**
 * method to react to a guess by displaying a win/lose message and the two values
 *
 * @param guess the number input as the guess
 * @param answer the number to be guessed
 */
public void checkGuessToAnswer(int guess, int answer)
{
    // appropriate code here
}
You really only have to use the check, whether the guess was correct or not, to determine whether the word "WINNER" or "LOSER' will be used. Eveerything else is the same whether the guess was correct or not. See what you can do.
You need to login to post a reply.