From 66efc3983afc865ec4fcb5b8fd8ff4fc68c766df Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 10:44:41 +0700 Subject: [PATCH 01/18] Created ScoreCalculator.java file File for first assignment for showing grade given a score. --- ScoreCalculator.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 ScoreCalculator.java diff --git a/ScoreCalculator.java b/ScoreCalculator.java new file mode 100644 index 0000000..e69de29 From 78c71c555a81024bc252561e74e33d79a84eca61 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 10:46:05 +0700 Subject: [PATCH 02/18] Created constructor and main Declared constructor and main method, with addition of try-catch for handling empty argument passed. --- ScoreCalculator.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ScoreCalculator.java b/ScoreCalculator.java index e69de29..b6de7e1 100644 --- a/ScoreCalculator.java +++ b/ScoreCalculator.java @@ -0,0 +1,13 @@ +public class ScoreCalculator { + public ScoreCalculator(Integer score){ + + } + + public static void main(String[] args){ + try{ + new ScoreCalculator(Integer.parseInt(args[0])); + } catch(Exception e){ + System.out.println("Empty argument!"); + } + } +} \ No newline at end of file From 09685cde0041dc8f3cf813a717eb991c0935b053 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 10:47:13 +0700 Subject: [PATCH 03/18] Created logic for showing grade Added logic for showing grade inside constructor. --- ScoreCalculator.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ScoreCalculator.java b/ScoreCalculator.java index b6de7e1..0dbb042 100644 --- a/ScoreCalculator.java +++ b/ScoreCalculator.java @@ -1,6 +1,22 @@ public class ScoreCalculator { public ScoreCalculator(Integer score){ - + System.out.print("Your grade: "); + if(score >= 0 && score <= 20){ + System.out.println("E"); + System.out.println("You Have to Study Extra Extra Hard!"); + } else if(score > 20 && score <= 40){ + System.out.println("D"); + System.out.println("You Have to Study Extra Hard!"); + } else if(score > 40 && score <= 60){ + System.out.println("C"); + System.out.println("You Have to Study Hard!"); + } else if(score > 60 && score <= 80){ + System.out.println("B"); + System.out.println("You Have to Study Harder!"); + } else if(score > 80 && score <= 100){ + System.out.println("A"); + System.out.println("You Have to Maintain Your Performance!"); + } } public static void main(String[] args){ From c3c0d34797b6c8ac01e32ea03a6e94dd6ff05b1c Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 10:50:38 +0700 Subject: [PATCH 04/18] Created MonthNamePrinter.java file Added constructor and main method surrounded with try-catch for handling empty argument call. --- MonthNamePrinter.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 MonthNamePrinter.java diff --git a/MonthNamePrinter.java b/MonthNamePrinter.java new file mode 100644 index 0000000..39131de --- /dev/null +++ b/MonthNamePrinter.java @@ -0,0 +1,13 @@ +public class MonthNamePrinter { + public MonthNamePrinter(Integer monthNumber){ + + } + + public static void main(String[] args){ + try{ + new MonthNamePrinter(Integer.parseInt(args[0])); + } catch(Exception e){ + System.out.println("Empty argument!"); + } + } +} \ No newline at end of file From b38d2de86f0554e7d728d1e909aa3e6890d97afb Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 10:52:44 +0700 Subject: [PATCH 05/18] Created DayPrinter.java file Added main method with try-catch for handling empty argument call. --- DayPrinter.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 DayPrinter.java diff --git a/DayPrinter.java b/DayPrinter.java new file mode 100644 index 0000000..c095f6f --- /dev/null +++ b/DayPrinter.java @@ -0,0 +1,9 @@ +public class DayPrinter { + public static void main(String[] args){ + try{ + new DayPrinter(Integer.parseInt(args[0]), Integer.parseInt(args[1])); + } catch (Exception e){ + System.out.println("Empty argument!"); + } + } +} \ No newline at end of file From 3235f7c80645e6b13be349939fb31f4b752c210e Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 10:55:03 +0700 Subject: [PATCH 06/18] Created FactorialLooping.java file Added empty constructor and main method. --- FactorialLooping.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 FactorialLooping.java diff --git a/FactorialLooping.java b/FactorialLooping.java new file mode 100644 index 0000000..fc5b030 --- /dev/null +++ b/FactorialLooping.java @@ -0,0 +1,9 @@ +public class FactorialLooping { + public FactorialLooping(){ + + } + + public static void main(String[] args){ + new FactorialLooping(); + } +} \ No newline at end of file From 692a6dc504b61f466abcd187623c23a1251cbd18 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 10:56:39 +0700 Subject: [PATCH 07/18] Created FactorialRecursive.java file Added empty constructor and main method with try-catch for handling empty argument call. --- FactorialRecursive.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 FactorialRecursive.java diff --git a/FactorialRecursive.java b/FactorialRecursive.java new file mode 100644 index 0000000..ea1399b --- /dev/null +++ b/FactorialRecursive.java @@ -0,0 +1,13 @@ +public class FactorialRecursive { + public FactorialRecursive(){ + + } + + public static void main(String[] args){ + try{ + new FactorialRecursive(); + } catch (Exception e){ + System.out.println("Empty argument!"); + } + } +} \ No newline at end of file From f08eae74652f112d0f2161fd367894805039273e Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 11:02:22 +0700 Subject: [PATCH 08/18] Finished working with FactorialRecursive.java Finished implementing factorial calculation using recursive method. --- FactorialRecursive.class | Bin 0 -> 935 bytes FactorialRecursive.java | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 FactorialRecursive.class diff --git a/FactorialRecursive.class b/FactorialRecursive.class new file mode 100644 index 0000000000000000000000000000000000000000..bc8889d4c84f93041b43e774198e73d66a7998aa GIT binary patch literal 935 zcmZuv+int36kP`>19SkPK)tlJc&S`!(W+I0@x`lp)CfuN%reWzy)lt3m^K9&PnXi2+SDA}%RDyNveq$c2d)j8rs zv~1bxb-!I#&Vj7ASP55M+4!_CyOZ4i!m=&*r9kRZ@*1hy(z12`aBfr8bu7DC%+{z^ zAXM%2orc=8^oHd<*>F3KC0lQ&(zmp11343UY?`=_EfWz$O)Q~c;DL#U*f#LUq*qS_ z;{Owv*uhf`PY5i{JlOr*P+iyRP+oMm-E~jarPJ)UmF=cA*E4}DGjOGTtQxLBY*w0h zC=jr0w`igv&skk-=)hfCXnvTEvTOKT-7E+r_VLXv0GNB@P<~oG)&2M zaVq~}nftmL)Z&jM=g(oRnKn~mS2{gK#s5I2CqdB{MyK@}uadzFrynmo+ILVkvkH97 zfsOnS!uJI$`kfmkN9XXI!OQ$3zrOi&Aku>vV}v}KE5P|Q{D_Y-ktQtyc6bdLl;h;flI%vuCNB$1kM98LtT{eV5BSf?kmhP s>Eeq+n5RU8vk7vH1*WhtVvmt4K}|ZYl2r>e;5jg`9N^GZrXF1T3xD^=z5oCK literal 0 HcmV?d00001 diff --git a/FactorialRecursive.java b/FactorialRecursive.java index ea1399b..9fe7752 100644 --- a/FactorialRecursive.java +++ b/FactorialRecursive.java @@ -1,11 +1,21 @@ public class FactorialRecursive { - public FactorialRecursive(){ + private Integer recursive(Integer number){ + if(number > 1){ + return number * recursive(number - 1); + } else { + return 1; + } + } + + public FactorialRecursive(Integer number){ + Integer result = recursive(number); + System.out.println(result); } public static void main(String[] args){ try{ - new FactorialRecursive(); + new FactorialRecursive(Integer.parseInt(args[0])); } catch (Exception e){ System.out.println("Empty argument!"); } From 30b3e8aa7172dabe233b027e442455e5861ca4af Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 11:07:39 +0700 Subject: [PATCH 09/18] Finished working with FactorialLooping.java Finished implementing factorial calculation using looping. --- FactorialLooping.class | Bin 0 -> 843 bytes FactorialLooping.java | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 FactorialLooping.class diff --git a/FactorialLooping.class b/FactorialLooping.class new file mode 100644 index 0000000000000000000000000000000000000000..2731afe203bfda15c525c9639775d5b46a5c88a3 GIT binary patch literal 843 zcmZ8f$xa(V5Pdx!+-4ZOVw24TLKZIsCuBPiafv{(WI`k(BgCogbeticMMIl}d;TN` z&g1|nk@5lgmHa^tA=LwxZKP56)azI8RaN)ze?NW!c#c;VY}~YP3%B)hXA(usS-6XN zjs=a}vk=E3$NdBzX#63^BZl~E$8*#gL!s2z7l)$O6JEDg_mu3)aJAfGFyHv^B}1y= zc=B!EZOd?5w0ne1HZ5qQ1otb3F4Vzj2 z(vg93e5xwB?gr{;UWDDgD?O!!UXsv|yVc&89mS9tLRYh3h?Vp>_@U_a<<+t(<|G=P)+SwPN)Y zv2VyN(N_GZv9B?9eDUWyOoAp(B9Sz$bKudxi5Mm^fgG6>XBEx@?I6ikjR zM~*%Q{KYIWW{|%sVvkBNwBAp|cPp`#b8vD!Lt^I`c7trQ)+we=hz-)5p Date: Tue, 14 Aug 2018 11:12:44 +0700 Subject: [PATCH 10/18] Finished working with DayPrinter.java Finished implementing logic for printing number of day given year and month. --- DayPrinter.class | Bin 0 -> 990 bytes DayPrinter.java | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 DayPrinter.class diff --git a/DayPrinter.class b/DayPrinter.class new file mode 100644 index 0000000000000000000000000000000000000000..0b09471c6bd6f4c9fb781ec054c596092d51f867 GIT binary patch literal 990 zcmZ`&?M@Rx6g|5w%(5($4=Dsu~}@ln`M`Xi9hur zd;t>w=?@^9_yE3$Z=s%9ss*FT&dj}M?wot>o!M_cK7R!;k7W~G7&37Qm)kIm5d)(p z#xQPR!oZ|~DFZ2iv>$}Vmw3$QbA5;twa%dbD#|lTOu|D`~ReNW!Pl)xz57Baf z1!cBIW@ehq!h4TSg^37DD$|I}c4fBF{75z(=Q!u0%sS#!cOUK8pkJi!O)7uRhzk1P zqaUwv0dFvfw-_Pk_2E+2QW@_lt1DaCNU8y5YV3q3>eHc$RHgTe*w$( B#b^Kk literal 0 HcmV?d00001 diff --git a/DayPrinter.java b/DayPrinter.java index c095f6f..aa43344 100644 --- a/DayPrinter.java +++ b/DayPrinter.java @@ -1,4 +1,33 @@ public class DayPrinter { + public DayPrinter(Integer year, Integer month){ + switch(month){ + case 1: + case 3: + case 5: + case 7: + case 8: + case 10: + case 12: + System.out.println("31"); + break; + case 4: + case 6: + case 9: + case 11: + System.out.println("30"); + break; + case 2: + if(year % 4 == 0){ + System.out.println("29"); + } else { + System.out.println("28"); + } + break; + default: + System.out.println("Invalid input!"); + } + } + public static void main(String[] args){ try{ new DayPrinter(Integer.parseInt(args[0]), Integer.parseInt(args[1])); From 9b86b7d1299af28b31c258cef00fa88739ae135b Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 11:14:42 +0700 Subject: [PATCH 11/18] Finished working with MonthNamePrinter.java Finished implementing logic for printing month name given the month number. --- MonthNamePrinter.class | Bin 0 -> 1236 bytes MonthNamePrinter.java | 42 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 MonthNamePrinter.class diff --git a/MonthNamePrinter.class b/MonthNamePrinter.class new file mode 100644 index 0000000000000000000000000000000000000000..759057147a54a5cdf01312ec3c3427d4af17238f GIT binary patch literal 1236 zcmZ{j>q`_-7{;GjSLe7+nwPb^X90Q6xzhSk^{!xprb zqYdo>9WiW0r@%IWE`e@=?E*UldIWj}`UG|g>=M{5u*b$;{oy`+^v6(x{WcB=9JF!B zLfL-TbAy8x>f6R<<-F|9NH5(z>;)>V{QmYS3(=#w^U6ZinCq$WFgvaMNjaUNXGJoQ zsf!7jH}9-s<1oXs()Dz@vqkxmf$w^0rekFbv1BgvQ)lPD7tD;ytUAe1y| z4F_v5zRt*sRC9Gd-*VEbiH|*anCnd zSov?y4n{EQUjTHuuXmkwj*0{o8r^ZTyO&Y5V)@xj8utH-s@dX=-U_DRY zoDoD(!mC?~lPE(H0%uWgO5XWt-!d;4YkD@)GXb-Ug zPtbs8Xv8ZDyNG5ip#>lKFa8Ow_=0wPMJJ=cs+B)jFk+*@#zr7k^k=hnBfmF`U?)+t zh=%v5Inz4{dEiS$yc*;##IvU*MfY^Sf6-W}|>hn4$GbsLdM N8=C}6G&3lImY;Nv1Wy0} literal 0 HcmV?d00001 diff --git a/MonthNamePrinter.java b/MonthNamePrinter.java index 39131de..56bb045 100644 --- a/MonthNamePrinter.java +++ b/MonthNamePrinter.java @@ -1,6 +1,46 @@ public class MonthNamePrinter { public MonthNamePrinter(Integer monthNumber){ - + switch(monthNumber){ + case 1: + System.out.println("January"); + break; + case 2: + System.out.println("February"); + break; + case 3: + System.out.println("March"); + break; + case 4: + System.out.println("April"); + break; + case 5: + System.out.println("May"); + break; + case 6: + System.out.println("June"); + break; + case 7: + System.out.println("July"); + break; + case 8: + System.out.println("August"); + break; + case 9: + System.out.println("September"); + break; + case 10: + System.out.println("October"); + break; + case 11: + System.out.println("November"); + break; + case 12: + System.out.println("December"); + break; + default: + System.out.println("Input invalid!"); + break; + } } public static void main(String[] args){ From d1d5bb06aa5abefbccbac8a10e9f445fddff39b4 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 11:17:58 +0700 Subject: [PATCH 12/18] Finished working with ScoreCalculator.java Finished implementing logic for showing grade given score. --- ScoreCalculator.class | Bin 0 -> 1250 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 ScoreCalculator.class diff --git a/ScoreCalculator.class b/ScoreCalculator.class new file mode 100644 index 0000000000000000000000000000000000000000..0bb24c1bcae30aa1d95f59cd75ea6955c5b1e6a7 GIT binary patch literal 1250 zcmZ{jTTc@~6vzKl3OkgAwor;Fm#q{mpi~i20WVmJ6hTNzFodU}9hzdh+bmlGpTS3c zGw}ryUeyO6nizfcL#bz$Me2ozo!L3_JC{BGv)_Mw`T}4Kive^X-iUq-a9j%@fx!TV zFwAjX9d2-pa3ncya@^t=<+#l;#&L&ZT*F<3-c!r{0K%BiFv&5c;Q>R#RM9Lt4;i9~ zg)Olok|kjlk{Q#H1!+$Xt}^&jR$ej$7mB8QUM+7(dqr%N$kLp3MDFFHsJLg!qJiT0 z%c5wiaO*YkvW{Ie3lxqrGX%0$)y~P;qKXp9<}6#LL@8G-3CFTWR24cd;gN>NI;Qc2 zL0=;WqhO1?oG>(`bj%=4*>ud}DFaLEm_wSOk2qsa>`240jI2}5?-}V`#}?i?C+vKT z@EL~gi^wx3#nACDb9PHLb^iZW+A6~|!$9r*BK5?f#~`C^EK7USvdhBENrHoaH9$uO z^E#ekL3N>%q3v9k^lna8oT5by4yMZ$XU`CJp<0%vLxDo)+|tID%sC9l?WeL8t>iLk=8$qylu5MHD*iMx)K?TlUbWNnTWtnTx2vL5C7~&A zhCy>3O7sD|BJ6ERWnJK{;2q_Vj^n(CCFx4(vF9U3x&OWk! z8#)I22w!X65&XkPsDF!IwS^-4h$?%-5j3@P+7I#O^zOie5+2m(K>-)CTqtn{O?gn0 z2k9;}??O{&(6R?Ldr*rD^}EpW0lM6m{65-LEkO?o(f+~xv@5jEqt$))qYgU!=t4c> zXh0Gg{Uw~HrV%R$U=vL+iP%FkUZDlA5yU%$@Sa+ALNUG~LcTy7>VJ~6PeZqc9v~i% z$0$TEjME-sosy^?_IyToZK!UPoKMhpjL3^a=nJaQs9PW-CQL!wiB^S1sW6ZhVLC-f Zk# Date: Tue, 14 Aug 2018 11:20:59 +0700 Subject: [PATCH 13/18] Modified algorithm for FactorialRecursive.java Added shorter implementation of factorial calculation using recursive method. --- FactorialRecursive.class | Bin 935 -> 934 bytes FactorialRecursive.java | 5 ++--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/FactorialRecursive.class b/FactorialRecursive.class index bc8889d4c84f93041b43e774198e73d66a7998aa..a18494eafb7ee6f5fe8356f8281a7305cd2c593c 100644 GIT binary patch delta 87 zcmZ3^zKngt0wz8`1{MY;1_lOI?QIN<^CqunG8AA33MnwKF$e*LnHd-rCVyZu=j8+n kaseR^gCGO%WD{m@K|vr(1PFx~L>Yt`WEn&!Phb`Y0A<$;&Hw-a delta 88 zcmZ3+zMOr-0w#Wc1{MY;1_lN-?QINPp@q%4Ej 1){ + if(number > 0){ return number * recursive(number - 1); - } else { - return 1; } + return 1; } public FactorialRecursive(Integer number){ From 0994bd4fb96f33a566944de1bb9136da0d14d45c Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 11:33:31 +0700 Subject: [PATCH 14/18] Created BubbleSort.java file Declared and defined constructor and main method with try-catch for handling empty argument call. --- BubbleSort.class | Bin 0 -> 1082 bytes BubbleSort.java | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 BubbleSort.class create mode 100644 BubbleSort.java diff --git a/BubbleSort.class b/BubbleSort.class new file mode 100644 index 0000000000000000000000000000000000000000..c6f91e5830a1b25a6321bfa6a29051674fff7964 GIT binary patch literal 1082 zcmZuw+fEZv6kVqsm{JGJrRAcGfTFZRrHTre8iE>3NXjMF)EJ+pWvqkkv?)^}zRHXK zflns*K;j!d0MWLvD z`+w>+jAMedCrpwgB+z-1I`cYbm0i0;X`z{7*zwsNjO z__T-ms092`Ihug&xEZrhr3V7D0_v)KTX-SO&&JLeXhV2z|mlBJd zl*@TpW-(cJ&)?{l-p2R$1@n@;c4Yr1AGv2 zj9lCJc7!HAztY{Rz!%RjC}6nz7kxIRWC9#Q1>3Da@C0eQI#f11$-u;77> zi5|ADh|QzV>wc~uj(c@{L9M*W3;f#hG`4dc_Z0h}z)!^rx~X&+Dw6cFh!!jnTV|}x z=o>nE%l#eN(ZO2g9r4~MDmqn!RYU}EfS~w|$NOmF?*KyVql+|MB(4qPBMB82-#7MX zAth(=9nEvcQX_HQ(8qS6N`s!-pWhI8HWJ@K%hOG0^R&`&ZX4Pb2@RgV2?RNB>BZnb xAWTUSs_aG&pCRrB`k2?xOdXTF_0zoBQhylAA=>^*-$!psMNfdNy^Q&A;SXNe>&gHC literal 0 HcmV?d00001 diff --git a/BubbleSort.java b/BubbleSort.java new file mode 100644 index 0000000..a5af11f --- /dev/null +++ b/BubbleSort.java @@ -0,0 +1,33 @@ +public class BubbleSort { + public BubbleSort(Integer count, Integer[] passedArray){ + for(int i = 0; i < count; i++){ + for(int j = 0; j < i; j++){ + if(passedArray[i] <= passedArray[j]){ + //Perform swap + passedArray[i] = passedArray[i] * passedArray[j]; + passedArray[j] = passedArray[i] / passedArray[j]; + passedArray[i] = passedArray[i] / passedArray[j]; + } + } + } + + for(int i = 0; i < count; i++){ + System.out.println(passedArray[i]); + } + } + + public static void main(String[] args){ + Integer numberOfItems = args.length; + Integer[] inputsToBeSorted = new Integer[numberOfItems]; + + for(int i = 0; i < numberOfItems; i++){ + inputsToBeSorted[i] = Integer.parseInt(args[i]); + } + + try { + new BubbleSort(numberOfItems, inputsToBeSorted); + } catch (Exception e) { + System.out.println("Empty argument!"); + } + } +} \ No newline at end of file From 72dbd8623346a20cc44badca6c18733bde3f781c Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 12:08:19 +0700 Subject: [PATCH 15/18] Modified BubbleSort.java and deleted .class files Added swapping using multiplication/division, XOR, and addition/substraction in BubbleSort.java. .class files are also deleted. --- BubbleSort.class | Bin 1082 -> 0 bytes BubbleSort.java | 18 ++++++++++++++---- DayPrinter.class | Bin 990 -> 0 bytes FactorialLooping.class | Bin 843 -> 0 bytes FactorialRecursive.class | Bin 934 -> 0 bytes MonthNamePrinter.class | Bin 1236 -> 0 bytes ScoreCalculator.class | Bin 1250 -> 0 bytes 7 files changed, 14 insertions(+), 4 deletions(-) delete mode 100644 BubbleSort.class delete mode 100644 DayPrinter.class delete mode 100644 FactorialLooping.class delete mode 100644 FactorialRecursive.class delete mode 100644 MonthNamePrinter.class delete mode 100644 ScoreCalculator.class diff --git a/BubbleSort.class b/BubbleSort.class deleted file mode 100644 index c6f91e5830a1b25a6321bfa6a29051674fff7964..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1082 zcmZuw+fEZv6kVqsm{JGJrRAcGfTFZRrHTre8iE>3NXjMF)EJ+pWvqkkv?)^}zRHXK zflns*K;j!d0MWLvD z`+w>+jAMedCrpwgB+z-1I`cYbm0i0;X`z{7*zwsNjO z__T-ms092`Ihug&xEZrhr3V7D0_v)KTX-SO&&JLeXhV2z|mlBJd zl*@TpW-(cJ&)?{l-p2R$1@n@;c4Yr1AGv2 zj9lCJc7!HAztY{Rz!%RjC}6nz7kxIRWC9#Q1>3Da@C0eQI#f11$-u;77> zi5|ADh|QzV>wc~uj(c@{L9M*W3;f#hG`4dc_Z0h}z)!^rx~X&+Dw6cFh!!jnTV|}x z=o>nE%l#eN(ZO2g9r4~MDmqn!RYU}EfS~w|$NOmF?*KyVql+|MB(4qPBMB82-#7MX zAth(=9nEvcQX_HQ(8qS6N`s!-pWhI8HWJ@K%hOG0^R&`&ZX4Pb2@RgV2?RNB>BZnb xAWTUSs_aG&pCRrB`k2?xOdXTF_0zoBQhylAA=>^*-$!psMNfdNy^Q&A;SXNe>&gHC diff --git a/BubbleSort.java b/BubbleSort.java index a5af11f..ee8eb74 100644 --- a/BubbleSort.java +++ b/BubbleSort.java @@ -3,10 +3,20 @@ public BubbleSort(Integer count, Integer[] passedArray){ for(int i = 0; i < count; i++){ for(int j = 0; j < i; j++){ if(passedArray[i] <= passedArray[j]){ - //Perform swap - passedArray[i] = passedArray[i] * passedArray[j]; - passedArray[j] = passedArray[i] / passedArray[j]; - passedArray[i] = passedArray[i] / passedArray[j]; + ////Swapping using multiplication/division - buggy when any item(s) is/are 0 + //passedArray[i] = passedArray[i] * passedArray[j]; + //passedArray[j] = passedArray[i] / passedArray[j]; + //passedArray[i] = passedArray[i] / passedArray[j]; + + ////Swapping using XOR + //passedArray[i] = passedArray[i] ^ passedArray[j]; + //passedArray[j] = passedArray[i] ^ passedArray[j]; + //passedArray[i] = passedArray[i] ^ passedArray[j]; + + //Swapping using addition/substraction + passedArray[i] = passedArray[i] + passedArray[j]; + passedArray[j] = passedArray[i] - passedArray[j]; + passedArray[i] = passedArray[i] - passedArray[j]; } } } diff --git a/DayPrinter.class b/DayPrinter.class deleted file mode 100644 index 0b09471c6bd6f4c9fb781ec054c596092d51f867..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 990 zcmZ`&?M@Rx6g|5w%(5($4=Dsu~}@ln`M`Xi9hur zd;t>w=?@^9_yE3$Z=s%9ss*FT&dj}M?wot>o!M_cK7R!;k7W~G7&37Qm)kIm5d)(p z#xQPR!oZ|~DFZ2iv>$}Vmw3$QbA5;twa%dbD#|lTOu|D`~ReNW!Pl)xz57Baf z1!cBIW@ehq!h4TSg^37DD$|I}c4fBF{75z(=Q!u0%sS#!cOUK8pkJi!O)7uRhzk1P zqaUwv0dFvfw-_Pk_2E+2QW@_lt1DaCNU8y5YV3q3>eHc$RHgTe*w$( B#b^Kk diff --git a/FactorialLooping.class b/FactorialLooping.class deleted file mode 100644 index 2731afe203bfda15c525c9639775d5b46a5c88a3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 843 zcmZ8f$xa(V5Pdx!+-4ZOVw24TLKZIsCuBPiafv{(WI`k(BgCogbeticMMIl}d;TN` z&g1|nk@5lgmHa^tA=LwxZKP56)azI8RaN)ze?NW!c#c;VY}~YP3%B)hXA(usS-6XN zjs=a}vk=E3$NdBzX#63^BZl~E$8*#gL!s2z7l)$O6JEDg_mu3)aJAfGFyHv^B}1y= zc=B!EZOd?5w0ne1HZ5qQ1otb3F4Vzj2 z(vg93e5xwB?gr{;UWDDgD?O!!UXsv|yVc&89mS9tLRYh3h?Vp>_@U_a<<+t(<|G=P)+SwPN)Y zv2VyN(N_GZv9B?9eDUWyOoAp(B9Sz$bKudxi5Mm^fgG6>XBEx@?I6ikjR zM~*%Q{KYIWW{|%sVvkBNwBAp|cPp`#b8vD!Lt^I`c7trQ)+we=hz-)5p74~8ea?~O$r!GY79@)GSb^QurMB`~rHU8mmiEi}OE7`R>&_lK zl2ymkTRpd-{T)nx}!Y$((#<&mB7rUIbWw< z0jt*O`Axmym$$+yv*PW>zHSBrQ)ke~ zLxGs%1$EW#QGPg=uL#IPlWl)6|6RGC-PrT_o{ diff --git a/MonthNamePrinter.class b/MonthNamePrinter.class deleted file mode 100644 index 759057147a54a5cdf01312ec3c3427d4af17238f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1236 zcmZ{j>q`_-7{;GjSLe7+nwPb^X90Q6xzhSk^{!xprb zqYdo>9WiW0r@%IWE`e@=?E*UldIWj}`UG|g>=M{5u*b$;{oy`+^v6(x{WcB=9JF!B zLfL-TbAy8x>f6R<<-F|9NH5(z>;)>V{QmYS3(=#w^U6ZinCq$WFgvaMNjaUNXGJoQ zsf!7jH}9-s<1oXs()Dz@vqkxmf$w^0rekFbv1BgvQ)lPD7tD;ytUAe1y| z4F_v5zRt*sRC9Gd-*VEbiH|*anCnd zSov?y4n{EQUjTHuuXmkwj*0{o8r^ZTyO&Y5V)@xj8utH-s@dX=-U_DRY zoDoD(!mC?~lPE(H0%uWgO5XWt-!d;4YkD@)GXb-Ug zPtbs8Xv8ZDyNG5ip#>lKFa8Ow_=0wPMJJ=cs+B)jFk+*@#zr7k^k=hnBfmF`U?)+t zh=%v5Inz4{dEiS$yc*;##IvU*MfY^Sf6-W}|>hn4$GbsLdM N8=C}6G&3lImY;Nv1Wy0} diff --git a/ScoreCalculator.class b/ScoreCalculator.class deleted file mode 100644 index 0bb24c1bcae30aa1d95f59cd75ea6955c5b1e6a7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1250 zcmZ{jTTc@~6vzKl3OkgAwor;Fm#q{mpi~i20WVmJ6hTNzFodU}9hzdh+bmlGpTS3c zGw}ryUeyO6nizfcL#bz$Me2ozo!L3_JC{BGv)_Mw`T}4Kive^X-iUq-a9j%@fx!TV zFwAjX9d2-pa3ncya@^t=<+#l;#&L&ZT*F<3-c!r{0K%BiFv&5c;Q>R#RM9Lt4;i9~ zg)Olok|kjlk{Q#H1!+$Xt}^&jR$ej$7mB8QUM+7(dqr%N$kLp3MDFFHsJLg!qJiT0 z%c5wiaO*YkvW{Ie3lxqrGX%0$)y~P;qKXp9<}6#LL@8G-3CFTWR24cd;gN>NI;Qc2 zL0=;WqhO1?oG>(`bj%=4*>ud}DFaLEm_wSOk2qsa>`240jI2}5?-}V`#}?i?C+vKT z@EL~gi^wx3#nACDb9PHLb^iZW+A6~|!$9r*BK5?f#~`C^EK7USvdhBENrHoaH9$uO z^E#ekL3N>%q3v9k^lna8oT5by4yMZ$XU`CJp<0%vLxDo)+|tID%sC9l?WeL8t>iLk=8$qylu5MHD*iMx)K?TlUbWNnTWtnTx2vL5C7~&A zhCy>3O7sD|BJ6ERWnJK{;2q_Vj^n(CCFx4(vF9U3x&OWk! z8#)I22w!X65&XkPsDF!IwS^-4h$?%-5j3@P+7I#O^zOie5+2m(K>-)CTqtn{O?gn0 z2k9;}??O{&(6R?Ldr*rD^}EpW0lM6m{65-LEkO?o(f+~xv@5jEqt$))qYgU!=t4c> zXh0Gg{Uw~HrV%R$U=vL+iP%FkUZDlA5yU%$@Sa+ALNUG~LcTy7>VJ~6PeZqc9v~i% z$0$TEjME-sosy^?_IyToZK!UPoKMhpjL3^a=nJaQs9PW-CQL!wiB^S1sW6ZhVLC-f Zk# Date: Tue, 14 Aug 2018 13:16:10 +0700 Subject: [PATCH 16/18] Renamed files ordered by time of order Renamed files according to order of given assignments. 1st is ScoreCalculator, 2nd is MonthNamePrinter, and so on. --- ScoreCalculator.java => 1. ScoreGradePrinter.java | 0 MonthNamePrinter.java => 2. MonthNamePrinter.java | 0 DayPrinter.java => 3. DayPrinter.java | 0 FactorialLooping.java => 4. FactorialLooping.java | 0 FactorialRecursive.java => 5. FactorialRecursive.java | 0 BubbleSort.java => 6. BubbleSort.java | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename ScoreCalculator.java => 1. ScoreGradePrinter.java (100%) rename MonthNamePrinter.java => 2. MonthNamePrinter.java (100%) rename DayPrinter.java => 3. DayPrinter.java (100%) rename FactorialLooping.java => 4. FactorialLooping.java (100%) rename FactorialRecursive.java => 5. FactorialRecursive.java (100%) rename BubbleSort.java => 6. BubbleSort.java (100%) diff --git a/ScoreCalculator.java b/1. ScoreGradePrinter.java similarity index 100% rename from ScoreCalculator.java rename to 1. ScoreGradePrinter.java diff --git a/MonthNamePrinter.java b/2. MonthNamePrinter.java similarity index 100% rename from MonthNamePrinter.java rename to 2. MonthNamePrinter.java diff --git a/DayPrinter.java b/3. DayPrinter.java similarity index 100% rename from DayPrinter.java rename to 3. DayPrinter.java diff --git a/FactorialLooping.java b/4. FactorialLooping.java similarity index 100% rename from FactorialLooping.java rename to 4. FactorialLooping.java diff --git a/FactorialRecursive.java b/5. FactorialRecursive.java similarity index 100% rename from FactorialRecursive.java rename to 5. FactorialRecursive.java diff --git a/BubbleSort.java b/6. BubbleSort.java similarity index 100% rename from BubbleSort.java rename to 6. BubbleSort.java From b20a41658f0bfccbc1d0ee5a7b5febbd5955c67d Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 18:17:23 +0700 Subject: [PATCH 17/18] Renamed files according to class names Forgotten about file name and class name must be the same in last push. Edited the file names. --- BubbleSort.java | 43 +++++++++++++++++++++++++++++++++ CollectionsTest.java | 37 ++++++++++++++++++++++++++++ DayPrinter.java | 38 +++++++++++++++++++++++++++++ FactorialLooping.java | 19 +++++++++++++++ FactorialRecursive.java | 22 +++++++++++++++++ MonthNamePrinter.java | 53 +++++++++++++++++++++++++++++++++++++++++ ScoreGradePrinter.java | 29 ++++++++++++++++++++++ 7 files changed, 241 insertions(+) create mode 100644 BubbleSort.java create mode 100644 CollectionsTest.java create mode 100644 DayPrinter.java create mode 100644 FactorialLooping.java create mode 100644 FactorialRecursive.java create mode 100644 MonthNamePrinter.java create mode 100644 ScoreGradePrinter.java diff --git a/BubbleSort.java b/BubbleSort.java new file mode 100644 index 0000000..ee8eb74 --- /dev/null +++ b/BubbleSort.java @@ -0,0 +1,43 @@ +public class BubbleSort { + public BubbleSort(Integer count, Integer[] passedArray){ + for(int i = 0; i < count; i++){ + for(int j = 0; j < i; j++){ + if(passedArray[i] <= passedArray[j]){ + ////Swapping using multiplication/division - buggy when any item(s) is/are 0 + //passedArray[i] = passedArray[i] * passedArray[j]; + //passedArray[j] = passedArray[i] / passedArray[j]; + //passedArray[i] = passedArray[i] / passedArray[j]; + + ////Swapping using XOR + //passedArray[i] = passedArray[i] ^ passedArray[j]; + //passedArray[j] = passedArray[i] ^ passedArray[j]; + //passedArray[i] = passedArray[i] ^ passedArray[j]; + + //Swapping using addition/substraction + passedArray[i] = passedArray[i] + passedArray[j]; + passedArray[j] = passedArray[i] - passedArray[j]; + passedArray[i] = passedArray[i] - passedArray[j]; + } + } + } + + for(int i = 0; i < count; i++){ + System.out.println(passedArray[i]); + } + } + + public static void main(String[] args){ + Integer numberOfItems = args.length; + Integer[] inputsToBeSorted = new Integer[numberOfItems]; + + for(int i = 0; i < numberOfItems; i++){ + inputsToBeSorted[i] = Integer.parseInt(args[i]); + } + + try { + new BubbleSort(numberOfItems, inputsToBeSorted); + } catch (Exception e) { + System.out.println("Empty argument!"); + } + } +} \ No newline at end of file diff --git a/CollectionsTest.java b/CollectionsTest.java new file mode 100644 index 0000000..6727c6c --- /dev/null +++ b/CollectionsTest.java @@ -0,0 +1,37 @@ +import java.util.*; + +public class CollectionsTest { + public static void main(String[] args){ + //ArrayList + List names = new ArrayList<>(); + names.add("ABC"); + names.add("Budi"); + names.add("Andy"); + names.add(null); + //names.add(stringSet); //Compile error due to different object type + + for(String name : names){ + System.out.println(name); + } + + //Set + Set stringSet = new HashSet<>(); + stringSet.add("String 1"); + stringSet.add("String 1"); + stringSet.add("String 2"); + stringSet.add(null); + //stringSet.add(names); //Compile error due to different object type + for(String str : stringSet){ + System.out.println(str); + } + + //Map + Map scoreByName = new HashMap<>(); + scoreByName.put("Oliver", 100); + scoreByName.put(null, 19); + //scoreByName.put(names, 21); //Compile error due to different object type + for (Map.Entry entry : scoreByName.entrySet()){ //Prints from last item + System.out.println(entry.getKey() + ": " + entry.getValue()); + } + } +} \ No newline at end of file diff --git a/DayPrinter.java b/DayPrinter.java new file mode 100644 index 0000000..aa43344 --- /dev/null +++ b/DayPrinter.java @@ -0,0 +1,38 @@ +public class DayPrinter { + public DayPrinter(Integer year, Integer month){ + switch(month){ + case 1: + case 3: + case 5: + case 7: + case 8: + case 10: + case 12: + System.out.println("31"); + break; + case 4: + case 6: + case 9: + case 11: + System.out.println("30"); + break; + case 2: + if(year % 4 == 0){ + System.out.println("29"); + } else { + System.out.println("28"); + } + break; + default: + System.out.println("Invalid input!"); + } + } + + public static void main(String[] args){ + try{ + new DayPrinter(Integer.parseInt(args[0]), Integer.parseInt(args[1])); + } catch (Exception e){ + System.out.println("Empty argument!"); + } + } +} \ No newline at end of file diff --git a/FactorialLooping.java b/FactorialLooping.java new file mode 100644 index 0000000..053f48e --- /dev/null +++ b/FactorialLooping.java @@ -0,0 +1,19 @@ +public class FactorialLooping { + public FactorialLooping(Integer number){ + Integer result = 1; + + for(int i = 1; i <= number; i++){ + result = result * i; + } + + System.out.println(result); + } + + public static void main(String[] args){ + try{ + new FactorialLooping(Integer.parseInt(args[0])); + } catch(Exception e){ + System.out.println("Empty argument"); + } + } +} \ No newline at end of file diff --git a/FactorialRecursive.java b/FactorialRecursive.java new file mode 100644 index 0000000..d343686 --- /dev/null +++ b/FactorialRecursive.java @@ -0,0 +1,22 @@ +public class FactorialRecursive { + private Integer recursive(Integer number){ + if(number > 0){ + return number * recursive(number - 1); + } + return 1; + } + + public FactorialRecursive(Integer number){ + Integer result = recursive(number); + + System.out.println(result); + } + + public static void main(String[] args){ + try{ + new FactorialRecursive(Integer.parseInt(args[0])); + } catch (Exception e){ + System.out.println("Empty argument!"); + } + } +} \ No newline at end of file diff --git a/MonthNamePrinter.java b/MonthNamePrinter.java new file mode 100644 index 0000000..56bb045 --- /dev/null +++ b/MonthNamePrinter.java @@ -0,0 +1,53 @@ +public class MonthNamePrinter { + public MonthNamePrinter(Integer monthNumber){ + switch(monthNumber){ + case 1: + System.out.println("January"); + break; + case 2: + System.out.println("February"); + break; + case 3: + System.out.println("March"); + break; + case 4: + System.out.println("April"); + break; + case 5: + System.out.println("May"); + break; + case 6: + System.out.println("June"); + break; + case 7: + System.out.println("July"); + break; + case 8: + System.out.println("August"); + break; + case 9: + System.out.println("September"); + break; + case 10: + System.out.println("October"); + break; + case 11: + System.out.println("November"); + break; + case 12: + System.out.println("December"); + break; + default: + System.out.println("Input invalid!"); + break; + } + } + + public static void main(String[] args){ + try{ + new MonthNamePrinter(Integer.parseInt(args[0])); + } catch(Exception e){ + System.out.println("Empty argument!"); + } + } +} \ No newline at end of file diff --git a/ScoreGradePrinter.java b/ScoreGradePrinter.java new file mode 100644 index 0000000..9fab721 --- /dev/null +++ b/ScoreGradePrinter.java @@ -0,0 +1,29 @@ +public class ScoreGradePrinter { + public ScoreGradePrinter(Integer score){ + System.out.print("Your grade: "); + if(score >= 0 && score <= 20){ + System.out.println("E"); + System.out.println("You Have to Study Extra Extra Hard!"); + } else if(score > 20 && score <= 40){ + System.out.println("D"); + System.out.println("You Have to Study Extra Hard!"); + } else if(score > 40 && score <= 60){ + System.out.println("C"); + System.out.println("You Have to Study Hard!"); + } else if(score > 60 && score <= 80){ + System.out.println("B"); + System.out.println("You Have to Study Harder!"); + } else if(score > 80 && score <= 100){ + System.out.println("A"); + System.out.println("You Have to Maintain Your Performance!"); + } + } + + public static void main(String[] args){ + try{ + new ScoreGradePrinter(Integer.parseInt(args[0])); + } catch(Exception e){ + System.out.println("Empty argument!"); + } + } +} \ No newline at end of file From feec02a78efa413dde58765b1c66264c2e290ee1 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 14 Aug 2018 18:26:29 +0700 Subject: [PATCH 18/18] Deleted not important files --- 1. ScoreGradePrinter.java | 29 --------------------- 2. MonthNamePrinter.java | 53 -------------------------------------- 3. DayPrinter.java | 38 --------------------------- 4. FactorialLooping.java | 19 -------------- 5. FactorialRecursive.java | 22 ---------------- 6. BubbleSort.java | 43 ------------------------------- 6 files changed, 204 deletions(-) delete mode 100644 1. ScoreGradePrinter.java delete mode 100644 2. MonthNamePrinter.java delete mode 100644 3. DayPrinter.java delete mode 100644 4. FactorialLooping.java delete mode 100644 5. FactorialRecursive.java delete mode 100644 6. BubbleSort.java diff --git a/1. ScoreGradePrinter.java b/1. ScoreGradePrinter.java deleted file mode 100644 index 0dbb042..0000000 --- a/1. ScoreGradePrinter.java +++ /dev/null @@ -1,29 +0,0 @@ -public class ScoreCalculator { - public ScoreCalculator(Integer score){ - System.out.print("Your grade: "); - if(score >= 0 && score <= 20){ - System.out.println("E"); - System.out.println("You Have to Study Extra Extra Hard!"); - } else if(score > 20 && score <= 40){ - System.out.println("D"); - System.out.println("You Have to Study Extra Hard!"); - } else if(score > 40 && score <= 60){ - System.out.println("C"); - System.out.println("You Have to Study Hard!"); - } else if(score > 60 && score <= 80){ - System.out.println("B"); - System.out.println("You Have to Study Harder!"); - } else if(score > 80 && score <= 100){ - System.out.println("A"); - System.out.println("You Have to Maintain Your Performance!"); - } - } - - public static void main(String[] args){ - try{ - new ScoreCalculator(Integer.parseInt(args[0])); - } catch(Exception e){ - System.out.println("Empty argument!"); - } - } -} \ No newline at end of file diff --git a/2. MonthNamePrinter.java b/2. MonthNamePrinter.java deleted file mode 100644 index 56bb045..0000000 --- a/2. MonthNamePrinter.java +++ /dev/null @@ -1,53 +0,0 @@ -public class MonthNamePrinter { - public MonthNamePrinter(Integer monthNumber){ - switch(monthNumber){ - case 1: - System.out.println("January"); - break; - case 2: - System.out.println("February"); - break; - case 3: - System.out.println("March"); - break; - case 4: - System.out.println("April"); - break; - case 5: - System.out.println("May"); - break; - case 6: - System.out.println("June"); - break; - case 7: - System.out.println("July"); - break; - case 8: - System.out.println("August"); - break; - case 9: - System.out.println("September"); - break; - case 10: - System.out.println("October"); - break; - case 11: - System.out.println("November"); - break; - case 12: - System.out.println("December"); - break; - default: - System.out.println("Input invalid!"); - break; - } - } - - public static void main(String[] args){ - try{ - new MonthNamePrinter(Integer.parseInt(args[0])); - } catch(Exception e){ - System.out.println("Empty argument!"); - } - } -} \ No newline at end of file diff --git a/3. DayPrinter.java b/3. DayPrinter.java deleted file mode 100644 index aa43344..0000000 --- a/3. DayPrinter.java +++ /dev/null @@ -1,38 +0,0 @@ -public class DayPrinter { - public DayPrinter(Integer year, Integer month){ - switch(month){ - case 1: - case 3: - case 5: - case 7: - case 8: - case 10: - case 12: - System.out.println("31"); - break; - case 4: - case 6: - case 9: - case 11: - System.out.println("30"); - break; - case 2: - if(year % 4 == 0){ - System.out.println("29"); - } else { - System.out.println("28"); - } - break; - default: - System.out.println("Invalid input!"); - } - } - - public static void main(String[] args){ - try{ - new DayPrinter(Integer.parseInt(args[0]), Integer.parseInt(args[1])); - } catch (Exception e){ - System.out.println("Empty argument!"); - } - } -} \ No newline at end of file diff --git a/4. FactorialLooping.java b/4. FactorialLooping.java deleted file mode 100644 index 053f48e..0000000 --- a/4. FactorialLooping.java +++ /dev/null @@ -1,19 +0,0 @@ -public class FactorialLooping { - public FactorialLooping(Integer number){ - Integer result = 1; - - for(int i = 1; i <= number; i++){ - result = result * i; - } - - System.out.println(result); - } - - public static void main(String[] args){ - try{ - new FactorialLooping(Integer.parseInt(args[0])); - } catch(Exception e){ - System.out.println("Empty argument"); - } - } -} \ No newline at end of file diff --git a/5. FactorialRecursive.java b/5. FactorialRecursive.java deleted file mode 100644 index d343686..0000000 --- a/5. FactorialRecursive.java +++ /dev/null @@ -1,22 +0,0 @@ -public class FactorialRecursive { - private Integer recursive(Integer number){ - if(number > 0){ - return number * recursive(number - 1); - } - return 1; - } - - public FactorialRecursive(Integer number){ - Integer result = recursive(number); - - System.out.println(result); - } - - public static void main(String[] args){ - try{ - new FactorialRecursive(Integer.parseInt(args[0])); - } catch (Exception e){ - System.out.println("Empty argument!"); - } - } -} \ No newline at end of file diff --git a/6. BubbleSort.java b/6. BubbleSort.java deleted file mode 100644 index ee8eb74..0000000 --- a/6. BubbleSort.java +++ /dev/null @@ -1,43 +0,0 @@ -public class BubbleSort { - public BubbleSort(Integer count, Integer[] passedArray){ - for(int i = 0; i < count; i++){ - for(int j = 0; j < i; j++){ - if(passedArray[i] <= passedArray[j]){ - ////Swapping using multiplication/division - buggy when any item(s) is/are 0 - //passedArray[i] = passedArray[i] * passedArray[j]; - //passedArray[j] = passedArray[i] / passedArray[j]; - //passedArray[i] = passedArray[i] / passedArray[j]; - - ////Swapping using XOR - //passedArray[i] = passedArray[i] ^ passedArray[j]; - //passedArray[j] = passedArray[i] ^ passedArray[j]; - //passedArray[i] = passedArray[i] ^ passedArray[j]; - - //Swapping using addition/substraction - passedArray[i] = passedArray[i] + passedArray[j]; - passedArray[j] = passedArray[i] - passedArray[j]; - passedArray[i] = passedArray[i] - passedArray[j]; - } - } - } - - for(int i = 0; i < count; i++){ - System.out.println(passedArray[i]); - } - } - - public static void main(String[] args){ - Integer numberOfItems = args.length; - Integer[] inputsToBeSorted = new Integer[numberOfItems]; - - for(int i = 0; i < numberOfItems; i++){ - inputsToBeSorted[i] = Integer.parseInt(args[i]); - } - - try { - new BubbleSort(numberOfItems, inputsToBeSorted); - } catch (Exception e) { - System.out.println("Empty argument!"); - } - } -} \ No newline at end of file