commit 3273adb6bba3bd74c9393cb8e3ebc5bbdb2745cd Author: kriskapa88057 Date: Wed Nov 2 15:05:16 2022 +0100 git test diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..104cfef --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f605a9a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Interaktion Projekt.iml b/Interaktion Projekt.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Interaktion Projekt.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/Interaktion Projekt/GameClass.class b/out/production/Interaktion Projekt/GameClass.class new file mode 100644 index 0000000..50e79d6 Binary files /dev/null and b/out/production/Interaktion Projekt/GameClass.class differ diff --git a/out/production/Interaktion Projekt/RockPaperScissors.class b/out/production/Interaktion Projekt/RockPaperScissors.class new file mode 100644 index 0000000..7f80f06 Binary files /dev/null and b/out/production/Interaktion Projekt/RockPaperScissors.class differ diff --git a/src/GameClass.java b/src/GameClass.java new file mode 100644 index 0000000..376fa1e --- /dev/null +++ b/src/GameClass.java @@ -0,0 +1,6 @@ +public class GameClass { + + public static void main(String[] args){ + for (int i = 0; i < 7; i++) RockPaperScissors.runGame(); + } +} diff --git a/src/RockPaperScissors.java b/src/RockPaperScissors.java new file mode 100644 index 0000000..a9fb9ef --- /dev/null +++ b/src/RockPaperScissors.java @@ -0,0 +1,76 @@ +import java.util.Scanner; +import java.util.Random; + +public class RockPaperScissors { + + public static void runGame() { + int computerInput = letComputerChoose(); + int userInput = letUserInput(); + convertToWordUser(userInput); + convertToWordComputer(computerInput); + checkResults(computerInput, userInput); + } + + public static void checkResults(int computerInput, int userInput) { + + if (computerInput == userInput) { + System.out.println("Draw!"); + } else if (computerInput == 1 && userInput == 2 + || computerInput == 2 && userInput == 3 + || computerInput == 3 && userInput == 1) { + System.out.println("You win!"); + + } else if (computerInput == 2 && userInput == 1 + || computerInput == 3 && userInput == 2 + || computerInput == 1 && userInput == 3) { + System.out.println("Computer wins!"); + } else { + System.out.println("Incorrect inputs: round void"); + } + } + + private static String convertToWordUser(int userInput) { + + String userInputWord = ""; + + if (userInput == 1) { + userInputWord = "Rock"; + } else if (userInput == 2) { + userInputWord = "Paper"; + } else if (userInput == 3) { + userInputWord = "Scissors"; + } else { + userInputWord = "a false option"; + } + System.out.println("You chose " + userInputWord); + return userInputWord; + } + + public static String convertToWordComputer(int computerInput) { + String computerInputWord = ""; + + if (computerInput == 1) { + computerInputWord = "Rock"; + } else if (computerInput == 2) { + computerInputWord = "Paper"; + } else if (computerInput == 3) { + computerInputWord = "Scissors"; + } + System.out.println("Computer chose " + computerInputWord); + return computerInputWord; + } + + public static int letUserInput() { + int userInput; + Scanner input = new Scanner (System.in); + System.out.println("1 for Rock, 2 for Paper, 3 for Scissors: "); + userInput = input.nextInt(); + return userInput; + } + + public static int letComputerChoose() { + Random rgen = new Random(); + int computerInput = rgen.nextInt(1, 3); + return computerInput; + } +}