Skip to content

Commit 4080321

Browse files
committed
added game №5 progression
1 parent d64b99c commit 4080321

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

app/src/main/java/hexlet/code/App.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static void main(String[] args) {
1212
2 - Even
1313
3 - Calc
1414
4 - GCD
15+
5 - Progression
1516
0 - Exit
1617
Your choice:""");
1718

@@ -28,6 +29,8 @@ public static void main(String[] args) {
2829

2930
case "4" -> Games.gcd();
3031

32+
case "5" -> Games.progression();
33+
3134
default -> System.out.println("Invalid choice, please try again.");
3235

3336
}

app/src/main/java/hexlet/code/Engine.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package hexlet.code;
22

3+
34
import java.util.Scanner;
45

56
public class Engine {
67
public static final int rounds = 3;
78

89
public static void skeletonOfGames(String mainGameQuestion, String[] question, String[] correctAnswer) {
10+
911
Scanner scanner = new Scanner(System.in);
1012
System.out.println("""
1113
Welcome to the Brain Games!
@@ -35,12 +37,3 @@ public static void skeletonOfGames(String mainGameQuestion, String[] question, S
3537
System.out.println("Congratulations, " + name + "!");
3638
}
3739
}
38-
39-
40-
41-
42-
//import java.util.Arrays;
43-
//import java.util.List;
44-
//import java.util.Scanner;
45-
//import java.util.Random;
46-
//import hexlet.code.Engine;

app/src/main/java/hexlet/code/Games.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public static int calc() {
6363
}
6464

6565

66+
6667
// Game №4 GCD
6768
public static int gcd() {
6869
Random random = new Random();
@@ -88,6 +89,36 @@ public static int gcd() {
8889
Engine.skeletonOfGames(mainGameQuestion, question, correctAnswer);
8990
return 0;
9091
}
91-
}
9292

9393

94+
95+
// Game №5 Progression
96+
public static int progression() {
97+
Random random = new Random();
98+
String mainGameQuestion = "What number is missing in the progression?";
99+
100+
String[] question = new String[Engine.rounds];
101+
String[] correctAnswer = new String[Engine.rounds];
102+
103+
for (var i = 0; i < Engine.rounds; i++) {
104+
105+
int[] array = new int[10];
106+
107+
int step = random.nextInt(9) + 1;
108+
int start = random.nextInt(14) + 1;
109+
110+
for (int j = 0; j < 10; j++) {
111+
array[j] = start + j * step;
112+
}
113+
114+
int indexFromArray = random.nextInt(9);
115+
String arrayToString = Arrays.toString(array);
116+
String hideNumber = arrayToString.replaceAll(String.valueOf(array[indexFromArray]), "..");
117+
question[i] = hideNumber;
118+
correctAnswer[i] = String.valueOf(array[indexFromArray]);
119+
120+
}
121+
Engine.skeletonOfGames(mainGameQuestion, question, correctAnswer);
122+
return 0;
123+
}
124+
}

0 commit comments

Comments
 (0)