Guest User

Untitled

a guest
Jan 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class OddsAndEvens {
  4. public static Scanner input = new Scanner(System.in);
  5. public static String nameChoice = "";
  6. public static String computerChoice = "";
  7. public static int namePlay;
  8. public static int computerPlay;
  9. public static String name;
  10.  
  11. public static void main(String[] args){
  12. intro();
  13. play();
  14. result(name, namePlay,computerPlay);
  15. }
  16.  
  17. public static void intro(){
  18. System.out.println("Let's play a game called \"Odds and Evens\"");
  19. System.out.print("What is your name? ");
  20. name = input.next();
  21. System.out.print("Hi " + name + ", which do you choose? (O)dds or (E)vens? ");
  22. String nameShortChoice = input.next();
  23. nameChoice = nameShortChoice.equals("O") ? "odds" : "evens";
  24. computerChoice = nameShortChoice.equals("O") ? "evens" : "odds";
  25. System.out.println(name + " has picked " + nameChoice + "! The computer will be " + computerChoice + ".");
  26. closing();
  27. }
  28.  
  29. public static void play(){
  30. System.out.println("How many “fingers” do you put out? ");
  31. Random rand = new Random();
  32. namePlay = input.nextInt();
  33. computerPlay = rand.nextInt(6);
  34. System.out.println("The computer plays " + computerPlay + " \"fingers\".");
  35. closing();
  36. }
  37.  
  38. public static void result(String name,int namePlay, int computerPlay){
  39. int sum = namePlay + computerPlay;
  40. System.out.println(namePlay + " + " + computerPlay + " = " + sum);
  41. if(sum % 2 == 0){
  42. System.out.println( sum + " ...is even!");
  43. if(nameChoice.equals("evens")){
  44. System.out.println("That means " + name + " wins! :)" );
  45. }else{
  46. System.out.println("That means the computer wins! :)" );
  47. }
  48. }else{
  49. System.out.println( sum + " ...is odds!");
  50. if(nameChoice.equals("odds")){
  51. System.out.println("That means " + name + " wins! :)" );
  52. }else{
  53. System.out.println("That means the computer wins! :)" );
  54. }
  55. }
  56. closing();
  57. }
  58.  
  59. public static void closing(){
  60. for(int i = 0 ; i<50 ; i++){
  61. System.out.print("-");
  62. }
  63. System.out.println();
  64. }
  65. }
Add Comment
Please, Sign In to add comment