Made a calculator using Switches
This commit is contained in:
parent
9f00555fed
commit
190d61afe6
3 changed files with 145 additions and 53 deletions
|
|
@ -4,20 +4,10 @@
|
||||||
<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="updated junk java files">
|
<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" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/java_practice.iml" beforeDir="false" afterPath="$PROJECT_DIR$/java_practice.iml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/out/production/java_practice/Main.class" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/out/production/java_practice/TempConverter.class" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/out/production/java_practice/compoundInterest.class" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/out/production/java_practice/ifStatements.class" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/out/production/java_practice/madLibs.class" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/out/production/java_practice/printF.class" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/out/production/java_practice/randomNums.class" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/out/production/java_practice/shoppingCart.class" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/out/production/java_practice/substrings.class" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/out/production/java_practice/trueFalse.class" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/out/production/java_practice/weightConverter.class" beforeDir="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" />
|
||||||
|
|
@ -46,6 +36,10 @@
|
||||||
"accountId": "1865e200-c7ac-4f58-baed-f72f06b5746c"
|
"accountId": "1865e200-c7ac-4f58-baed-f72f06b5746c"
|
||||||
}
|
}
|
||||||
}</component>
|
}</component>
|
||||||
|
<component name="KubernetesApiPersistence"><![CDATA[{}]]></component>
|
||||||
|
<component name="KubernetesApiProvider"><![CDATA[{
|
||||||
|
"isMigrated": true
|
||||||
|
}]]></component>
|
||||||
<component name="McpProjectServerCommands">
|
<component name="McpProjectServerCommands">
|
||||||
<commands />
|
<commands />
|
||||||
<urls />
|
<urls />
|
||||||
|
|
@ -64,44 +58,45 @@
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"Application.Calculator.executor": "Run",
|
"Application.Calculator.executor": "Run",
|
||||||
"Application.Main.executor": "Run",
|
"Application.EnhancedSwitches.executor": "Run",
|
||||||
"Application.TempConverter.executor": "Run",
|
"Application.Main.executor": "Run",
|
||||||
"Application.compountInterest.executor": "Run",
|
"Application.TempConverter.executor": "Run",
|
||||||
"Application.ifStatements.executor": "Run",
|
"Application.compountInterest.executor": "Run",
|
||||||
"Application.madLibs.executor": "Run",
|
"Application.ifStatements.executor": "Run",
|
||||||
"Application.printF.executor": "Run",
|
"Application.madLibs.executor": "Run",
|
||||||
"Application.randomNums.executor": "Run",
|
"Application.printF.executor": "Run",
|
||||||
"Application.shoppingCart.executor": "Run",
|
"Application.randomNums.executor": "Run",
|
||||||
"Application.substrings.executor": "Run",
|
"Application.shoppingCart.executor": "Run",
|
||||||
"Application.tempConverter.executor": "Run",
|
"Application.substrings.executor": "Run",
|
||||||
"Application.trueFalse.executor": "Run",
|
"Application.tempConverter.executor": "Run",
|
||||||
"Application.weightConverter.executor": "Run",
|
"Application.trueFalse.executor": "Run",
|
||||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
"Application.weightConverter.executor": "Run",
|
||||||
"RunOnceActivity.MCP Project settings loaded": "true",
|
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.MCP Project settings loaded": "true",
|
||||||
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
||||||
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultModelSelectionForGA.v1": "true",
|
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
||||||
"git-widget-placeholder": "main",
|
"com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultModelSelectionForGA.v1": "true",
|
||||||
"junie.onboarding.icon.badge.shown": "true",
|
"git-widget-placeholder": "main",
|
||||||
"kotlin-language-version-configured": "true",
|
"junie.onboarding.icon.badge.shown": "true",
|
||||||
"node.js.detected.package.eslint": "true",
|
"kotlin-language-version-configured": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"project.structure.last.edited": "SDKs",
|
"nodejs_package_manager_path": "npm",
|
||||||
"project.structure.proportion": "0.15",
|
"project.structure.last.edited": "SDKs",
|
||||||
"project.structure.side.proportion": "0.2",
|
"project.structure.proportion": "0.15",
|
||||||
"settings.editor.selected.configurable": "configurable.group.language",
|
"project.structure.side.proportion": "0.2",
|
||||||
"to.speed.mode.migration.done": "true",
|
"settings.editor.selected.configurable": "configurable.group.language",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"to.speed.mode.migration.done": "true",
|
||||||
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}</component>
|
}]]></component>
|
||||||
<component name="RecentsManager">
|
<component name="RecentsManager">
|
||||||
<key name="MoveClassesOrPackagesDialog.RECENTS_KEY">
|
<key name="MoveClassesOrPackagesDialog.RECENTS_KEY">
|
||||||
<recent name="" />
|
<recent name="" />
|
||||||
|
|
@ -125,7 +120,7 @@
|
||||||
<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="55000" />
|
<workItem from="1767838192168" duration="2611000" />
|
||||||
</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" />
|
||||||
|
|
@ -255,12 +250,47 @@
|
||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1767824260007</updated>
|
<updated>1767824260007</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="17" />
|
<task id="LOCAL-00017" summary="updated java version to 17 so I can use switched (Introduced in 14">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1767838335498</created>
|
||||||
|
<option name="number" value="00017" />
|
||||||
|
<option name="presentableId" value="LOCAL-00017" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1767838335498</updated>
|
||||||
|
</task>
|
||||||
|
<task id="LOCAL-00018" summary="Did a few base cases using enhanced switches">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1767839475258</created>
|
||||||
|
<option name="number" value="00018" />
|
||||||
|
<option name="presentableId" value="LOCAL-00018" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1767839475258</updated>
|
||||||
|
</task>
|
||||||
|
<task id="LOCAL-00019" summary="Did a few base cases using enhanced switches">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1767839480914</created>
|
||||||
|
<option name="number" value="00019" />
|
||||||
|
<option name="presentableId" value="LOCAL-00019" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1767839480914</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="20" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
<option name="version" value="3" />
|
<option name="version" value="3" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
|
<option name="TAB_STATES">
|
||||||
|
<map>
|
||||||
|
<entry key="MAIN">
|
||||||
|
<value>
|
||||||
|
<State />
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<MESSAGE value="updated module output folders" />
|
<MESSAGE value="updated module output folders" />
|
||||||
<MESSAGE value="moved small projects into one project folder" />
|
<MESSAGE value="moved small projects into one project folder" />
|
||||||
|
|
@ -277,7 +307,10 @@
|
||||||
<MESSAGE value="Refactored classes / File names to use Pascal case" />
|
<MESSAGE value="Refactored classes / File names to use Pascal case" />
|
||||||
<MESSAGE value="updated junk files" />
|
<MESSAGE value="updated junk files" />
|
||||||
<MESSAGE value="updated junk java files" />
|
<MESSAGE value="updated junk java files" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="updated junk java files" />
|
<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" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XSLT-Support.FileAssociations.UIState">
|
<component name="XSLT-Support.FileAssociations.UIState">
|
||||||
<expand />
|
<expand />
|
||||||
|
|
|
||||||
BIN
out/production/java_practice/Calculator.class
Normal file
BIN
out/production/java_practice/Calculator.class
Normal file
Binary file not shown.
59
practice_projects/src/Calculator.java
Normal file
59
practice_projects/src/Calculator.java
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Calculator {
|
||||||
|
|
||||||
|
public static void main(String[] args){
|
||||||
|
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
double result;
|
||||||
|
|
||||||
|
// take users first number
|
||||||
|
System.out.print("Enter the first number: ");
|
||||||
|
|
||||||
|
// grab both the number and a COPY of the number for Clean OUTPUT
|
||||||
|
String num1Input = scanner.nextLine().trim();
|
||||||
|
double num1 = Double.parseDouble(num1Input);
|
||||||
|
|
||||||
|
// Get the operator from the user
|
||||||
|
System.out.print("Enter the operator (+, -, *, /, ^): ");
|
||||||
|
char operator = scanner.nextLine().trim().charAt(0);
|
||||||
|
|
||||||
|
// take users second number
|
||||||
|
System.out.print("Enter the second number: ");
|
||||||
|
|
||||||
|
// grab both the number and a COPY of the number for Clean OUTPUT
|
||||||
|
String num2Input = scanner.nextLine().trim();
|
||||||
|
double num2 = Double.parseDouble(num2Input);
|
||||||
|
|
||||||
|
// Switch to process the operator and do the appropriate math
|
||||||
|
switch(operator){
|
||||||
|
case '+' -> result = num1 + num2;
|
||||||
|
case '-' -> result = num1 - num2;
|
||||||
|
case '*' -> result = num1 * num2;
|
||||||
|
case '^' -> result = Math.pow(num1, num2);
|
||||||
|
case '/' -> {
|
||||||
|
if(num2 == 0){
|
||||||
|
System.out.println("Cannot divide by zero!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result = num1 / num2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Error catch if user entered something else
|
||||||
|
default -> {
|
||||||
|
System.out.println("Invalid operator!");
|
||||||
|
scanner.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print out the result
|
||||||
|
// Use the String copies of the numbers to get clean output exactly as user entered them
|
||||||
|
System.out.printf("%s %c %s = %.2f", num1Input, operator, num2Input, result);
|
||||||
|
|
||||||
|
scanner.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue