Skip to content

Commit e3dca83

Browse files
add Progression.java, mod README.md, App.java
1 parent 56d3a42 commit e3dca83

File tree

8 files changed

+66
-38
lines changed

8 files changed

+66
-38
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ https://asciinema.org/a/5NUp6quilr3DtKLHDEYSfAcZ2
77
### Demo 4 (GCD)
88
https://asciinema.org/a/5TK9BqwuQriLXfKwwefoqJjLP
99

10+
### Demo 5 (Progression)
11+
https://asciinema.org/a/lB79E4WkEmp1207S7mYMDvjjQ
12+
1013

1114
### Hexlet tests and linter status:
1215
[![Actions Status](https://github.com/alexeichuprikov/qa-auto-engineer-java-project-61/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/alexeichuprikov/qa-auto-engineer-java-project-61/actions)

app/.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ build/
66
INFO.md
77

88
### IntelliJ IDEA ###
9+
.idea/
10+
*.iws
11+
*.iml
12+
*.ipr
913
.idea/modules.xml
1014
.idea/jarRepositories.xml
1115
.idea/compiler.xml
1216
.idea/libraries/
13-
*.iws
14-
*.iml
15-
*.ipr
1617
out/
1718
!**/src/main/**/out/
1819
!**/src/test/**/out/
19-
.idea/
20+
2021

2122
### Eclipse ###
2223
.apt_generated

app/.idea/.gitignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

app/.idea/gradle.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/.idea/misc.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import hexlet.code.games.Calc;
44
import hexlet.code.games.Even;
55
import hexlet.code.games.Gcd;
6+
import hexlet.code.games.Progression;
67

78
import java.util.Scanner;
89

@@ -14,6 +15,7 @@ public static void main(String[] args) {
1415
System.out.println("2 - Even");
1516
System.out.println("3 - Calc");
1617
System.out.println("4 - GCD");
18+
System.out.println("5 - Progression");
1719
System.out.println("0 - Exit");
1820
System.out.print("Your choice : ");
1921
String option = scanner.nextLine();
@@ -31,6 +33,9 @@ public static void main(String[] args) {
3133
case "4":
3234
Gcd.play();
3335
break;
36+
case "5":
37+
Progression.play();
38+
break;
3439
}
3540
scanner.close();
3641
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package hexlet.code.games;
2+
3+
import hexlet.code.Engine;
4+
5+
import java.util.Scanner;
6+
7+
public class Progression {
8+
public static void play() {
9+
String userName = Engine.description();
10+
System.out.println("What number is missing in the progression?");
11+
Scanner scanner = new Scanner(System.in);
12+
13+
14+
for (int i = 1; i <= Engine.rounds; i++) {
15+
int start = (int) (Math.random() * 20) + 1;
16+
int step = (int) (Math.random() * 10) + 1;
17+
int length = 10;
18+
int[] sequence = addSequence(start, step, length);
19+
20+
int hideIndex = (int) (Math.random() * length);
21+
int hideValue = sequence[hideIndex];
22+
23+
System.out.print("Question: ");
24+
for (int j = 0; j < length; j++) {
25+
if (j == hideIndex) {
26+
System.out.print(".. ");
27+
} else {
28+
System.out.print(sequence[j] + " ");
29+
}
30+
}
31+
System.out.print("Your answer: ");
32+
int answer = scanner.nextInt();
33+
34+
if (answer == hideValue) {
35+
System.out.println("Correct!");
36+
} else {
37+
System.out.println("'" + answer + "' is wrong answer ;(. Correct answer was '" + hideValue + "'.");
38+
System.out.println("Let's try again, " + userName + "!");
39+
return;
40+
}
41+
}
42+
System.out.println("Congratulations, " + userName + "!");
43+
}
44+
45+
public static int[] addSequence(int start, int step, int length) {
46+
int[] sequence = new int[length];
47+
48+
for (int i = 0; i < length; i++) {
49+
sequence[i] = start + i * step;
50+
}
51+
return sequence;
52+
}
53+
}

0 commit comments

Comments
 (0)