Compare commits
4 commits
190d61afe6
...
f36c339509
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f36c339509 | ||
|
|
0f1b64f5d4 | ||
|
|
f19b97c13b | ||
|
|
4969478280 |
6 changed files with 138 additions and 6 deletions
|
|
@ -4,10 +4,10 @@
|
|||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="8658cbac-7347-4046-83e8-57065c86d2b8" name="Changes" comment="Made a calculator using Switches">
|
||||
<change afterPath="$PROJECT_DIR$/out/production/java_practice/Calculator.class" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/practice_projects/src/Calculator.java" afterDir="false" />
|
||||
<list default="true" id="8658cbac-7347-4046-83e8-57065c86d2b8" name="Changes" comment="made a basic calculator">
|
||||
<change afterPath="$PROJECT_DIR$/practice_projects/src/GuessANumber.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/java_practice/WhileLoops.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/java_practice/WhileLoops.class" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
|
@ -62,8 +62,10 @@
|
|||
"keyToString": {
|
||||
"Application.Calculator.executor": "Run",
|
||||
"Application.EnhancedSwitches.executor": "Run",
|
||||
"Application.GuessANumber.executor": "Run",
|
||||
"Application.Main.executor": "Run",
|
||||
"Application.TempConverter.executor": "Run",
|
||||
"Application.WhileLoops.executor": "Run",
|
||||
"Application.compountInterest.executor": "Run",
|
||||
"Application.ifStatements.executor": "Run",
|
||||
"Application.madLibs.executor": "Run",
|
||||
|
|
@ -120,7 +122,7 @@
|
|||
<workItem from="1767557093354" duration="14440000" />
|
||||
<workItem from="1767678323979" duration="16130000" />
|
||||
<workItem from="1767837943314" duration="237000" />
|
||||
<workItem from="1767838192168" duration="2611000" />
|
||||
<workItem from="1767838192168" duration="7995000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="updated module output folders">
|
||||
<option name="closed" value="true" />
|
||||
|
|
@ -274,7 +276,31 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1767839480914</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="20" />
|
||||
<task id="LOCAL-00020" summary="Made a calculator using Switches">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767840813715</created>
|
||||
<option name="number" value="00020" />
|
||||
<option name="presentableId" value="LOCAL-00020" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767840813715</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00021" summary="Explored while and do while loops">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767853449206</created>
|
||||
<option name="number" value="00021" />
|
||||
<option name="presentableId" value="LOCAL-00021" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767853449206</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00022" summary="made a basic calculator">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767853460560</created>
|
||||
<option name="number" value="00022" />
|
||||
<option name="presentableId" value="LOCAL-00022" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767853460560</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="23" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
|
|
@ -310,7 +336,9 @@
|
|||
<MESSAGE value="updated java version to 17 so I can use switched (Introduced in 14" />
|
||||
<MESSAGE value="Did a few base cases using enhanced switches" />
|
||||
<MESSAGE value="Made a calculator using Switches" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Made a calculator using Switches" />
|
||||
<MESSAGE value="Explored while and do while loops" />
|
||||
<MESSAGE value="made a basic calculator" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="made a basic calculator" />
|
||||
</component>
|
||||
<component name="XSLT-Support.FileAssociations.UIState">
|
||||
<expand />
|
||||
|
|
|
|||
Binary file not shown.
BIN
out/production/java_practice/GuessANumber.class
Normal file
BIN
out/production/java_practice/GuessANumber.class
Normal file
Binary file not shown.
BIN
out/production/java_practice/WhileLoops.class
Normal file
BIN
out/production/java_practice/WhileLoops.class
Normal file
Binary file not shown.
58
practice_projects/src/GuessANumber.java
Normal file
58
practice_projects/src/GuessANumber.java
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import java.util.Scanner;
|
||||
import java.util.Random;
|
||||
|
||||
public class GuessANumber {
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
// Intro at top of screen
|
||||
System.out.println("=== !! NUMBER GUESSING GAME !! ===");
|
||||
System.out.println("Guess a number between 1-100");
|
||||
System.out.println("--- You have 10 guesses --- ");
|
||||
|
||||
// have computer pick a random number 1-100
|
||||
Random random = new Random();
|
||||
int number = random.nextInt(1, 101); // end range is not included. so we use 101
|
||||
|
||||
// Declare guess so we can use it for our while loop
|
||||
int guess = 0;
|
||||
int chances = 10; // Only give them 10 chances to guess it
|
||||
|
||||
// While logic to process guesses
|
||||
while(guess != number){
|
||||
System.out.print("\nEnter a guess: ");
|
||||
guess = scanner.nextInt();
|
||||
|
||||
if(chances == 1){
|
||||
System.out.println("\n####### YOU LOSE!!! #######");
|
||||
System.out.println("--- The number was [ " + number + " ] ---");
|
||||
break;
|
||||
} else if(guess > number){
|
||||
System.out.println("\nTOO HIGH. Try again");
|
||||
chances--;
|
||||
System.out.println("-- " + chances + " guesses remaining. --");
|
||||
continue;
|
||||
} else if(guess < number){
|
||||
System.out.println("\nTOO LOW. Try again");
|
||||
chances--;
|
||||
System.out.println("-- " + chances + " guesses remaining. --");
|
||||
continue;
|
||||
} else {
|
||||
// Winner message with the correct number
|
||||
System.out.println("---------------------------------------");
|
||||
System.out.println("\n***** WINNER * WINNER * WINNER *****");
|
||||
System.out.println("********* YOU GUESSED IT! ********* \n");
|
||||
System.out.println("\n----- The number was [ " + number + " ] -----");
|
||||
System.out.println(" -- You had " + chances + " guesses remaining --");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
scanner.close();
|
||||
|
||||
}
|
||||
}
|
||||
46
practice_projects/src/WhileLoops.java
Normal file
46
practice_projects/src/WhileLoops.java
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class WhileLoops {
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
String name = "";
|
||||
|
||||
// Get users name
|
||||
while(name.isEmpty()){
|
||||
System.out.print("Enter your name: ");
|
||||
name = scanner.nextLine();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// get users age
|
||||
int age = 0;
|
||||
|
||||
do{
|
||||
System.out.println("Enter your age: ");
|
||||
System.out.println("(Your age can't be negative)");
|
||||
age = scanner.nextInt();
|
||||
|
||||
}while(age < 0);
|
||||
|
||||
// Greet them
|
||||
System.out.printf("Hello %s. You are %d years old!\n", name, age);
|
||||
|
||||
|
||||
// ask a user to enter a number between 1 - 10;
|
||||
int number = 0;
|
||||
do{
|
||||
System.out.print("Enter a number between 1-10: ");
|
||||
number = scanner.nextInt();
|
||||
|
||||
|
||||
} while(number < 1 || number > 10);
|
||||
|
||||
System.out.printf("Wow %s. You picked %d", name, number);
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue