File tree Expand file tree Collapse file tree 6 files changed +45
-1
lines changed
app/src/main/java/hexlet/code Expand file tree Collapse file tree 6 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 1616![ Calc win] ( screenshots/CalcGame-win.png )
1717### Defeat in the app Calc
1818![ Calc lose] ( screenshots/CalcGame-lose.png )
19+ ### Victory in the app GCD
20+ ![ GCD win] ( screenshots/GCDGame-win.png )
21+ ### Defeat in the app GCD
22+ ![ GCD lose] ( screenshots/GCDGame-lose.png )
1923### Exiting the app
2024![ Exit] ( screenshots/Exiting-app.png )
Original file line number Diff line number Diff line change 33
44import hexlet .code .games .Calc ;
55import hexlet .code .games .Even ;
6+ import hexlet .code .games .GCD ;
67
78public class App {
89 public static void main (String [] args ) {
910 Scanner scanner = new Scanner (System .in );
1011 try {
1112 System .out .println ("Please enter the game number and press Enter." );
12- System .out .print ("1 - Greet\n 2 - Even\n 3 - Cacl\n 0 - Exit\n Your choice: " );
13+ System .out .print ("1 - Greet\n 2 - Even\n 3 - Cacl\n 4 - GCD \ n 0 - Exit\n Your choice: " );
1314 int usersChoise = 0 ;
1415
1516 try {
@@ -33,6 +34,11 @@ public static void main(String[] args) {
3334 Calc .startGameCalc ();
3435 Engine .runGame (Engine .CALC_GAME_NUMBER , scanner );
3536 break ;
37+ case 4 :
38+ Cli .greetings (scanner );
39+ GCD .startGameGCD ();
40+ Engine .runGame (Engine .GCD_GAME_NUMBER , scanner );
41+ break ;
3642 case 0 :
3743 break ;
3844 }
Original file line number Diff line number Diff line change 44
55import hexlet .code .games .Calc ;
66import hexlet .code .games .Even ;
7+ import hexlet .code .games .GCD ;
78
89public class Engine {
910 private static int scoreCounter = 0 ;
@@ -12,19 +13,24 @@ public class Engine {
1213 private static StringBuilder usersAnswer = new StringBuilder ();
1314 static final int EVEN_GAME_NUMBER = 2 ;
1415 static final int CALC_GAME_NUMBER = 3 ;
16+ static final int GCD_GAME_NUMBER = 4 ;
1517
1618 public static void runGame (int gameNumber , Scanner scanner ) {
1719 for (int i = 0 ; i <scoreToWin ; i ++) {
1820 correctAnswer .setLength (0 );
1921 usersAnswer .setLength (0 );
22+
2023 switch (gameNumber ) {
2124 case EVEN_GAME_NUMBER :
2225 correctAnswer .append (Even .generateCorrectAnswer ());
2326 break ;
2427 case CALC_GAME_NUMBER :
2528 correctAnswer .append (Calc .generateCorrectAnswer ());
2629 break ;
30+ case GCD_GAME_NUMBER :
31+ correctAnswer .append (GCD .generateCorrectAnswer ());
2732 }
33+
2834 System .out .print ("Your answer: " );
2935 usersAnswer .append (scanner .nextLine ());
3036 if (usersAnswer .toString ().equals (correctAnswer .toString ())) {
Original file line number Diff line number Diff line change 1+ package hexlet .code .games ;
2+
3+ public class GCD {
4+ private static int numberA ;
5+ private static int numberB ;
6+ private static int numberC ;
7+
8+ public static void startGameGCD () {
9+ System .out .println ("Find the greatest common divisor of given numbers." );
10+ }
11+
12+ public static String generateCorrectAnswer () {
13+ numberA = (int ) (Math .random ()*100 );
14+ numberB = (int ) (Math .random ()*100 );
15+ System .out .println ("Question: " + numberA + " " + numberB );
16+ while (true ) {
17+ if (numberB > 0 ) {
18+ numberC = numberA ;
19+ numberA = numberB ;
20+ numberB = numberC % numberB ;
21+ }
22+ else {
23+ break ;
24+ }
25+ }
26+ return String .valueOf (numberA );
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments