Compare commits
5 commits
907e8c096e
...
92a33e4499
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92a33e4499 | ||
|
|
55338e94cd | ||
|
|
242f37411b | ||
|
|
0e3b267847 | ||
|
|
a3644df8c2 |
6 changed files with 235 additions and 10 deletions
|
|
@ -4,8 +4,11 @@
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="8658cbac-7347-4046-83e8-57065c86d2b8" name="Changes" comment="java class file update">
|
<list default="true" id="8658cbac-7347-4046-83e8-57065c86d2b8" name="Changes" comment="updated java junk files">
|
||||||
<change beforePath="$PROJECT_DIR$/practice_projects/src/GuessANumber.java" beforeDir="false" afterPath="$PROJECT_DIR$/practice_projects/src/GuessANumber.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/practice_projects/src/Banking.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/practice_projects/src/Dice.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/GuessANumber.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/java_practice/GuessANumber.class" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
|
@ -34,10 +37,10 @@
|
||||||
"accountId": "1865e200-c7ac-4f58-baed-f72f06b5746c"
|
"accountId": "1865e200-c7ac-4f58-baed-f72f06b5746c"
|
||||||
}
|
}
|
||||||
}</component>
|
}</component>
|
||||||
<component name="KubernetesApiPersistence"><![CDATA[{}]]></component>
|
<component name="KubernetesApiPersistence">{}</component>
|
||||||
<component name="KubernetesApiProvider"><![CDATA[{
|
<component name="KubernetesApiProvider">{
|
||||||
"isMigrated": true
|
"isMigrated": true
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="McpProjectServerCommands">
|
<component name="McpProjectServerCommands">
|
||||||
<commands />
|
<commands />
|
||||||
<urls />
|
<urls />
|
||||||
|
|
@ -58,7 +61,9 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
|
"Application.Banking.executor": "Run",
|
||||||
"Application.Calculator.executor": "Run",
|
"Application.Calculator.executor": "Run",
|
||||||
|
"Application.Dice.executor": "Run",
|
||||||
"Application.EnhancedSwitches.executor": "Run",
|
"Application.EnhancedSwitches.executor": "Run",
|
||||||
"Application.GuessANumber.executor": "Run",
|
"Application.GuessANumber.executor": "Run",
|
||||||
"Application.Main.executor": "Run",
|
"Application.Main.executor": "Run",
|
||||||
|
|
@ -92,7 +97,7 @@
|
||||||
"project.structure.last.edited": "SDKs",
|
"project.structure.last.edited": "SDKs",
|
||||||
"project.structure.proportion": "0.15",
|
"project.structure.proportion": "0.15",
|
||||||
"project.structure.side.proportion": "0.2",
|
"project.structure.side.proportion": "0.2",
|
||||||
"settings.editor.selected.configurable": "configurable.group.language",
|
"settings.editor.selected.configurable": "editing.templates",
|
||||||
"to.speed.mode.migration.done": "true",
|
"to.speed.mode.migration.done": "true",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
|
|
@ -120,7 +125,8 @@
|
||||||
<workItem from="1767557093354" duration="14440000" />
|
<workItem from="1767557093354" duration="14440000" />
|
||||||
<workItem from="1767678323979" duration="16130000" />
|
<workItem from="1767678323979" duration="16130000" />
|
||||||
<workItem from="1767837943314" duration="237000" />
|
<workItem from="1767837943314" duration="237000" />
|
||||||
<workItem from="1767838192168" duration="8317000" />
|
<workItem from="1767838192168" duration="17826000" />
|
||||||
|
<workItem from="1768158295756" duration="2394000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="updated module output folders">
|
<task id="LOCAL-00001" summary="updated module output folders">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
|
|
@ -314,7 +320,23 @@
|
||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1767855617721</updated>
|
<updated>1767855617721</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="25" />
|
<task id="LOCAL-00025" summary="added notes to explain IF statement">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1767855849671</created>
|
||||||
|
<option name="number" value="00025" />
|
||||||
|
<option name="presentableId" value="LOCAL-00025" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1767855849671</updated>
|
||||||
|
</task>
|
||||||
|
<task id="LOCAL-00026" summary="updated java junk files">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1767855859506</created>
|
||||||
|
<option name="number" value="00026" />
|
||||||
|
<option name="presentableId" value="LOCAL-00026" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1767855859506</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="27" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
|
@ -354,7 +376,9 @@
|
||||||
<MESSAGE value="made a basic calculator" />
|
<MESSAGE value="made a basic calculator" />
|
||||||
<MESSAGE value="coded a Random number Guessing game" />
|
<MESSAGE value="coded a Random number Guessing game" />
|
||||||
<MESSAGE value="java class file update" />
|
<MESSAGE value="java class file update" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="java class file update" />
|
<MESSAGE value="added notes to explain IF statement" />
|
||||||
|
<MESSAGE value="updated java junk files" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="updated java junk files" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XSLT-Support.FileAssociations.UIState">
|
<component name="XSLT-Support.FileAssociations.UIState">
|
||||||
<expand />
|
<expand />
|
||||||
|
|
|
||||||
BIN
out/production/java_practice/Banking.class
Normal file
BIN
out/production/java_practice/Banking.class
Normal file
Binary file not shown.
BIN
out/production/java_practice/Dice.class
Normal file
BIN
out/production/java_practice/Dice.class
Normal file
Binary file not shown.
Binary file not shown.
77
practice_projects/src/Banking.java
Normal file
77
practice_projects/src/Banking.java
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Banking {
|
||||||
|
|
||||||
|
static Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
public static void main(String[] args){
|
||||||
|
|
||||||
|
double balance = 0.00;
|
||||||
|
boolean isRunning = true;
|
||||||
|
|
||||||
|
while(isRunning) {
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println("***************");
|
||||||
|
System.out.println("BANKING PROGRAM");
|
||||||
|
System.out.println("***************");
|
||||||
|
System.out.println("1. Show Balance");
|
||||||
|
System.out.println("2. Deposit");
|
||||||
|
System.out.println("3. Withdraw");
|
||||||
|
System.out.println("4. Exit");
|
||||||
|
System.out.println("***************");
|
||||||
|
System.out.print("Enter your choice (1-4): ");
|
||||||
|
|
||||||
|
int choice = scanner.nextInt();
|
||||||
|
|
||||||
|
switch (choice) {
|
||||||
|
case 1 -> balance(balance);
|
||||||
|
case 2 -> balance += deposit();
|
||||||
|
case 3 -> balance -= withdraw(balance);
|
||||||
|
case 4 -> isRunning = false;
|
||||||
|
default -> System.out.println("Invalid choice");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("***************");
|
||||||
|
System.out.println("Have a nice day!");
|
||||||
|
System.out.println("***************");
|
||||||
|
|
||||||
|
scanner.close();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void balance(double balance){
|
||||||
|
System.out.println("***************");
|
||||||
|
System.out.printf("$%.2f\n", balance);
|
||||||
|
}
|
||||||
|
|
||||||
|
static double deposit(){
|
||||||
|
System.out.print("Enter amount to deposit: ");
|
||||||
|
double amount = scanner.nextDouble();
|
||||||
|
|
||||||
|
if(amount < 0){
|
||||||
|
System.out.println("Amount can't be negative! ");
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static double withdraw(double balance){
|
||||||
|
System.out.print("Enter amount to withdraw: ");
|
||||||
|
double amount = scanner.nextDouble();
|
||||||
|
|
||||||
|
if(amount < 0){
|
||||||
|
System.out.println("Amount can't be negative! ");
|
||||||
|
return 0;
|
||||||
|
} else if (amount > balance){
|
||||||
|
System.out.println("INSUFFICIENT FUNDS!");
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
124
practice_projects/src/Dice.java
Normal file
124
practice_projects/src/Dice.java
Normal file
|
|
@ -0,0 +1,124 @@
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Dice {
|
||||||
|
|
||||||
|
static Random random = new Random();
|
||||||
|
|
||||||
|
// JAVA DICE ROLLER PROGRAM
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
int numOfDice;
|
||||||
|
int total;
|
||||||
|
|
||||||
|
System.out.println("**************************");
|
||||||
|
System.out.println("WELCOME TO THE DICE ROLLER");
|
||||||
|
System.out.println("**************************");
|
||||||
|
System.out.println("Enter the # of dice to roll: ");
|
||||||
|
numOfDice = scanner.nextInt();
|
||||||
|
|
||||||
|
if(numOfDice <= 0){
|
||||||
|
System.out.print("# of dice must be more than 0!");
|
||||||
|
} else {
|
||||||
|
int[] rolls = rollDice(numOfDice);
|
||||||
|
total = calcTotal(rolls);
|
||||||
|
printTotal(total);
|
||||||
|
}
|
||||||
|
|
||||||
|
scanner.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int[] rollDice(int numOfDice){
|
||||||
|
|
||||||
|
int[] rolls = new int[numOfDice];
|
||||||
|
|
||||||
|
for(int i = 0; i < numOfDice; i++){
|
||||||
|
int roll = random.nextInt(1, 7);
|
||||||
|
rolls[i] = roll;
|
||||||
|
printDie(roll);
|
||||||
|
System.out.println("You rolled: " + roll);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rolls;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int calcTotal(int[] rolls){
|
||||||
|
int total = 0;
|
||||||
|
System.out.print("\nDice rolled: ");
|
||||||
|
for(int roll : rolls){
|
||||||
|
System.out.print("[ " + roll + " ]");
|
||||||
|
total+= roll;
|
||||||
|
}
|
||||||
|
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void printDie(int roll){
|
||||||
|
|
||||||
|
String dice1 = """
|
||||||
|
-------
|
||||||
|
| |
|
||||||
|
| ● |
|
||||||
|
| |
|
||||||
|
-------
|
||||||
|
""";
|
||||||
|
|
||||||
|
String dice2 = """
|
||||||
|
-------
|
||||||
|
| ● |
|
||||||
|
| |
|
||||||
|
| ● |
|
||||||
|
-------
|
||||||
|
""";
|
||||||
|
|
||||||
|
String dice3 = """
|
||||||
|
-------
|
||||||
|
| ● |
|
||||||
|
| ● |
|
||||||
|
| ● |
|
||||||
|
-------
|
||||||
|
""";
|
||||||
|
|
||||||
|
String dice4 = """
|
||||||
|
-------
|
||||||
|
| ● ● |
|
||||||
|
| |
|
||||||
|
| ● ● |
|
||||||
|
-------
|
||||||
|
""";
|
||||||
|
|
||||||
|
String dice5 = """
|
||||||
|
-------
|
||||||
|
| ● ● |
|
||||||
|
| ● |
|
||||||
|
| ● ● |
|
||||||
|
-------
|
||||||
|
""";
|
||||||
|
|
||||||
|
String dice6 = """
|
||||||
|
-------
|
||||||
|
| ● ● |
|
||||||
|
| ● ● |
|
||||||
|
| ● ● |
|
||||||
|
-------
|
||||||
|
""";
|
||||||
|
|
||||||
|
switch (roll) {
|
||||||
|
case 1 -> System.out.print(dice1);
|
||||||
|
case 2 -> System.out.print(dice2);
|
||||||
|
case 3 -> System.out.print(dice3);
|
||||||
|
case 4 -> System.out.print(dice4);
|
||||||
|
case 5 -> System.out.print(dice5);
|
||||||
|
case 6 -> System.out.print(dice6);
|
||||||
|
default -> System.out.print("Invalid roll");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void printTotal(int total){
|
||||||
|
System.out.println("\nTotal: " + total);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue