Z Williams wrote:changed the else if to if. For this assignment, I think this will do.
Liutauras Vilda wrote:
Z Williams wrote:changed the else if to if. For this assignment, I think this will do.
Stephan was way more elaborate than I did, so read his advises carefully.
Don't think whether it will do (just to meet bare minimum) for this exercise or no - try to aim best you can do for this exercise. Read once again what Stephan wrote, make 2 versions of this application. First version so it would go sort of along the lines what Stephan advised (some parts may be too early for you as of now, but no one can stop you from taking challenge), Second version what the assignment requires to submit.
First one would be way closer to what you'll be doing in your programmer's career. Second one probably would be a throw away thing in near future.
Z Williams wrote:I have just started programming, so I'm still new to this. But, I will take any constructive criticism.
Z Williams wrote:For this assignment, I think this will do.
Stephan van Hulst wrote:
Z Williams wrote:For this assignment, I think this will do.
I don't think so. The point of the assignment is to eliminate the use of logic operators by nesting if-statements. The following two statements are equivalent:
Your teacher wants you to eliminate all logic operators by using nested if-statements.
Remember the childhood game “Rock, Paper, Scissors”? It is a two-player game in which each
person simultaneously chooses either rock, paper, or scissors. Rock beats scissors but loses to paper,
paper beats rock but loses to scissors, and scissors beats paper but loses to rock. Write a Java
program that prompts player 1 and player 2 to each enter a string: rock, paper, or scissors. Finish the
program by adding nested if statements to appropriately report “Player 1 wins”, “Player 2 wins”, or
“It is a tie.”
Z Williams wrote:Is this correct? Do you just make 3 of the same code and change the value in each one?
Not at all good, I am afraid. Sorry.Z Williams wrote:Okay, how does this look? . . .
Stephan van Hulst wrote:Did you try it out? Run it with all combinations of choices for player 1 and player 2 and see if it prints what you expect it to print.
Stephan van Hulst wrote:Yes, and that's good. The problem however is that you're comparing player 1's choice nine times.
Why do you check that the player had chosen rock on line 13, when you already know they've chosen rock on line 5?
Stephan van Hulst wrote: First write three if/else clauses for each of the choices that the first player can make. Then, inside each of them, nest three if/else clauses for each of the choices that the second player can make.
Finally, you can make a slight optimization to your program by removing from each outer if or else statement the if or else statement in which the first and second player's choices are the same, and make a special case for it by checking that the two choices are equal.
Don't get me started about those stupid light bulbs. |