Untitled

 avatar
unknown
plain_text
4 years ago
25 kB
5
Indexable
package GivenProblem;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;


public class Main {
    // Runs the whole thing
    public static void main(String[] args) throws IOException {
        
        Scanner sc = new Scanner(System.in);
        // Creates the box layer and runs an if statement to determine how many players are going to play
        System.out.println("--------------------" + "\n|Fraction Game 101 |" + "\n--------------------");
        System.out.println("Please Enter How many players are Playing: (2-4)");
        int amntPlayers = sc.nextInt();
        sc.nextLine();


        //if the amount of players is equal to 2 then follow all of this requirements


        // 2 Players

        if (amntPlayers == 2) {
            initializers initializers = new initializers();
            ArrayList<Integer> points1 = new ArrayList<Integer>();
            ArrayList<Integer> points2 = new ArrayList<Integer>();
            players players = new players();
            // sets the player 1 and player 2 to give more of a game feeling
            System.out.println("Enter a name for Player 1");
            String player1 = sc.next();
            sc.nextLine();
            players.setPlayer1(player1);
            System.out.println("Enter a name for Player 2");
            String player2 = sc.next();
            sc.nextLine();
            players.setPlayer2(player2);


            // Ask the user how many questions to ask and loops it based on that.
            System.out.println("Set how many question to ask per person? (Max 20 per person)");
            int amnt = sc.nextInt();
            sc.nextLine();


            for (int i = 0; i < amnt; i++) {
                // Asks Player one the questions then runs compare statements
                System.out.println(players.getPlayer1() + ", Answer me This: " + initializers.question.get(i));
                String answer = sc.next();
                sc.nextLine();
                //if it equals to the simplified answer then it will save the users points in a list
                if (answer.equals(initializers.SimplifiedAnswers.get(i))) {
                    System.out.println("Good Job! You get 4 Points");
                    points1.add(4);
                    // else it will compare to the not simplified Answer and if it is equal to it, it will then give the user the points in an array.
                } else if (answer.equals(initializers.notSimplified.get(i))) {
                    System.out.println("Good Work! However, the Answer wasnt in its most simplified form, You get 3 points");
                    points1.add(3);
                } else {
                    // It gives the user one more chance to try again, by using comparing statements similar to what was given before
                    System.out.println("Aww that Sucks, Lets try One More Time");
                    String answer2 = sc.next();
                    sc.nextLine();
                    if (answer2.equals(initializers.SimplifiedAnswers.get(i))) {
                        System.out.println("Good Job! You get 2 Points");
                        points1.add(2);
                    }
                    if (answer2.equals(initializers.notSimplified.get(i))) {
                        System.out.println("Good Work! However, the Answer wasn't in its most simplified form, You get 1 points");
                        points1.add(1);
                    } else {
                        // If they dont get it correct the second time then it gives no points to the user and adds zero to their arraylist
                        System.out.println("Sorry " + players.getPlayer1() + ", you get no points");
                        points1.add(0);
                    }
                }


                // repeats the same process with the other player but chooses the next question in the list given
                System.out.println(players.getPlayer2() + ", Answer me This: " + initializers.question.get(i + 1));
                String answer3 = sc.next();
                sc.nextLine();

                // same comparison, checks if its the same, if so, 4 points, if not then 3 points
                if (answer3.equals(initializers.SimplifiedAnswers.get(i + 1))) {
                    System.out.println("Good Job! You get 4 Points");
                    points2.add(4);
                } else if (answer3.equals(initializers.notSimplified.get(i + 1))) {
                    System.out.println("Good Work! However, the Answer wasnt in its most simplified form, You get 3 points");
                    points2.add(3);
                } else {
                    // Gives the users a second try to the question to see if they get it right, 2 points if it simplified 1 for not, then 0 if they get it wrong twice
                    System.out.println("Aww that Sucks, Lets try One More Time");
                    String answer4 = sc.next();
                    sc.nextLine();
                    if (answer4.equals(initializers.SimplifiedAnswers.get(i + 1))) {
                        System.out.println("Good Job! You get 2 Points");
                        points2.add(2);
                    }
                    if (answer4.equals(initializers.notSimplified.get(i + 1))) {
                        System.out.println("Good Work! However, the Answer wasn't in its most simplified form, You get 1 points");
                        points2.add(1);
                    } else {
                        System.out.println("Sorry " + players.getPlayer2() + ", you get no points");
                        points2.add(0);
                    }
                }
                i++;
            }
            // Sets the new arrays created to the the class method to add them all together
           int num1 = players.setAddPlayerPoints1(points1);
            int num2 = players.setAddPlayerPoints2(points2);

            // Displays all the information out:
            System.out.println("Lets Sum up the Winnings:");
            System.out.println("\n" + players.getPlayer1() + ", You got " + num1+ " points. Looks like your average was " +
                    players.setPlayerAverage1(num1, amnt) + ". Nice Work.");
            System.out.println("\n" + players.getPlayer2() + ", You got " + num2 + " points. Looks like your average was " +
                    players.setPlayerAverage2(num2, amnt) + ". Well Done.");


            // 3 Players

        } else if (amntPlayers == 3) {


            initializers initializers = new initializers();
            ArrayList<Integer> points1 = new ArrayList<Integer>();
            ArrayList<Integer> points2 = new ArrayList<Integer>();
            ArrayList<Integer> points3 = new ArrayList<Integer>();
            players players = new players();


            // sets the player 1 and player 2, 3 names to give more of a game feeling
            System.out.println("Enter a name for Player 1");
            String player1 = sc.next();
            sc.nextLine();
            players.setPlayer1(player1);
            System.out.println("Enter a name for Player 2");
            String player2 = sc.next();
            sc.nextLine();
            players.setPlayer2(player2);
            System.out.println("Enter a name for Player 3");
            String player3 = sc.next();
            sc.nextLine();
            players.setPlayer3(player3);


            // Ask the user how many questions to ask and loops it based on that.
            System.out.println("Set how many question to ask per person? (Max 20 per person)");
            int amnt = sc.nextInt();
            sc.nextLine();


            for (int i = 0; i < amnt; i++) {
                // Asks Player one the questions then runs compare statements
                System.out.println(players.getPlayer1() + ", Answer me This: " + initializers.question.get(i));
                String answer = sc.next();
                sc.nextLine();
                //if it equals to the simplified answer then it will save the users points in a list
                if (answer.equals(initializers.SimplifiedAnswers.get(i))) {
                    System.out.println("Good Job! You get 4 Points");
                    points1.add(4);
                    // else it will compare to the not simplified Answer and if it is equal to it, it will then give the user the points in an array.
                } else if (answer.equals(initializers.notSimplified.get(i))) {
                    System.out.println("Good Work! However, the Answer wasnt in its most simplified form, You get 3 points");
                    points1.add(3);
                } else {
                    // It gives the user one more chance to try again, by using comparing statements similar to what was given before
                    System.out.println("Aww that Sucks, Lets try One More Time");
                    String answer2 = sc.next();
                    sc.nextLine();
                    if (answer2.equals(initializers.SimplifiedAnswers.get(i))) {
                        System.out.println("Good Job! You get 2 Points");
                        points1.add(2);
                    }
                    if (answer2.equals(initializers.notSimplified.get(i))) {
                        System.out.println("Good Work! However, the Answer wasn't in its most simplified form, You get 1 points");
                        points1.add(1);
                    } else {
                        // If they don't get it correct the second time then it gives no points to the user and adds zero to their arraylist
                        System.out.println("Sorry " + players.getPlayer1() + ", you get no points");
                        points1.add(0);
                    }
                }


                // repeats the same process with the other player but chooses the next question in the list given
                System.out.println(players.getPlayer2() + ", Answer me This: " + initializers.question.get(i + 1));
                String answer3 = sc.next();
                sc.nextLine();

                // same comparison, checks if its the same, if so, 4 points, if not then 3 points
                if (answer3.equals(initializers.SimplifiedAnswers.get(i + 1))) {
                    System.out.println("Good Job! You get 4 Points");
                    points2.add(4);
                } else if (answer3.equals(initializers.notSimplified.get(i + 1))) {
                    System.out.println("Good Work! However, the Answer wasnt in its most simplified form, You get 3 points");
                    points2.add(3);
                } else {
                    // Gives the users a second try to the question to see if they get it right, 2 points if it simplified 1 for not, then 0 if they get it wrong twice
                    System.out.println("Aww that Sucks, Lets try One More Time");
                    String answer4 = sc.next();
                    sc.nextLine();
                    if (answer4.equals(initializers.SimplifiedAnswers.get(i + 1))) {
                        System.out.println("Good Job! You get 2 Points");
                        points2.add(2);
                    }
                    if (answer4.equals(initializers.notSimplified.get(i + 1))) {
                        System.out.println("Good Work! However, the Answer wasn't in its most simplified form, You get 1 points");
                        points2.add(1);
                    } else {
                        System.out.println("Sorry " + players.getPlayer2() + ", you get no points");
                        points2.add(0);
                    }
                }

                // 3rd Player

                // repeats the same process with the other player but chooses the next question in the list given
                System.out.println(players.getPlayer3() + ", Answer me This: " + initializers.question.get(i + 2));
                String answer5 = sc.next();
                sc.nextLine();

                // same comparison, checks if its the same, if so, 4 points, if not then 3 points
                if (answer5.equals(initializers.SimplifiedAnswers.get(i + 2))) {
                    System.out.println("Good Job! You get 4 Points");
                    points3.add(4);
                } else if (answer5.equals(initializers.notSimplified.get(i + 2))) {
                    System.out.println("Good Work! However, the Answer wasnt in its most simplified form, You get 3 points");
                    points3.add(3);
                } else {
                    // Gives the users a second try to the question to see if they get it right, 2 points if it simplified 2 for not, then 0 if they get it wrong twice
                    System.out.println("Aww that Sucks, Lets try One More Time");
                    String answer6 = sc.next();
                    sc.nextLine();
                    if (answer6.equals(initializers.SimplifiedAnswers.get(i + 2))) {
                        System.out.println("Good Job! You get 2 Points");
                        points3.add(2);
                    }
                    if (answer6.equals(initializers.notSimplified.get(i + 2))) {
                        System.out.println("Good Work! However, the Answer wasn't in its most simplified form, You get 1 points");
                        points3.add(1);
                    } else {
                        System.out.println("Sorry " + players.getPlayer2() + ", you get no points");
                        points3.add(0);
                    }
                }
                i++;
            }
            // Sets the new arrays created to the the class method to add them all together
           int num1 = players.setAddPlayerPoints1(points1);
           int num2 =  players.setAddPlayerPoints2(points2);
           int num3 = players.setAddPlayerPoints3(points3);

            // Displays all the information out:
            System.out.println("Lets Sum up the Winnings:");
            System.out.println("\n" + players.getPlayer1() + ", You got " + num1 + " points. Looks like your average was " +
                    players.setPlayerAverage1(num1, amnt) + ". Nice Work.");
            System.out.println("\n" + players.getPlayer2() + ", You got " + num2 + " points. Looks like your average was " +
                    players.setPlayerAverage2(num2, amnt) + ". Well Done.");
            System.out.println("\n" + players.getPlayer3()  + ", You got " + num3 + " points. Looks like your average was " +
                    players.setPlayerAverage3(num3, amnt) + ". Awesome :)");

        }

        // Repeats the Steps for if there is 4 Players:
        else if (amntPlayers == 4) {

            initializers initializers = new initializers();
            ArrayList<Integer> points1 = new ArrayList<Integer>();
            ArrayList<Integer> points2 = new ArrayList<Integer>();
            ArrayList<Integer> points3 = new ArrayList<Integer>();
            ArrayList<Integer> points4 = new ArrayList<Integer>();
            players players = new players();


            // sets the player 1 and player 2, 3 names to give more of a game feeling
            System.out.println("Enter a name for Player 1");
            String player1 = sc.next();
            sc.nextLine();
            players.setPlayer1(player1);
            System.out.println("Enter a name for Player 2");
            String player2 = sc.next();
            sc.nextLine();
            players.setPlayer2(player2);
            System.out.println("Enter a name for Player 3");
            String player3 = sc.next();
            sc.nextLine();
            players.setPlayer3(player3);
            System.out.println("Enter a name for Player 4");
            String player4 = sc.next();
            sc.nextLine();
            players.setPlayer3(player4);


            // Ask the user how many questions to ask and loops it based on that.
            System.out.println("Set how many question to ask per person? ");
            int amnt = sc.nextInt();
            sc.nextLine();


            for (int i = 0; i < amnt; i++) {


                System.out.println(players.getPlayer1() + ", Answer me This: " + initializers.question.get(i));
                String answer = sc.next();
                sc.nextLine();
                //if it equals to the simplified answer then it will save the users points in a list
                if (answer.equals(initializers.SimplifiedAnswers.get(i))) {
                    System.out.println("Good Job! You get 4 Points");
                    points1.add(4);
                    // else it will compare to the not simplified Answer and if it is equal to it, it will then give the user the points in an array.
                } else if (answer.equals(initializers.notSimplified.get(i))) {
                    System.out.println("Good Work! However, the Answer wasnt in its most simplified form, You get 3 points");
                    points1.add(3);
                } else {
                    // It gives the user one more chance to try again, by using comparing statements similar to what was given before
                    System.out.println("Aww that Sucks, Lets try One More Time");
                    String answer2 = sc.next();
                    sc.nextLine();
                    if (answer2.equals(initializers.SimplifiedAnswers.get(i))) {
                        System.out.println("Good Job! You get 2 Points");
                        points1.add(2);
                    }
                    if (answer2.equals(initializers.notSimplified.get(i))) {
                        System.out.println("Good Work! However, the Answer wasn't in its most simplified form, You get 1 points");
                        points1.add(1);
                    } else {
                        // If they don't get it correct the second time then it gives no points to the user and adds zero to their arraylist
                        System.out.println("Sorry " + players.getPlayer1() + ", you get no points");
                        points1.add(0);
                    }
                }

                //2nd Player

                // repeats the same process with the  player 2 but chooses the next question in the list given
                System.out.println(players.getPlayer2() + ", Answer me This: " + initializers.question.get(i + 1));
                String answer3 = sc.next();
                sc.nextLine();

                // same comparison, checks if its the same, if so, 4 points, if not then 3 points
                if (answer3.equals(initializers.SimplifiedAnswers.get(i + 1))) {
                    System.out.println("Good Job! You get 4 Points");
                    points2.add(4);
                } else if (answer3.equals(initializers.notSimplified.get(i + 1))) {
                    System.out.println("Good Work! However, the Answer wasnt in its most simplified form, You get 3 points");
                    points2.add(3);
                } else {
                    // Gives the users a second try to the question to see if they get it right, 2 points if it simplified 1 for not, then 0 if they get it wrong twice
                    System.out.println("Aww that Sucks, Lets try One More Time");
                    String answer4 = sc.next();
                    sc.nextLine();
                    if (answer4.equals(initializers.SimplifiedAnswers.get(i + 1))) {
                        System.out.println("Good Job! You get 2 Points");
                        points2.add(2);
                    }
                    if (answer4.equals(initializers.notSimplified.get(i + 1))) {
                        System.out.println("Good Work! However, the Answer wasn't in its most simplified form, You get 1 points");
                        points2.add(1);
                    } else {
                        System.out.println("Sorry " + players.getPlayer2() + ", you get no points");
                        points2.add(0);
                    }
                }

                // 3rd Player

                // repeats the same process with the player 3 but chooses the next question in the list given
                System.out.println(players.getPlayer3() + ", Answer me This: " + initializers.question.get(i + 2));
                String answer5 = sc.next();
                sc.nextLine();

                // same comparison, checks if its the same, if so, 4 points, if not then 3 points
                if (answer5.equals(initializers.SimplifiedAnswers.get(i + 2))) {
                    System.out.println("Good Job! You get 4 Points");
                    points3.add(4);
                } else if (answer5.equals(initializers.notSimplified.get(i + 2))) {
                    System.out.println("Good Work! However, the Answer wasnt in its most simplified form, You get 3 points");
                    points3.add(3);
                } else {
                    // Gives the users a second try to the question to see if they get it right, 2 points if it simplified 1 for not, then 0 if they get it wrong twice
                    System.out.println("Aww that Sucks, Lets try One More Time");
                    String answer6 = sc.next();
                    sc.nextLine();
                    if (answer6.equals(initializers.SimplifiedAnswers.get(i + 2))) {
                        System.out.println("Good Job! You get 2 Points");
                        points3.add(2);
                    }
                    if (answer6.equals(initializers.notSimplified.get(i + 2))) {
                        System.out.println("Good Work! However, the Answer wasn't in its most simplified form, You get 1 points");
                        points3.add(1);
                    } else {
                        System.out.println("Sorry " + players.getPlayer2() + ", you get no points");
                        points3.add(0);
                    }
                }

                // 4th player

                // repeats the same process with the player 4 but chooses the next question in the list given
                System.out.println(players.getPlayer3() + ", Answer me This: " + initializers.question.get(i + 3));
                String answer7 = sc.next();
                sc.nextLine();

                // same comparison, checks if its the same, if so, 4 points, if not then 3 points
                if (answer7.equals(initializers.SimplifiedAnswers.get(i + 3))) {
                    System.out.println("Good Job! You get 4 Points");
                    points4.add(4);
                } else if (answer5.equals(initializers.notSimplified.get(i + 3))) {
                    System.out.println("Good Work! However, the Answer wasnt in its most simplified form, You get 3 points");
                    points4.add(3);
                } else {
                    // Gives the users a second try to the question to see if they get it right, 2 points if it simplified 1 for not, then 0 if they get it wrong twice
                    System.out.println("Aww that Sucks, Lets try One More Time");
                    String answer8 = sc.next();
                    sc.nextLine();
                    if (answer8.equals(initializers.SimplifiedAnswers.get(i + 3))) {
                        System.out.println("Good Job! You get 2 Points");
                        points4.add(2);
                    }
                    if (answer8.equals(initializers.notSimplified.get(i + 3))) {
                        System.out.println("Good Work! However, the Answer wasn't in its most simplified form, You get 1 points");
                        points4.add(1);
                    } else {
                        System.out.println("Sorry " + players.getPlayer2() + ", you get no points");
                        points4.add(0);
                    }
                }


                i++;
            }
            // Sets the new arrays created to the the class method to add them all together
            int num1 =players.setAddPlayerPoints1(points1);
            int num2 =players.setAddPlayerPoints2(points2);
            int num3 =players.setAddPlayerPoints3(points3);
            int num4 =players.setAddPlayerPoints4(points4);

            // Displays all the information out:
            System.out.println("Lets Sum up the Winnings:");
            System.out.println("\n" + players.getPlayer1() + " You got " + num1 + " points. Looks like your average was " +
                    players.setPlayerAverage1(num1, amnt) + ". Nice Work.");
            System.out.println("\n" + players.getPlayer2() + " You got " + num2 + " points. Looks like your average was " +
                    players.setPlayerAverage2(num2 , amnt) + ". Well Done.");
            System.out.println("\n" + players.getPlayer3() + " You got " + num3 + " points. Looks like your average was " +
                    players.setPlayerAverage3(num3, amnt) + ". Awesome :)");
            System.out.println("\n" + players.getPlayer4() + " You got " + num4 + " points. Looks like your average was " +
                    players.setPlayerAverage4(num4, amnt) + ". Awesome :)");

        } else if (amntPlayers > 5) {
            System.out.println("Not Supported Yet");
        } else {
            System.out.println("Invalid Response.");
        }
    }
}
Editor is loading...