From 46ad34ac0da221fb3234dc1ad8544b604acc42df Mon Sep 17 00:00:00 2001 From: sgoudham Date: Thu, 8 Oct 2020 18:11:44 +0100 Subject: [PATCH 01/11] first commit --- .gitignore | 1 + Java Classes and Interfaces/.DS_Store | Bin 0 -> 6148 bytes .../Calc Engine/.DS_Store | Bin 0 -> 6148 bytes .../Calc Engine/src/.DS_Store | Bin 0 -> 6148 bytes .../Calc Engine/src/calcEngine.java | 43 ++++ Java Fundamentals/.DS_Store | Bin 0 -> 6148 bytes .../Calc Engine/src/calcEngine.java | 187 ++++++++++++++++++ .../Get Organised/src/com/.DS_Store | Bin 0 -> 6148 bytes .../src/com/pluralsite/.DS_Store | Bin 0 -> 6148 bytes .../pluralsite/getorganised/getOrganised.java | 6 + .../Hello World/src/helloWorld.java | 7 + .../src/operatorPrecedence.java | 16 ++ .../Type Conversion/src/typeConversion.java | 44 +++++ README.md | 7 + 14 files changed, 311 insertions(+) create mode 100644 .gitignore create mode 100644 Java Classes and Interfaces/.DS_Store create mode 100644 Java Classes and Interfaces/Calc Engine/.DS_Store create mode 100644 Java Classes and Interfaces/Calc Engine/src/.DS_Store create mode 100644 Java Classes and Interfaces/Calc Engine/src/calcEngine.java create mode 100644 Java Fundamentals/.DS_Store create mode 100644 Java Fundamentals/Calc Engine/src/calcEngine.java create mode 100644 Java Fundamentals/Get Organised/src/com/.DS_Store create mode 100644 Java Fundamentals/Get Organised/src/com/pluralsite/.DS_Store create mode 100644 Java Fundamentals/Get Organised/src/com/pluralsite/getorganised/getOrganised.java create mode 100644 Java Fundamentals/Hello World/src/helloWorld.java create mode 100644 Java Fundamentals/Operator Precedence/src/operatorPrecedence.java create mode 100644 Java Fundamentals/Type Conversion/src/typeConversion.java create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c96066d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.DS_Store \ No newline at end of file diff --git a/Java Classes and Interfaces/.DS_Store b/Java Classes and Interfaces/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f2f010a117d9dbeb9526230b4159e4ef06d0a30d GIT binary patch literal 6148 zcmeHKOHRWu5S@Wa1hMIorLWK%gesh%8~~M~g4B>!z~15#T!BNd;$*z%8BjvAV1W=q zGm`zro{ya;#rBAZ&L3AZk*SDOXhfwlBAgyI9k}xZs3pg(+{t>go-MArkwkxSihDnj z3%Qnid63@z+ih>VUp(5bX_lLA36JXac=z)3{C2jVr|nkX@Y>#xt-)%&g+mPnf`MQl z7zhS_oB`a~lnmtj6U+tI;nT7Ku Q92gIQLP&JMz%MZH4)Mz^jsO4v literal 0 HcmV?d00001 diff --git a/Java Classes and Interfaces/Calc Engine/.DS_Store b/Java Classes and Interfaces/Calc Engine/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c25158cb2f3af6c87863553b0c3c168165fb82db GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8rihq>V2^w8)Z5h|jIG#JHo6eG+JH15f)J?~p z*3aTN{M23VJQ&Rf=FU+ZrEU<7rZPG3M-Xy#5k!7G@5QsoPvks~a^O1kf!WA1%i3=W ztJBS!BI|ZrP0_Iq^1N>B?zIn3hIbE-*;D@fqWI-Nzm#o_CA@;7%e!}`Q5Z+JFj7XB zQG~<*F+dCu11rUVJ_d}ehypskB@l&1 zTVtURJRn@90;*K5pBP-F!?@6Kw#GuCN@rZI4D;xf%f}0stHZdE;f&h~sV4@Afkg(Y z$~5u(KZd`|(ntPc3R%PeG4RhA;I+Qf??F-eZ2eXqp0xtn5E=@`6{vuKzHkWu1NV`J ebSl3<9pY?_g+iPK$7MPoT?8Z{)DZ)}z`zI4z)#r# literal 0 HcmV?d00001 diff --git a/Java Classes and Interfaces/Calc Engine/src/.DS_Store b/Java Classes and Interfaces/Calc Engine/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0i&V#MQ^0PsOMB=mx}4|7TYKBQdvA~K z)-~@I^H;(T?#Uut{twJQL-XKT#xFz;YpCmJf8sv;6z^&CK0oexG`wTxwK=!TnX~@*&Kdg}I>!^>)lJl{<+*qp!UJUIABuZvB|$^FJSd|96A@lUKki@TU|IsoZjI z1}T}d^-FSm)=HEO6gKvYG^!9(<~UXjK8iLG@=LQ{|G1 results[i] = leftVals[i] + rightVals[i]; + case 's' -> results[i] = leftVals[i] - rightVals[i]; + case 'm' -> results[i] = leftVals[i] * rightVals[i]; + case 'd' -> results[i] = rightVals[i] != 0 ? leftVals[i] / rightVals[i] : 0.0d; + default -> { + System.out.println("Invalid opCode" + opCodes[i]); + results[i] = 0.0d; + } + } + */ + double result; + switch (opCode) { + case 'a': + result = leftVal + rightVal; + break; + case 's': + result = leftVal - rightVal; + break; + case 'm': + result = leftVal * rightVal; + break; + case 'd': + result = rightVal != 0 ? leftVal / rightVal : 0.0d; + break; + default: + System.out.println("Invalid opCode" + opCode); + result = 0.0d; + break; + } + return result; + } + + static double getCommandLine(String[] args) { + /* Handle the command line arguments and get the result */ + + char opCode = args[0].charAt(0); + double leftVal = Double.parseDouble(args[1]); + double rightVal = Double.parseDouble(args[2]); + return execute(opCode, leftVal, rightVal); + + } + + static char getOpCodeFromString(String operationName) { + /* Return the opcode from the string*/ + + return operationName.charAt(0); + } + + static double valueFromWord(String word) { + /* Return the double representation of the number */ + + String[] values = { + "zero", "one", "two", "three", "four", "five", + "six", "seven", "eight", "nine", "ten" + }; + double value = -1d; + for (int i = 0; i < values.length; i++) { + if (word.equals(values[i])) { + value = i; + break; + } + } + + // Checking to see if value had changed, if not. Parse the string into a double + if (value == -1) + value = Double.parseDouble(word); + + return value; + } + + static char symbolFromOpCode(char opCode) { + /* Get the relevant symbol for the operation given by the user*/ + + char[] opCodes = {'a', 's', 'm', 'd'}; + char[] symbols = {'+', '-', '*', '/'}; + char symbol = ' '; + + // Loop through the list of chars and get the relevant symbol + for (int i = 0; i < opCodes.length; i++) { + if (opCode == opCodes[i]) { + symbol = symbols[i]; + break; + } + } + return symbol; + } + + static void displayResult(char opCode, double leftVal, double rightVal, double result) { + /* Display the result of the expression but nicely formatted */ + + char symbol = symbolFromOpCode(opCode); + // StringBuilder stringBuilder = new StringBuilder(); + + // stringBuilder.append(leftVal); + // stringBuilder.append(" " + symbol + " "); + // stringBuilder.append(rightVal); + // stringBuilder.append(" = "); + // stringBuilder.append(result); + + // String finalResult = stringBuilder.toString(); + + String finalResult = String.format("%.1f %c %.1f = %.1f", + leftVal, symbol, rightVal, result); + System.out.println(finalResult); + + } + + static void handleWhen(String[] stringParts) { + /* Return date arithmetic operation (days added) */ + + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); + LocalDate startDate = LocalDate.parse(stringParts[1], dateTimeFormatter); + long daysToAdd = (long) valueFromWord(stringParts[2]); + + LocalDate newDate = startDate.plusDays(daysToAdd); + String output = String.format("%s + %d days is %s", + startDate.format(dateTimeFormatter), daysToAdd, newDate.format(dateTimeFormatter)); + System.out.println(output); + + } + + static void performOperation(String[] stringParts) { + /* Execute the operation with the numbers given by the user */ + + char opCode = getOpCodeFromString(stringParts[0]); + + if (opCode == 'w') { + handleWhen(stringParts); + } else { + double leftVal = valueFromWord(stringParts[1]); + double rightVal = valueFromWord(stringParts[2]); + double result = execute(opCode, leftVal, rightVal); + displayResult(opCode, leftVal, rightVal, result); + + } + } + + + static void executeInteractively() { + /* Allow the user to be able to enter in numbers for operations */ + + Scanner in = new Scanner(System.in); + System.out.println("Enter in an operation and two numbers"); + String userInput = in.nextLine(); + in.close(); + + String[] stringParts = userInput.split(" "); + performOperation(stringParts); + + } + + public static void main(String[] args) { + + double[] leftVals = {100.0d, 25.0d, 225.0d, 11.0d}; + double[] rightVals = {50.0d, 92.0d, 17.0d, 3.0}; + char[] opCodes = {'d', 'a', 's', 'm'}; + double[] results = new double[opCodes.length]; + + // Make sure the user has entered in command line arguments before trying to use them + if (args.length == 0) { + // Get the results of the operation and store it into an array + for (int i = 0; i < opCodes.length; i++) + results[i] = execute(opCodes[i], leftVals[i], rightVals[i]); + + // Print out all the results stored in the array + for (double currentResult: results) + System.out.println(currentResult); + + } else if (args.length == 1 && args[0].equals("interactive")) { + executeInteractively(); + } else if (args.length == 3) + System.out.println(getCommandLine(args)); + else + System.out.println("Please Enter 3 Command Line Arguments!"); + } +} diff --git a/Java Fundamentals/Get Organised/src/com/.DS_Store b/Java Fundamentals/Get Organised/src/com/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..248fc0869dfadef140005507aa99a20a7f552a85 GIT binary patch literal 6148 zcmeHK%}xR_5S{|+qA_wXkz+63I6y!-nQRab-b~i$K@IE%BAcwcgk2Tto98wIBAPNh=zMy;zOo z=m5=A?3BvWX}x|_k@ZG1t;lJ!S*^%M{WwjF*1=)z+mc3`yZK<^DqcU@^`Y_y-cOF@bOf=TTqf@5-lT^dNAYQ=~`}Mj*|u zR0xUrsppmaIMAaGdb> z*nMnI!^?3v**-Y0H~LMJXT!q`921ictKq}y$yO7J#nX9zi*i^` zRFnczV5-1%Zdcy_ALu{K|5K87Qa}p)D+O$^*>2W+rRuG-m-AlR=#O--`J}sX9TbLW l$HZvI+;}^_i=wP+zUFx^920}ie9(#d8E{=>QsA!@_yT-d7IXjr literal 0 HcmV?d00001 diff --git a/Java Fundamentals/Get Organised/src/com/pluralsite/getorganised/getOrganised.java b/Java Fundamentals/Get Organised/src/com/pluralsite/getorganised/getOrganised.java new file mode 100644 index 0000000..b461644 --- /dev/null +++ b/Java Fundamentals/Get Organised/src/com/pluralsite/getorganised/getOrganised.java @@ -0,0 +1,6 @@ +public class getOrganised { + + public static void main(String[] args) { + System.out.println("I'm being organised!"); + } +} diff --git a/Java Fundamentals/Hello World/src/helloWorld.java b/Java Fundamentals/Hello World/src/helloWorld.java new file mode 100644 index 0000000..754058b --- /dev/null +++ b/Java Fundamentals/Hello World/src/helloWorld.java @@ -0,0 +1,7 @@ +public class helloWorld { + + public static void main(String[] args) { + /* Printing out Hello World! */ + System.out.println("Hello World!"); + } +} diff --git a/Java Fundamentals/Operator Precedence/src/operatorPrecedence.java b/Java Fundamentals/Operator Precedence/src/operatorPrecedence.java new file mode 100644 index 0000000..fce3ae4 --- /dev/null +++ b/Java Fundamentals/Operator Precedence/src/operatorPrecedence.java @@ -0,0 +1,16 @@ +public class operatorPrecedence { + public static void main(String[] args) { + + int valA = 21; + int valB = 6; + int valC = 3; + int valD = 1; + + int result1 = valA / valC * valD + valB; + int result2 = valA / (valC * (valD + valB)); + + System.out.println(result1); + System.out.println(result2); + + } +} diff --git a/Java Fundamentals/Type Conversion/src/typeConversion.java b/Java Fundamentals/Type Conversion/src/typeConversion.java new file mode 100644 index 0000000..49a1cbe --- /dev/null +++ b/Java Fundamentals/Type Conversion/src/typeConversion.java @@ -0,0 +1,44 @@ +public class typeConversion { + + public static void main(String[] args) { + float floatVal = 1.0f; + double doubleVal = 4.0d; + byte byteVal = 7; + short shortVal = 7; + long longVal = 5; + + // Possible + short result1 = byteVal; + + // Not possible + // short result2 = longVal; + + // Possible + short result2 = (short) longVal; + + // Not Possible + // short result3 = byteVal - longVal; + + // Possible + short result3 = (short) (byteVal - longVal); + + // Not Possible + // long result4 = longVal - floatVal; + + // Better to do this - Possible + float result4 = longVal - floatVal; + + // Possible + double result5 = doubleVal + shortVal; + + + System.out.println("Success"); + System.out.println(result1); + System.out.println(result2); + System.out.println(result3); + System.out.println(result4); + System.out.println(result5); + } +} + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..49334dc --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# LearningJava + +#### Uploading any projects/code that shows my progression in learning Java + +# Courses Included +- [Java Fundamentals](https://app.pluralsight.com/library/courses/getting-started-programming-java/table-of-contents) +- [Java Classes & Interfaces](https://app.pluralsight.com/library/courses/working-classes-interfaces-java/table-of-contents) \ No newline at end of file From 39cb05e02d567de41ba2180f97b928b519f92964 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Thu, 8 Oct 2020 18:20:02 +0100 Subject: [PATCH 02/11] Deleted files that were not needed --- Java Classes and Interfaces/.DS_Store | Bin 6148 -> 0 bytes .../Calc Engine/.DS_Store | Bin 6148 -> 0 bytes .../Calc Engine/src/.DS_Store | Bin 6148 -> 0 bytes Java Fundamentals/.DS_Store | Bin 6148 -> 0 bytes .../Get Organised/src/com/.DS_Store | Bin 6148 -> 0 bytes .../Get Organised/src/com/pluralsite/.DS_Store | Bin 6148 -> 0 bytes 6 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Java Classes and Interfaces/.DS_Store delete mode 100644 Java Classes and Interfaces/Calc Engine/.DS_Store delete mode 100644 Java Classes and Interfaces/Calc Engine/src/.DS_Store delete mode 100644 Java Fundamentals/.DS_Store delete mode 100644 Java Fundamentals/Get Organised/src/com/.DS_Store delete mode 100644 Java Fundamentals/Get Organised/src/com/pluralsite/.DS_Store diff --git a/Java Classes and Interfaces/.DS_Store b/Java Classes and Interfaces/.DS_Store deleted file mode 100644 index f2f010a117d9dbeb9526230b4159e4ef06d0a30d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKOHRWu5S@Wa1hMIorLWK%gesh%8~~M~g4B>!z~15#T!BNd;$*z%8BjvAV1W=q zGm`zro{ya;#rBAZ&L3AZk*SDOXhfwlBAgyI9k}xZs3pg(+{t>go-MArkwkxSihDnj z3%Qnid63@z+ih>VUp(5bX_lLA36JXac=z)3{C2jVr|nkX@Y>#xt-)%&g+mPnf`MQl z7zhS_oB`a~lnmtj6U+tI;nT7Ku Q92gIQLP&JMz%MZH4)Mz^jsO4v diff --git a/Java Classes and Interfaces/Calc Engine/.DS_Store b/Java Classes and Interfaces/Calc Engine/.DS_Store deleted file mode 100644 index c25158cb2f3af6c87863553b0c3c168165fb82db..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5Z-O8rihq>V2^w8)Z5h|jIG#JHo6eG+JH15f)J?~p z*3aTN{M23VJQ&Rf=FU+ZrEU<7rZPG3M-Xy#5k!7G@5QsoPvks~a^O1kf!WA1%i3=W ztJBS!BI|ZrP0_Iq^1N>B?zIn3hIbE-*;D@fqWI-Nzm#o_CA@;7%e!}`Q5Z+JFj7XB zQG~<*F+dCu11rUVJ_d}ehypskB@l&1 zTVtURJRn@90;*K5pBP-F!?@6Kw#GuCN@rZI4D;xf%f}0stHZdE;f&h~sV4@Afkg(Y z$~5u(KZd`|(ntPc3R%PeG4RhA;I+Qf??F-eZ2eXqp0xtn5E=@`6{vuKzHkWu1NV`J ebSl3<9pY?_g+iPK$7MPoT?8Z{)DZ)}z`zI4z)#r# diff --git a/Java Classes and Interfaces/Calc Engine/src/.DS_Store b/Java Classes and Interfaces/Calc Engine/src/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0i&V#MQ^0PsOMB=mx}4|7TYKBQdvA~K z)-~@I^H;(T?#Uut{twJQL-XKT#xFz;YpCmJf8sv;6z^&CK0oexG`wTxwK=!TnX~@*&Kdg}I>!^>)lJl{<+*qp!UJUIABuZvB|$^FJSd|96A@lUKki@TU|IsoZjI z1}T}d^-FSm)=HEO6gKvYG^!9(<~UXjK8iLG@=LQ{|G1Tto98wIBAPNh=zMy;zOo z=m5=A?3BvWX}x|_k@ZG1t;lJ!S*^%M{WwjF*1=)z+mc3`yZK<^DqcU@^`Y_y-cOF@bOf=TTqf@5-lT^dNAYQ=~`}Mj*|u zR0xUrsppmaIMAaGdb> z*nMnI!^?3v**-Y0H~LMJXT!q`921ictKq}y$yO7J#nX9zi*i^` zRFnczV5-1%Zdcy_ALu{K|5K87Qa}p)D+O$^*>2W+rRuG-m-AlR=#O--`J}sX9TbLW l$HZvI+;}^_i=wP+zUFx^920}ie9(#d8E{=>QsA!@_yT-d7IXjr From db8e4fae9e62c74affdbd13bd01c34a9c551d2ad Mon Sep 17 00:00:00 2001 From: sgoudham Date: Thu, 8 Oct 2020 18:20:24 +0100 Subject: [PATCH 03/11] Updated gitignore --- .gitignore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c96066d..548ad8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ -/.DS_Store \ No newline at end of file +/.DS_Store +Java Classes and Interfaces/.DS_Store +Java Classes and Interfaces/Calc Engine/.DS_Store +Java Classes and Interfaces/Calc Engine/src/.DS_Store +Java Fundamentals/.DS_Store +Java Fundamentals/Get Organised/src/com/.DS_Store +Java Fundamentals/Get Organised/src/com/pluralsite/.DS_Store From 90e8d0e74ca245cc5bf9deaafa101dabc62aef02 Mon Sep 17 00:00:00 2001 From: Hamothy <58985301+sgoudham@users.noreply.github.com> Date: Thu, 8 Oct 2020 21:58:11 +0100 Subject: [PATCH 04/11] Delete calcEngine.java --- .../Calc Engine/src/calcEngine.java | 43 ------------------- 1 file changed, 43 deletions(-) delete mode 100644 Java Classes and Interfaces/Calc Engine/src/calcEngine.java diff --git a/Java Classes and Interfaces/Calc Engine/src/calcEngine.java b/Java Classes and Interfaces/Calc Engine/src/calcEngine.java deleted file mode 100644 index 66b9df9..0000000 --- a/Java Classes and Interfaces/Calc Engine/src/calcEngine.java +++ /dev/null @@ -1,43 +0,0 @@ -public class calcEngine { - - public static void main(String[] args) { - performCalculations(); - } - - static void performCalculations() { - double[] leftVals = {100.0d, 25.0d, 225.0d, 11.0d}; - double[] rightVals = {50.0d, 92.0d, 17.0d, 3.0d}; - char[] opCodes = {'d', 'a', 's', 'm'}; - double[] results = new double[opCodes.length]; - - for (int i = 0; i < opCodes.length; i++) { - results[i] = execute(opCodes[i], leftVals[i], rightVals[i]); - } - for (double currentResult : results) - System.out.println("result = " + currentResult); - - } - - static double execute(char opCode, double leftVal, double rightVal) { - double result; - switch (opCode) { - case 'a': - result = leftVal + rightVal; - break; - case 's': - result = leftVal - rightVal; - break; - case 'm': - result = leftVal * rightVal; - break; - case 'd': - result = rightVal != 0 ? leftVal / rightVal : 0.0d; - break; - default: - System.out.println("Invalid opCode: " + opCode); - result = 0.0d; - break; - } - return result; - } -} \ No newline at end of file From 5f4a60a5ef2be7a26dd00dbd9f6a8c513a253763 Mon Sep 17 00:00:00 2001 From: Hamothy <58985301+sgoudham@users.noreply.github.com> Date: Thu, 8 Oct 2020 21:58:23 +0100 Subject: [PATCH 05/11] Delete calcEngine.java --- .../Calc Engine/src/calcEngine.java | 187 ------------------ 1 file changed, 187 deletions(-) delete mode 100644 Java Fundamentals/Calc Engine/src/calcEngine.java diff --git a/Java Fundamentals/Calc Engine/src/calcEngine.java b/Java Fundamentals/Calc Engine/src/calcEngine.java deleted file mode 100644 index b4a052e..0000000 --- a/Java Fundamentals/Calc Engine/src/calcEngine.java +++ /dev/null @@ -1,187 +0,0 @@ -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.util.Scanner; - -public class calcEngine { - - static double execute(char opCode, double leftVal, double rightVal) { - /* Return the correct value - - // Enhanced Switch Statement - switch (opCodes[i]) { - case 'a' -> results[i] = leftVals[i] + rightVals[i]; - case 's' -> results[i] = leftVals[i] - rightVals[i]; - case 'm' -> results[i] = leftVals[i] * rightVals[i]; - case 'd' -> results[i] = rightVals[i] != 0 ? leftVals[i] / rightVals[i] : 0.0d; - default -> { - System.out.println("Invalid opCode" + opCodes[i]); - results[i] = 0.0d; - } - } - */ - double result; - switch (opCode) { - case 'a': - result = leftVal + rightVal; - break; - case 's': - result = leftVal - rightVal; - break; - case 'm': - result = leftVal * rightVal; - break; - case 'd': - result = rightVal != 0 ? leftVal / rightVal : 0.0d; - break; - default: - System.out.println("Invalid opCode" + opCode); - result = 0.0d; - break; - } - return result; - } - - static double getCommandLine(String[] args) { - /* Handle the command line arguments and get the result */ - - char opCode = args[0].charAt(0); - double leftVal = Double.parseDouble(args[1]); - double rightVal = Double.parseDouble(args[2]); - return execute(opCode, leftVal, rightVal); - - } - - static char getOpCodeFromString(String operationName) { - /* Return the opcode from the string*/ - - return operationName.charAt(0); - } - - static double valueFromWord(String word) { - /* Return the double representation of the number */ - - String[] values = { - "zero", "one", "two", "three", "four", "five", - "six", "seven", "eight", "nine", "ten" - }; - double value = -1d; - for (int i = 0; i < values.length; i++) { - if (word.equals(values[i])) { - value = i; - break; - } - } - - // Checking to see if value had changed, if not. Parse the string into a double - if (value == -1) - value = Double.parseDouble(word); - - return value; - } - - static char symbolFromOpCode(char opCode) { - /* Get the relevant symbol for the operation given by the user*/ - - char[] opCodes = {'a', 's', 'm', 'd'}; - char[] symbols = {'+', '-', '*', '/'}; - char symbol = ' '; - - // Loop through the list of chars and get the relevant symbol - for (int i = 0; i < opCodes.length; i++) { - if (opCode == opCodes[i]) { - symbol = symbols[i]; - break; - } - } - return symbol; - } - - static void displayResult(char opCode, double leftVal, double rightVal, double result) { - /* Display the result of the expression but nicely formatted */ - - char symbol = symbolFromOpCode(opCode); - // StringBuilder stringBuilder = new StringBuilder(); - - // stringBuilder.append(leftVal); - // stringBuilder.append(" " + symbol + " "); - // stringBuilder.append(rightVal); - // stringBuilder.append(" = "); - // stringBuilder.append(result); - - // String finalResult = stringBuilder.toString(); - - String finalResult = String.format("%.1f %c %.1f = %.1f", - leftVal, symbol, rightVal, result); - System.out.println(finalResult); - - } - - static void handleWhen(String[] stringParts) { - /* Return date arithmetic operation (days added) */ - - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); - LocalDate startDate = LocalDate.parse(stringParts[1], dateTimeFormatter); - long daysToAdd = (long) valueFromWord(stringParts[2]); - - LocalDate newDate = startDate.plusDays(daysToAdd); - String output = String.format("%s + %d days is %s", - startDate.format(dateTimeFormatter), daysToAdd, newDate.format(dateTimeFormatter)); - System.out.println(output); - - } - - static void performOperation(String[] stringParts) { - /* Execute the operation with the numbers given by the user */ - - char opCode = getOpCodeFromString(stringParts[0]); - - if (opCode == 'w') { - handleWhen(stringParts); - } else { - double leftVal = valueFromWord(stringParts[1]); - double rightVal = valueFromWord(stringParts[2]); - double result = execute(opCode, leftVal, rightVal); - displayResult(opCode, leftVal, rightVal, result); - - } - } - - - static void executeInteractively() { - /* Allow the user to be able to enter in numbers for operations */ - - Scanner in = new Scanner(System.in); - System.out.println("Enter in an operation and two numbers"); - String userInput = in.nextLine(); - in.close(); - - String[] stringParts = userInput.split(" "); - performOperation(stringParts); - - } - - public static void main(String[] args) { - - double[] leftVals = {100.0d, 25.0d, 225.0d, 11.0d}; - double[] rightVals = {50.0d, 92.0d, 17.0d, 3.0}; - char[] opCodes = {'d', 'a', 's', 'm'}; - double[] results = new double[opCodes.length]; - - // Make sure the user has entered in command line arguments before trying to use them - if (args.length == 0) { - // Get the results of the operation and store it into an array - for (int i = 0; i < opCodes.length; i++) - results[i] = execute(opCodes[i], leftVals[i], rightVals[i]); - - // Print out all the results stored in the array - for (double currentResult: results) - System.out.println(currentResult); - - } else if (args.length == 1 && args[0].equals("interactive")) { - executeInteractively(); - } else if (args.length == 3) - System.out.println(getCommandLine(args)); - else - System.out.println("Please Enter 3 Command Line Arguments!"); - } -} From 817f064ac1c90d93d877e52c5c09a9bc81553bca Mon Sep 17 00:00:00 2001 From: Hamothy <58985301+sgoudham@users.noreply.github.com> Date: Thu, 8 Oct 2020 21:58:34 +0100 Subject: [PATCH 06/11] Delete getOrganised.java --- .../src/com/pluralsite/getorganised/getOrganised.java | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 Java Fundamentals/Get Organised/src/com/pluralsite/getorganised/getOrganised.java diff --git a/Java Fundamentals/Get Organised/src/com/pluralsite/getorganised/getOrganised.java b/Java Fundamentals/Get Organised/src/com/pluralsite/getorganised/getOrganised.java deleted file mode 100644 index b461644..0000000 --- a/Java Fundamentals/Get Organised/src/com/pluralsite/getorganised/getOrganised.java +++ /dev/null @@ -1,6 +0,0 @@ -public class getOrganised { - - public static void main(String[] args) { - System.out.println("I'm being organised!"); - } -} From a07e12ee281df881476c425ba58fbd11f849da86 Mon Sep 17 00:00:00 2001 From: Hamothy <58985301+sgoudham@users.noreply.github.com> Date: Thu, 8 Oct 2020 21:58:48 +0100 Subject: [PATCH 07/11] Delete helloWorld.java --- Java Fundamentals/Hello World/src/helloWorld.java | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 Java Fundamentals/Hello World/src/helloWorld.java diff --git a/Java Fundamentals/Hello World/src/helloWorld.java b/Java Fundamentals/Hello World/src/helloWorld.java deleted file mode 100644 index 754058b..0000000 --- a/Java Fundamentals/Hello World/src/helloWorld.java +++ /dev/null @@ -1,7 +0,0 @@ -public class helloWorld { - - public static void main(String[] args) { - /* Printing out Hello World! */ - System.out.println("Hello World!"); - } -} From 261bdb27c58d25d2fc391bac7ed625c2aa95aa83 Mon Sep 17 00:00:00 2001 From: Hamothy <58985301+sgoudham@users.noreply.github.com> Date: Thu, 8 Oct 2020 21:58:56 +0100 Subject: [PATCH 08/11] Delete operatorPrecedence.java --- .../src/operatorPrecedence.java | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 Java Fundamentals/Operator Precedence/src/operatorPrecedence.java diff --git a/Java Fundamentals/Operator Precedence/src/operatorPrecedence.java b/Java Fundamentals/Operator Precedence/src/operatorPrecedence.java deleted file mode 100644 index fce3ae4..0000000 --- a/Java Fundamentals/Operator Precedence/src/operatorPrecedence.java +++ /dev/null @@ -1,16 +0,0 @@ -public class operatorPrecedence { - public static void main(String[] args) { - - int valA = 21; - int valB = 6; - int valC = 3; - int valD = 1; - - int result1 = valA / valC * valD + valB; - int result2 = valA / (valC * (valD + valB)); - - System.out.println(result1); - System.out.println(result2); - - } -} From 8ca948fbf59e8c64d196a8046f86d7a950589d1c Mon Sep 17 00:00:00 2001 From: Hamothy <58985301+sgoudham@users.noreply.github.com> Date: Thu, 8 Oct 2020 21:59:06 +0100 Subject: [PATCH 09/11] Delete typeConversion.java --- .../Type Conversion/src/typeConversion.java | 44 ------------------- 1 file changed, 44 deletions(-) delete mode 100644 Java Fundamentals/Type Conversion/src/typeConversion.java diff --git a/Java Fundamentals/Type Conversion/src/typeConversion.java b/Java Fundamentals/Type Conversion/src/typeConversion.java deleted file mode 100644 index 49a1cbe..0000000 --- a/Java Fundamentals/Type Conversion/src/typeConversion.java +++ /dev/null @@ -1,44 +0,0 @@ -public class typeConversion { - - public static void main(String[] args) { - float floatVal = 1.0f; - double doubleVal = 4.0d; - byte byteVal = 7; - short shortVal = 7; - long longVal = 5; - - // Possible - short result1 = byteVal; - - // Not possible - // short result2 = longVal; - - // Possible - short result2 = (short) longVal; - - // Not Possible - // short result3 = byteVal - longVal; - - // Possible - short result3 = (short) (byteVal - longVal); - - // Not Possible - // long result4 = longVal - floatVal; - - // Better to do this - Possible - float result4 = longVal - floatVal; - - // Possible - double result5 = doubleVal + shortVal; - - - System.out.println("Success"); - System.out.println(result1); - System.out.println(result2); - System.out.println(result3); - System.out.println(result4); - System.out.println(result5); - } -} - - From 5028a66e8d4049a132a94759476473299ae7bd82 Mon Sep 17 00:00:00 2001 From: Hamothy <58985301+sgoudham@users.noreply.github.com> Date: Thu, 8 Oct 2020 21:59:18 +0100 Subject: [PATCH 10/11] Delete .gitignore --- .gitignore | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 548ad8b..0000000 --- a/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -/.DS_Store -Java Classes and Interfaces/.DS_Store -Java Classes and Interfaces/Calc Engine/.DS_Store -Java Classes and Interfaces/Calc Engine/src/.DS_Store -Java Fundamentals/.DS_Store -Java Fundamentals/Get Organised/src/com/.DS_Store -Java Fundamentals/Get Organised/src/com/pluralsite/.DS_Store From 8c8c7f81729ec2cc86ede45a958fe418f6c33997 Mon Sep 17 00:00:00 2001 From: Hamothy <58985301+sgoudham@users.noreply.github.com> Date: Thu, 8 Oct 2020 21:59:32 +0100 Subject: [PATCH 11/11] Delete README.md --- README.md | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 49334dc..0000000 --- a/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# LearningJava - -#### Uploading any projects/code that shows my progression in learning Java - -# Courses Included -- [Java Fundamentals](https://app.pluralsight.com/library/courses/getting-started-programming-java/table-of-contents) -- [Java Classes & Interfaces](https://app.pluralsight.com/library/courses/working-classes-interfaces-java/table-of-contents) \ No newline at end of file