Compare commits
9 commits
a88cb9a6ed
...
0644186bce
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0644186bce | ||
|
|
326bf53196 | ||
|
|
c4e62fc5a3 | ||
|
|
abec7f6016 | ||
|
|
20ea45628d | ||
|
|
022af4a75b | ||
|
|
e57dcf39dd | ||
|
|
b82a6773e4 | ||
|
|
c1aa0e09ad |
25 changed files with 510 additions and 6 deletions
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/java_practice.iml" filepath="$PROJECT_DIR$/java_practice.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
238
.idea/workspace.xml
Normal file
238
.idea/workspace.xml
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="8658cbac-7347-4046-83e8-57065c86d2b8" name="Changes" comment="Refactored classes / File names to use Pascal case">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Class" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="McpProjectServerCommands">
|
||||
<commands />
|
||||
<urls />
|
||||
</component>
|
||||
<component name="ProblemsViewState">
|
||||
<option name="selectedTabId" value="CurrentFile" />
|
||||
</component>
|
||||
<component name="ProjectColorInfo">{
|
||||
"associatedIndex": 8
|
||||
}</component>
|
||||
<component name="ProjectId" id="37o6U1jLh6B9fGeTwrV9eeSfs6j" />
|
||||
<component name="ProjectLevelVcsManager">
|
||||
<ConfirmationsSetting value="2" id="Add" />
|
||||
</component>
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"Application.Calculator.executor": "Run",
|
||||
"Application.Main.executor": "Run",
|
||||
"Application.TempConverter.executor": "Run",
|
||||
"Application.compountInterest.executor": "Run",
|
||||
"Application.ifStatements.executor": "Run",
|
||||
"Application.madLibs.executor": "Run",
|
||||
"Application.printF.executor": "Run",
|
||||
"Application.randomNums.executor": "Run",
|
||||
"Application.shoppingCart.executor": "Run",
|
||||
"Application.substrings.executor": "Run",
|
||||
"Application.tempConverter.executor": "Run",
|
||||
"Application.trueFalse.executor": "Run",
|
||||
"Application.weightConverter.executor": "Run",
|
||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||
"RunOnceActivity.MCP Project settings loaded": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
||||
"com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultModelSelectionForGA.v1": "true",
|
||||
"git-widget-placeholder": "main",
|
||||
"junie.onboarding.icon.badge.shown": "true",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"project.structure.last.edited": "Modules",
|
||||
"project.structure.proportion": "0.15",
|
||||
"project.structure.side.proportion": "0.2",
|
||||
"settings.editor.selected.configurable": "reference.settingsdialog.IDE.editor.colors.Console Colors",
|
||||
"to.speed.mode.migration.done": "true",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}]]></component>
|
||||
<component name="RecentsManager">
|
||||
<key name="MoveClassesOrPackagesDialog.RECENTS_KEY">
|
||||
<recent name="" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="SharedIndexes">
|
||||
<attachedChunks>
|
||||
<set>
|
||||
<option value="bundled-jdk-30f59d01ecdd-26cb7f24e5b0-intellij.indexing.shared.core-IU-253.29346.138" />
|
||||
<option value="bundled-js-predefined-d6986cc7102b-9b0f141eb926-JavaScript-IU-253.29346.138" />
|
||||
</set>
|
||||
</attachedChunks>
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="8658cbac-7347-4046-83e8-57065c86d2b8" name="Changes" comment="" />
|
||||
<created>1767557089317</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1767557089317</updated>
|
||||
<workItem from="1767557093354" duration="14440000" />
|
||||
<workItem from="1767678323979" duration="14235000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="updated module output folders">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767565219423</created>
|
||||
<option name="number" value="00001" />
|
||||
<option name="presentableId" value="LOCAL-00001" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767565219423</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00002" summary="moved small projects into one project folder">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767578203605</created>
|
||||
<option name="number" value="00002" />
|
||||
<option name="presentableId" value="LOCAL-00002" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767578203605</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00003" summary="Created random number / coin flip generator with error catching">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767588535662</created>
|
||||
<option name="number" value="00003" />
|
||||
<option name="presentableId" value="LOCAL-00003" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767588535662</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00004" summary="explore printf variations">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767666830045</created>
|
||||
<option name="number" value="00004" />
|
||||
<option name="presentableId" value="LOCAL-00004" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767666830045</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00005" summary="created compound calculator">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767672756444</created>
|
||||
<option name="number" value="00005" />
|
||||
<option name="presentableId" value="LOCAL-00005" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767672756444</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00006" summary="fixed name of compoundInterest">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767678458164</created>
|
||||
<option name="number" value="00006" />
|
||||
<option name="presentableId" value="LOCAL-00006" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767678458165</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00007" summary="explored substring methods">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767812256757</created>
|
||||
<option name="number" value="00007" />
|
||||
<option name="presentableId" value="LOCAL-00007" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767812256757</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00008" summary="made a lbs to kgs weight converter">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767813520591</created>
|
||||
<option name="number" value="00008" />
|
||||
<option name="presentableId" value="LOCAL-00008" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767813520591</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00009" summary="uploaded junk files">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767813537078</created>
|
||||
<option name="number" value="00009" />
|
||||
<option name="presentableId" value="LOCAL-00009" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767813537078</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00010" summary="explored ternary operator">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767818577359</created>
|
||||
<option name="number" value="00010" />
|
||||
<option name="presentableId" value="LOCAL-00010" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767818577359</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00011" summary="uploaded junk files">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767818585588</created>
|
||||
<option name="number" value="00011" />
|
||||
<option name="presentableId" value="LOCAL-00011" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767818585588</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00012" summary="uploaded junk class files">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767818594413</created>
|
||||
<option name="number" value="00012" />
|
||||
<option name="presentableId" value="LOCAL-00012" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767818594413</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00013" summary="Crated a temperature converter">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767821485207</created>
|
||||
<option name="number" value="00013" />
|
||||
<option name="presentableId" value="LOCAL-00013" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767821485207</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00014" summary="Refactored classes / File names to use Pascal case">
|
||||
<option name="closed" value="true" />
|
||||
<created>1767821506803</created>
|
||||
<option name="number" value="00014" />
|
||||
<option name="presentableId" value="LOCAL-00014" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1767821506803</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="15" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="updated module output folders" />
|
||||
<MESSAGE value="moved small projects into one project folder" />
|
||||
<MESSAGE value="Created random number / coin flip generator with error catching" />
|
||||
<MESSAGE value="explore printf variations" />
|
||||
<MESSAGE value="created compound calculator" />
|
||||
<MESSAGE value="fixed name of compoundInterest" />
|
||||
<MESSAGE value="explored substring methods" />
|
||||
<MESSAGE value="made a lbs to kgs weight converter" />
|
||||
<MESSAGE value="explored ternary operator" />
|
||||
<MESSAGE value="uploaded junk files" />
|
||||
<MESSAGE value="uploaded junk class files" />
|
||||
<MESSAGE value="Crated a temperature converter" />
|
||||
<MESSAGE value="Refactored classes / File names to use Pascal case" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Refactored classes / File names to use Pascal case" />
|
||||
</component>
|
||||
</project>
|
||||
15
java_practice.iml
Normal file
15
java_practice.iml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<output url="file://$MODULE_DIR$/out/production/java_practice" />
|
||||
<output-test url="file://$MODULE_DIR$/out/test/java_practice" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/calculator/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/madLibs/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/practice_projects/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="jbr_dcevm-11" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
BIN
out/production/java_practice/Main.class
Normal file
BIN
out/production/java_practice/Main.class
Normal file
Binary file not shown.
BIN
out/production/java_practice/TempConverter.class
Normal file
BIN
out/production/java_practice/TempConverter.class
Normal file
Binary file not shown.
BIN
out/production/java_practice/compoundInterest.class
Normal file
BIN
out/production/java_practice/compoundInterest.class
Normal file
Binary file not shown.
BIN
out/production/java_practice/ifStatements.class
Normal file
BIN
out/production/java_practice/ifStatements.class
Normal file
Binary file not shown.
BIN
out/production/java_practice/madLibs.class
Normal file
BIN
out/production/java_practice/madLibs.class
Normal file
Binary file not shown.
BIN
out/production/java_practice/printF.class
Normal file
BIN
out/production/java_practice/printF.class
Normal file
Binary file not shown.
BIN
out/production/java_practice/randomNums.class
Normal file
BIN
out/production/java_practice/randomNums.class
Normal file
Binary file not shown.
BIN
out/production/java_practice/shoppingCart.class
Normal file
BIN
out/production/java_practice/shoppingCart.class
Normal file
Binary file not shown.
BIN
out/production/java_practice/substrings.class
Normal file
BIN
out/production/java_practice/substrings.class
Normal file
Binary file not shown.
BIN
out/production/java_practice/trueFalse.class
Normal file
BIN
out/production/java_practice/trueFalse.class
Normal file
Binary file not shown.
BIN
out/production/java_practice/weightConverter.class
Normal file
BIN
out/production/java_practice/weightConverter.class
Normal file
Binary file not shown.
|
|
@ -1,6 +1,6 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class compoundInterest {
|
||||
public class CompoundInterest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class ifStatements {
|
||||
public class IfStatements {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class madLibs {
|
||||
public class MadLibs {
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
public class printF {
|
||||
public class PrintF {
|
||||
|
||||
public static void main(String[] args){
|
||||
String name = "Spongebob";
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class randomNums {
|
||||
public class RandomNums {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Random random = new Random();
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class shoppingCart {
|
||||
public class ShoppingCart {
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
74
practice_projects/src/TempConverter.java
Normal file
74
practice_projects/src/TempConverter.java
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class TempConverter {
|
||||
|
||||
// Define methods to convert each temperature
|
||||
|
||||
// Celsius to Fahrenheit
|
||||
static double celToFar(double c) { return (c * 9.0 / 5.0) + 32; }
|
||||
|
||||
// Fahrenheit to Celsius
|
||||
static double farToCel(double f) { return (f - 32) * 5.0 / 9.0; }
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
// Initialize scanner to take input
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
// Styled header just to make things pretty
|
||||
System.out.println("=== Welcome to the Temperature Converter ===");
|
||||
|
||||
|
||||
// Create a loop so we can build in error checking
|
||||
while(true) {
|
||||
// Ask user which option they want to convert
|
||||
System.out.print("Which do you want to convert? (C) or (F): ");
|
||||
|
||||
// trim and convert to lower to make sure grab answer whether capitalized or not
|
||||
String choice = scanner.nextLine().trim().toLowerCase();
|
||||
|
||||
if(!choice.equals("c") && !choice.equals("f") ){
|
||||
System.out.println("Invalid Choice. Please enter C or F.");
|
||||
continue;
|
||||
}
|
||||
// Check which option the user entered
|
||||
boolean isCelsius = choice.equals("c");
|
||||
String fromUnit = isCelsius ? "C" : "F";
|
||||
String toUnit = isCelsius ? "F" : "C";
|
||||
|
||||
// Ask for a temperature to convert
|
||||
System.out.printf("Enter a temperature in %s: ", fromUnit);
|
||||
|
||||
double temperature;
|
||||
|
||||
// make sure a valid number is input
|
||||
try {
|
||||
temperature = Double.parseDouble(scanner.nextLine());
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
System.out.println("Invalid Temperature. Please enter a number");
|
||||
continue;
|
||||
}
|
||||
|
||||
// use ternary to convert temperature ine one line
|
||||
double newTemp = isCelsius ? celToFar(temperature) : farToCel(temperature);
|
||||
|
||||
// Print out the resulting converted temperature
|
||||
System.out.printf("%.1f°%s is %.1f°%s\n", temperature, fromUnit, newTemp, toUnit);
|
||||
|
||||
// Check if user wants to convert another
|
||||
System.out.print("Convert another? (y/n): ");
|
||||
|
||||
// Treat anything other than a "y" as a No.
|
||||
if(!scanner.nextLine().trim().equalsIgnoreCase("y")){
|
||||
System.out.println("\n--- Thanks for using the Temperature Converter!! ---");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Close scanner so we dont leave resources open
|
||||
scanner.close();
|
||||
|
||||
}
|
||||
}
|
||||
62
practice_projects/src/TrueFalse.java
Normal file
62
practice_projects/src/TrueFalse.java
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class TrueFalse {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
// ternary operator ! = Return 1 of 2 values if a condition is true
|
||||
|
||||
// variable =(condition) ? ifTrue : ifFalse;
|
||||
|
||||
// ---------------
|
||||
// Lets create a grade checker using old methods
|
||||
|
||||
/*
|
||||
// declare variables
|
||||
|
||||
// Get grade from student
|
||||
System.out.println("Enter your grade: ");
|
||||
int grade = Integer.parseInt(scanner.nextLine());
|
||||
|
||||
// Check if grade is passing or not
|
||||
if(grade >= 60) {
|
||||
System.out.println("PASS");
|
||||
}
|
||||
else {
|
||||
System.out.println("FAIL");
|
||||
}
|
||||
*/
|
||||
|
||||
// ---------------
|
||||
|
||||
|
||||
// ---------------
|
||||
// Lets use ternary method to do the same thing in half the lines of code
|
||||
|
||||
|
||||
// Get grade from student
|
||||
System.out.println("Enter your grade: ");
|
||||
int grade = Integer.parseInt(scanner.nextLine());
|
||||
|
||||
String passOrFail = (grade >= 60) ? "PASS" : "FAIL";
|
||||
|
||||
System.out.println(passOrFail);
|
||||
|
||||
|
||||
|
||||
// ---------------
|
||||
|
||||
// Lets use ternary to check if a number is even or odd
|
||||
System.out.println("Enter a number: ");
|
||||
int number = Integer.parseInt(scanner.nextLine());
|
||||
|
||||
String evenOrOdd = (number % 2 == 0) ? "EVEN" : "ODD";
|
||||
|
||||
System.out.println(evenOrOdd);
|
||||
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
59
practice_projects/src/WeightConverter.java
Normal file
59
practice_projects/src/WeightConverter.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class WeightConverter {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// Weight conversion program
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
// Declare variables
|
||||
String choice;
|
||||
int weight;
|
||||
double converted;
|
||||
|
||||
// Welcome message
|
||||
System.out.println("Welcome to the weight converter!\n");
|
||||
|
||||
// Prompt for user choice
|
||||
System.out.println("Choose: ");
|
||||
System.out.println("Option 1 Lbs -> Kgs (1)");
|
||||
System.out.println("Option 2 Kgs -> Lbs (2)\n");
|
||||
|
||||
choice = scanner.nextLine();
|
||||
|
||||
// option 1 convert lbs tp kgs
|
||||
if (choice.equals("1")){
|
||||
|
||||
// get the weight input from user
|
||||
System.out.println("Enter the weight in lbs: ");
|
||||
weight = Integer.parseInt(scanner.nextLine());
|
||||
|
||||
// convert the weight and print out the result
|
||||
converted = (weight * 1.0 / 2.205);
|
||||
System.out.printf("%d lbs is %.2f kgs.", weight, converted);
|
||||
|
||||
|
||||
|
||||
} // option 2 convert kgs to lbs
|
||||
else if(choice.equals("2")){
|
||||
|
||||
// get the weight input from user
|
||||
System.out.println("Enter the weight in kgs: ");
|
||||
weight = Integer.parseInt(scanner.nextLine());
|
||||
|
||||
// convert the weight and print out the result
|
||||
converted = (weight * 1.0 * 2.205);
|
||||
System.out.printf("%d kgs is %.2f lbs.", weight, converted);
|
||||
|
||||
|
||||
} //else print not a valid choice
|
||||
else {
|
||||
System.out.println("Not a valid choice. Try again");
|
||||
}
|
||||
|
||||
scanner.close();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
42
practice_projects/src/substrings.java
Normal file
42
practice_projects/src/substrings.java
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class substrings {
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
|
||||
// .substring() is a method used to extract a portion of a string.
|
||||
// You use it by giving a start and end position.
|
||||
// Example: string.substring(start, end)
|
||||
|
||||
while (true) {
|
||||
// Have user enter their email
|
||||
System.out.print("Enter an email: ");
|
||||
String email = scanner.nextLine();
|
||||
|
||||
// Check if its a valid email (Contains @ symbol)
|
||||
if(email.contains("@")){
|
||||
// find the index position of the @ symbol
|
||||
int index = email.indexOf("@");
|
||||
|
||||
// find the domain address of their email
|
||||
String domain = email.substring(index + 1);
|
||||
|
||||
String username = email.substring(0, index);
|
||||
|
||||
System.out.println("Your username is " + username);
|
||||
System.out.println("Your email domain is " + domain);
|
||||
break;
|
||||
|
||||
} else {
|
||||
System.out.println("Please enter a valid email address!\n");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
scanner.close();
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue