Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

Take note of the curly braces in my code, they emphasize the actual "blocks" of code. Your code is very hard to read because of poorly placed braces. Here is a link to another review Here is a link to another review, the top answer goes a lot more in depth on curly braces placement and has some decent visuals as well. Also while on the topic of indentation you have a few silly indentations through out.

Take note of the curly braces in my code, they emphasize the actual "blocks" of code. Your code is very hard to read because of poorly placed braces. Here is a link to another review, the top answer goes a lot more in depth on curly braces placement and has some decent visuals as well. Also while on the topic of indentation you have a few silly indentations through out.

Take note of the curly braces in my code, they emphasize the actual "blocks" of code. Your code is very hard to read because of poorly placed braces. Here is a link to another review, the top answer goes a lot more in depth on curly braces placement and has some decent visuals as well. Also while on the topic of indentation you have a few silly indentations through out.

deleted 5 characters in body
Source Link
jusexton
  • 696
  • 5
  • 14

Code FunctionalityFunctionality:

Code Functionality:

Functionality:

added 328 characters in body
Source Link
jusexton
  • 696
  • 5
  • 14
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
/**
 * Created on 7/4/2016.
 *
 */
public class RockPaperScissors {
 public static void main(String[] args){
 List<Integer> computerMoves = Arrays.asList(1, 2, 3); // Used to generate random number.
 Scanner input = new Scanner(System.in);
 // Infinite loop until broken by exit case.
 loop : while(true){
 System.out.print("Rock, Paper, Scissors, Exit >>> ");
 String move = input.nextLine().toLowerCase();
 Collections.shuffle(computerMoves); // Shuffles list to achieve random numbers.
 
 switch(move){
 case "rock" : determineWinner(computerMoves.get(0), "Tie", "You Lose", "You Win"); break; // if move is rock
 case "paper" : determineWinner(computerMoves.get(0), "You Win", "Tie", "You Lose"); break; // if move is paper
 case "scissors" : determineWinner(computerMoves.get(0), "You Lose", "You Win", "Tie"); break; // if move is scissors
 case "exit" : break loop; // if move is exit
 case "" : continue loop; // if move is blank
 default : System.out.println("Invalid Input"); // if move is none of the above
 }
 }
 }
 // Used in the interest of code re-usability
 private static void determineWinner(int computerMove, String m1, String m2, String m3){
 if(computerMove == 1){ // computer move is rock
 System.out.printf("Computer Chose Rock, %s%n", m1);
 } else if(computerMove == 2){ // computer move is paper
 System.out.printf("Computer Chose Paper, %s%n", m2);
 } else { // computer move is scissors
 System.out.printf("Computer Chose Scissors, %s%n", m3);
 }
 }
}

Another notable problem with your game is that it will nextnever stop. int b in your rps class never changes. When asking the player if they want to continue, you will have to change int b so that it equals 0 for the game to stop. Because int b is in another class from rps2, you would reference it like so:

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
/**
 * Created on 7/4/2016.
 *
 */
public class RockPaperScissors {
 public static void main(String[] args){
 List<Integer> computerMoves = Arrays.asList(1, 2, 3); // Used to generate random number.
 Scanner input = new Scanner(System.in);
 // Infinite loop until broken.
 loop : while(true){
 System.out.print("Rock, Paper, Scissors, Exit >>> ");
 String move = input.nextLine().toLowerCase();
 Collections.shuffle(computerMoves); // Shuffles list to achieve random numbers.
 
 switch(move){
 case "rock" : determineWinner(computerMoves.get(0), "Tie", "You Lose", "You Win"); break;
 case "paper" : determineWinner(computerMoves.get(0), "You Win", "Tie", "You Lose"); break;
 case "scissors" : determineWinner(computerMoves.get(0), "You Lose", "You Win", "Tie"); break;
 case "exit" : break loop;
 case "" : continue loop;
 default : System.out.println("Invalid Input");
 }
 }
 }
 
 private static void determineWinner(int computerMove, String m1, String m2, String m3){
 if(computerMove == 1){
 System.out.printf("Computer Chose Rock, %s%n", m1);
 } else if(computerMove == 2){
 System.out.printf("Computer Chose Paper, %s%n", m2);
 } else {
 System.out.printf("Computer Chose Scissors, %s%n", m3);
 }
 }
}

Another notable problem with your game is that it will next stop. int b in your rps class never changes. When asking the player if they want to continue, you will have to change int b so that it equals 0 for the game to stop. Because int b is in another class from rps2, you would reference it like so:

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
/**
 * Created on 7/4/2016.
 *
 */
public class RockPaperScissors {
 public static void main(String[] args){
 List<Integer> computerMoves = Arrays.asList(1, 2, 3); // Used to generate random number.
 Scanner input = new Scanner(System.in);
 // Infinite loop until broken by exit case.
 loop : while(true){
 System.out.print("Rock, Paper, Scissors, Exit >>> ");
 String move = input.nextLine().toLowerCase();
 Collections.shuffle(computerMoves); // Shuffles list to achieve random numbers.
 
 switch(move){
 case "rock" : determineWinner(computerMoves.get(0), "Tie", "You Lose", "You Win"); break; // if move is rock
 case "paper" : determineWinner(computerMoves.get(0), "You Win", "Tie", "You Lose"); break; // if move is paper
 case "scissors" : determineWinner(computerMoves.get(0), "You Lose", "You Win", "Tie"); break; // if move is scissors
 case "exit" : break loop; // if move is exit
 case "" : continue loop; // if move is blank
 default : System.out.println("Invalid Input"); // if move is none of the above
 }
 }
 }
 // Used in the interest of code re-usability
 private static void determineWinner(int computerMove, String m1, String m2, String m3){
 if(computerMove == 1){ // computer move is rock
 System.out.printf("Computer Chose Rock, %s%n", m1);
 } else if(computerMove == 2){ // computer move is paper
 System.out.printf("Computer Chose Paper, %s%n", m2);
 } else { // computer move is scissors
 System.out.printf("Computer Chose Scissors, %s%n", m3);
 }
 }
}

Another notable problem with your game is that it will never stop. int b in your rps class never changes. When asking the player if they want to continue, you will have to change int b so that it equals 0 for the game to stop. Because int b is in another class from rps2, you would reference it like so:

added 328 characters in body
Source Link
jusexton
  • 696
  • 5
  • 14
Loading
Source Link
jusexton
  • 696
  • 5
  • 14
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /