Skip to content

Commit 63ce456

Browse files
committed
adhering to OOP
1 parent 5bf9b7b commit 63ce456

File tree

8 files changed

+470
-0
lines changed

8 files changed

+470
-0
lines changed

.idea/misc.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 363 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Phonetic Game.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$/../Phonetic Game">
6+
<sourceFolder url="file://$MODULE_DIR$/../Phonetic Game/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
1.73 KB
Binary file not shown.
1.32 KB
Binary file not shown.

src/Game.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import java.util.Random;
2+
import java.util.Scanner;
3+
4+
public class Game {
5+
private char[] alpha;
6+
private char randAlpha;
7+
private char[] upperAndLower;
8+
9+
public void printAlpha(char array[]) {
10+
int index = 0;
11+
for (char alphabets = 'A'; alphabets <= 'Z'; alphabets++) {
12+
array[index++] = alphabets;
13+
}
14+
this.alpha = array;
15+
}
16+
17+
public void randomAlphabet(char array[]){
18+
Random randNum = new Random(); //random() method returns a random number between 0.0 and 0.9999
19+
int R = randNum.nextInt(26);
20+
/*Returns a pseudorandom, uniformly distributed int value between 0
21+
(inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.*/
22+
char randAlpha = array[R]; // chooses a random letter
23+
System.out.println(randAlpha);
24+
this.randAlpha = randAlpha;
25+
26+
}
27+
28+
public void userInput(){
29+
Scanner Reading = new Scanner(System.in);//reading from input
30+
System.out.println("What was the letter?");
31+
String strUpper = Reading.nextLine();
32+
String strLower = strUpper.toUpperCase(); // allows for lower and upper case
33+
char genAlphaUpper = strUpper.charAt(0); char genAlphaLower = strLower.charAt(0); // since input is read as string, I convert these to characters
34+
char[] upperAndLower = {genAlphaUpper, genAlphaLower};
35+
this.upperAndLower = upperAndLower;
36+
}
37+
/*----------------------------------------------Getters-------------------------------------------------------*/
38+
public char[] getAlpha() {
39+
return alpha;
40+
}
41+
42+
public char getRandAlpha() {
43+
return randAlpha;
44+
}
45+
46+
public char[] getUpperAndLower() {
47+
return upperAndLower;
48+
}
49+
/*------------------------------------------------------------------------------------------------------------*/
50+
}

src/Main.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class Main {
2+
private static final int numGames = 5; // determines number of games
3+
4+
public static void main(String[] args) {
5+
char alpha[] = new char[26]; // can also write char[] alpha
6+
char randAlpha;
7+
char[] upperAndLower;
8+
9+
Game phoneticGame = new Game();
10+
11+
for(int i = 0; i <= numGames; i++){ // Does five rounds of game
12+
phoneticGame.printAlpha(alpha);
13+
alpha = phoneticGame.getAlpha();
14+
15+
phoneticGame.randomAlphabet(alpha);
16+
randAlpha = phoneticGame.getRandAlpha();
17+
18+
phoneticGame.userInput();
19+
upperAndLower = phoneticGame.getUpperAndLower();
20+
if(upperAndLower[0] == randAlpha || upperAndLower[1] == randAlpha){
21+
System.out.println("CORRECT\n");
22+
}
23+
else {
24+
System.out.println("WRONG! The correct choice is: " + randAlpha + "\n");
25+
}
26+
}
27+
28+
} // end main
29+
} // end main class

0 commit comments

Comments
 (0)