From 17e0d53c52b32888a95b67d4824208576127946c Mon Sep 17 00:00:00 2001 From: chintaiann Date: Mon, 17 Jan 2022 17:57:53 +0800 Subject: [PATCH 01/12] Increment Level-0 Commit Level 0.Greet --- src/main/java/Duke.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..923c3496a 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,10 @@ public class Duke { public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + System.out.println("---------------------"); + System.out.println(("Hello! I'm Duke")); + System.out.println(("What can i do for you?")); + System.out.println("---------------------"); + System.out.println(("Bye. Hope to see you again soon!")); + System.out.println("---------------------"); } } From b0542f65bfd717dcaed1e04dcbc98fad57c2f305 Mon Sep 17 00:00:00 2001 From: chintaiann Date: Thu, 3 Feb 2022 01:29:37 +0800 Subject: [PATCH 02/12] Level 1-0 --- src/main/java/Duke.class | Bin 0 -> 1004 bytes src/main/java/Duke.java | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/main/java/Duke.class diff --git a/src/main/java/Duke.class b/src/main/java/Duke.class new file mode 100644 index 0000000000000000000000000000000000000000..fc718cff37563647e2d655a303c5ac03c1a7b50a GIT binary patch literal 1004 zcmZuwTTc@~6#k|yo$b0%Zbd-RK}1@hR7F8)1qC&ba51UYh$gx%11@ZLYr9MAPvIBv zEDyzK;;YerWa8~iDOe2iFlR2`Ip>@2ocaFy(-#04Ea(Uz$PqHof-pn-wz+GjY}46F zt>w36!D9$#EXVR@8G`XdE&>e^4&A^x7^mRbYQ>X9Lb*OU#g^-VEI0L}Y&l-mD@(JO z*3d>*$+L!zc64xb8t6hdL)RJZ47{X**$xGXA0?}cgLIQHbl~JgLvhuQpY52 zaojdAh3V6ktjkG-m+ySjuKXwVQCp-F>l*Gdi216V5Q}a}3eOc4DV40k+%hdkR9x2? z_Vt{XgFni$I;l4BBWNrhee`2dG<#kARM0`eNfSFpXAX)`mxjVucXT5W_1%y+$AI clV=Q}pBU!o|AiFC5Xa;Xgw^{W)Kkp=1zz&rWdHyG literal 0 HcmV?d00001 diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 923c3496a..6a97534c1 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,26 @@ +import java.util.Scanner; + + public class Duke { public static void main(String[] args) { System.out.println("---------------------"); System.out.println(("Hello! I'm Duke")); System.out.println(("What can i do for you?")); System.out.println("---------------------"); - System.out.println(("Bye. Hope to see you again soon!")); - System.out.println("---------------------"); + Boolean run = true; + while (run) { + Scanner sc = new Scanner(System.in); + String anyString = sc.nextLine(); + if (anyString.equals("bye")) { + System.out.println("Bye. Hope to see you again soon!"); + run = false; + } + + + else { + System.out.println(anyString); + } + + } } } From 1c764079d9db2486ff88d81dd6fd6103c05b2561 Mon Sep 17 00:00:00 2001 From: chintaiann Date: Thu, 3 Feb 2022 01:42:39 +0800 Subject: [PATCH 03/12] Level 2-9 --- src/main/java/Duke.class | Bin 1004 -> 1137 bytes src/main/java/Duke.java | 28 ++++++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/Duke.class b/src/main/java/Duke.class index fc718cff37563647e2d655a303c5ac03c1a7b50a..4cd826ae27a70de92645a4cff0525e1e2b5f2585 100644 GIT binary patch delta 614 zcmYk3O-~b16o#KW)9J0vKr6MtNDD2{3Y4}gi1HyKeh?Eh8WIw4HN=KgOKY^4u#t_4 z8#ZQ)26g3zwJeI!;1BQ@_#<@TQlsdZ%EHZg?>!&yecyAx>hGcO=YtQQfGOslg%A2P z#}(1L?jyHYajUDvh5CbXbu~Y{oe2^%+^KYj&fQ_HG#Mt%VSiia@3Ou&z1ptr<5R&1FUG_CNmr$*8T+#tP8`Qs*;rCmNz<-9UTA=r5KSN^I+zKmsWYawCS36h zWUhDuuH~W_NW3-p3ci9d@zO+rHNE-Q`uG0#`m*+)%r9;JxH$a=EV6oFUUZw}xv3el zC~zw(tA~Cb+hT;<3Tr0}>%JGf^6D*Lk(ij=){H8yz4tzQZmU_VyPNO4An+SmGK^V_ zGodhQfg-oo$<#vkS@5yd+-x>{@56$LL&+jVIXYK`j6>C83OD+#M#t|8U}w)anPx_F z-(r?IMPFx3-3xYInNbUNBgYs^*(-bgRJ38-$l9O6Fc{G+L=EFb^wSu6K93>WA*uwF z7F`rqkgBAnN++l<(kLE@#@CP}%My>JkE7p7$O*iSmJ{}V@+*UD t=I9oD4^Qc3T@o+J@tV>AZy4l>Jk62(M^TgikE?Ms(|<|FTP}APD_5nRR(t>e diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 6a97534c1..db182741b 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -7,20 +7,32 @@ public static void main(String[] args) { System.out.println(("Hello! I'm Duke")); System.out.println(("What can i do for you?")); System.out.println("---------------------"); - Boolean run = true; - while (run) { + String[] strings = new String[100]; + + Boolean run = true; + int arrayIndex = 0; + while (run) { Scanner sc = new Scanner(System.in); String anyString = sc.nextLine(); - if (anyString.equals("bye")) { - System.out.println("Bye. Hope to see you again soon!"); - run = false; + + if (anyString.equals("bye")) { + System.out.println("Bye! Hope to see you again."); + run = false; } + else if (anyString.equals("list")){ + for (int i = 0; i Date: Thu, 3 Feb 2022 02:11:29 +0800 Subject: [PATCH 04/12] Level 3 --- src/main/java/Duke.class | Bin 1137 -> 1963 bytes src/main/java/Duke.java | 17 ++++++++++++----- src/main/java/Task.class | Bin 0 -> 1060 bytes src/main/java/Task.java | 23 +++++++++++++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 src/main/java/Task.class create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.class b/src/main/java/Duke.class index 4cd826ae27a70de92645a4cff0525e1e2b5f2585..208c0384db925cef0b733a4372764c5bf1dac730 100644 GIT binary patch literal 1963 zcmaJ?%~Kpj6#q3WJHtABvyhcQ286K7@}VI?1tbcQu)2iAMF;CD*(;ooL z;z0m)s8`_A&;UO}>mJ|d6DGHICRUPrBIPmoXAR5n<{0Y3k+nvsXjBl;@CvjO>WKr_ z6Is%-^JEl^7l90W;-+I*Ucz$(&(5f5rlql3PXMiGQ_!xV1Dy;VHOv{5oCGs10tuHk zD0)ihhP5*jSyR!)(6S^<)9%+}!&&`WJ|k3|W9VAn<({76mTu^2Tfb{N`hlIls^C=y z-zs-A0h~v#f<6rwpfj|+ zX;b8GQ^CawaNaY_i3GW02}e>I))2u6L!BXG`;WVrmCIMS3t$MNGD~9&=gQF&z11p_ zHK{bA;dQ*hpjzUA7dI^0y)#_xZka9>ljK+OKm>3FQwrYH@D|=anbRV%R085&o}2C| z+Dip86WLTT!_YH-Ao}$sJ12C{)?Fba!8+gJhBdC@9r7p3os51b9hLiC)$lIfBTlp2 zOYMr&(3Ol5^a2CZrOEpm7IB@S!OfWll~}k&3B)2>Re33+1Q5dq3O>{j$8seD#lneM zp4br%`Ih63E9m!Bh!sC#0fexk;il}7Vj!|+RD49$V;ZifVwGWFNjO61^m@DWl7g!n zmZZVarIJ2PafGm@VO{2@X-80QxtDiiDcfqNcHGdgi7kfiEYFAq+e&e7-SBp4}-5Bax3@wL>5b@g3riD*#{&R>@l*Au*2q=z zGnHB9xuU)TY5`>{E-9eI2ND!uN-P=@sZs7UE}Mr6iTc8GJ%{I(g|};`-4;Kn&rD<$ zSTaj?5fdfKOVKa#lxI5!4Bu4ex~y0NUE)^S6z*W$wln$M%vpA-W=A8$u23myU4x z5FHX|nhfiuNdfn1W%dYjhZv;MeEkuwP5VQB-=%3Kq&&gWlo}1HWO}23I4RsJf=o(~ zgan!L2mQU@;Q~zr{l4vJ&`-J_KgDf;mLK|A;h*0NXpiNhxIghTZUg( z4Bw#>S(2baq5Fky0t#G502k@{ibBH}ns6D-bQZPXI@)jx?bx6jh$Dy$x{yaVJ}0X$ zsGq(<4;~TEU!xD-(k)RSq~|1mq%-$tLi`0`{EAVeX~zMmFEFM+C^*ml#-xHF1y@G? mqO0vs^w<4?X1aB;Q}lBe21%8Yvqx_Z4*dmaYhC86s3n_3v?p>flCpKigHvZmoA^iaYtO zbtk00yf(dlQuH|qPn#NW7Ch04Aw^jszgx5zabAtZ^t2+pGWUO4T)xcq-p*PsoiF4R z<pfhF|H(Yi-gZCsaXfaYcqMNP>-(kfgx?4;~T9tlYON8T1wwV!bn=Unkp56YHaATLL z71ekpC@5Ml1)})qz)ze?5>$~SAfkg%g6E|P;1rJT4{x?7PXHwJ`~fm3DpNkH8y=1mI>Vgvt(yz(to1A zz*kM$nDoIP;EyuiWl0Kw_%d_n?z!ildvf>B-`n2+_OP2o1W^-)g?orGRDOe0fi>n?(sw0%+yF=}Ik|E!?BWY^imEBrU zma&jUj`&>l-jjlXeaVxCyoCaa49f%F6Ln8ITz_))IYmlysTIRkd7iK`pUQ(;Gb}Aa zpODnL*P*7_hAYK~(V#8-7H{_{lkN)L)Lf6$krT)-mKTr{j4)2`m=DKgCRS(63g={q z54hh8O-YXA)T8N*d`BF(LB~V@*a=J`j(yM5O8b0xEcCh8QP~(uNo-=v#EZb1GDGRk zPgh=gJy8wYg>D^iM|=Ji!`JD_C%};OkjqYAs8Yl8dZS@&-n*&HOkwM4C>Fp^r|{vL z)TTX~P}F(9-*mO8#bJ~Gr=QPQ94~`t{fseKM^XyE-segQWunTkIXCAb`6k{ltodvLBN17W*aj)f*+P-l9C*Kf4Trat2@LO2wy}L>r@*dQ#R<%Q1qNQD&un- PuPB$K_YPj;Emr;kLG$mv literal 0 HcmV?d00001 diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..acc6a58a0 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,23 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getStatusIcon() { + return (isDone ? "[X]"+ this.description : "[ ]"+ this.description); // mark done task with X + } + + public void markTask() { + this.isDone = true; + } + + public void unmarkTask() { + this.isDone = false; + } + + +} \ No newline at end of file From 521d9445dc25e0afca96290c24d24ad087874543 Mon Sep 17 00:00:00 2001 From: chintaiann Date: Thu, 3 Feb 2022 15:18:47 +0800 Subject: [PATCH 05/12] Level 4 --- src/main/java/Deadline.class | Bin 0 -> 1063 bytes src/main/java/Deadline.java | 17 +++++++++++++++++ src/main/java/Duke.class | Bin 1963 -> 2425 bytes src/main/java/Duke.java | 33 ++++++++++++++++++++++++++++----- src/main/java/Event.class | Bin 0 -> 1061 bytes src/main/java/Event.java | 15 +++++++++++++++ src/main/java/Task.class | Bin 1060 -> 1081 bytes src/main/java/Task.java | 4 ++-- 8 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 src/main/java/Deadline.class create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.class create mode 100644 src/main/java/Event.java diff --git a/src/main/java/Deadline.class b/src/main/java/Deadline.class new file mode 100644 index 0000000000000000000000000000000000000000..043c0d74cb306812a7dd471486a6d0d15310e4c0 GIT binary patch literal 1063 zcma)5T~8B16g{&*ce~wEEJef*1TCc>Nc|R5;)5jwW6_5;Xl!_xZYQvG*=csCB>WTo z1-@#cG3kRpz#nD2yREU>#_)3I&Yg44oqO-hkDvYT0JibegoY^{(-vkBW0-F6pu-T` zc05NtV_3-7PWTxwyWBe}*Ol*hN0q`s90uY#ObZEE491S&ZP)PxgVs7{NRM;klxEgK z3Uegx1UoVWvv*-QZDBrCNwh^^`%YIm(o56j7A#!GBE#Y-?})1OY_8ro>X^JhaZd#d zxk;BB&z%OfCZg=*1H)80x%`o@x6d269?D@9XbwbhP?-6Wcf|yFa|Hjobs}t48ST$dqRL&j?kG_)ut{xhzCC0H?uOn<=-p?~n>&Xr&k79I z3(pgN)#X7T0v(SS*2apSREv%$49owA(nB5;j#c^&8ogM$L---c)5xE}b+R{TSEBtC zt%+jk8(4AUEA-D1e3|TQbfgp9fQdL!ZenFfd>IJ=x#AZjKOjZRr9LviM_2>@3P6tD z#}e>~)HH;eG2(~Ht7LU(^LsjOQJQQ7SVNB14DHtmb|s?;yE zrPXQ+ty2?8T-X&0O^hxsi5ga#7&n@9rEyWWHYB>!rp3;Eu;|9c%>3uf`TftCnH#g; zzur0}UJ{1yv(A6LKJ2F8}6yA|!C!IpvKf2Ek`ZL)B zLQ$$sy^#X-rx9EGMG})jhc5*u?RBMlGg;4Jk05ms-j!q@p9yv*oAw5_bVsptWa$aT zskWTYd>d`*Y@DGJbd!l(4+@nj^(6C5Jra72jp zX8gdxSM5gCyrW5uu}nJ$ebWZ{`q~3YzTt$rW^6QUPN_*_t9+-{#a7L_kl;ry+FXhf zep2US58PqFkXjLvZP~2XzoECw_dVa{SCuvwi&7(IO~Fa>v@3en-C*hYw0dF|mz~kE zXa_Ok401L)(P?{iG!BwcmQ|l8O{&?dPKxcC`Kv?Lj8dVFSVe=ebfZ&UMyHxa0r)6%ww1muCjpZlyZ}gxkVXwSjc@A@sM(!Qo$co z@`4nvsA7`Eyk-f1QzHhoGK)Hy!%~^6zdJ>}RI^-aX^@pP$~u~)jg_)TuO4fqhYg(5 zJ(LmOG)0Zgw>I z>OydLLCD61n=D+_#Z)SFB`#bFg08fGMntP8;^Lm~JLi1oaZfA#x-0m!yY(IzLF4=}V(HRhOC5cD3;hO#7 zo>Mn%(L0t}4p`xiq0*LC?L+T_x@%A99ye0t?02unZhI+hxUcB@@0w|ao~%}v>#GcM zm4r+}tdj0pY+1alpc3?kHc=Zw6mw$RX>jS_I`hKIl6Wd*9TNR!Te^^-X@^bzF>9fh z9*a5NV4tvYCuU+)huSTSn$W!E)QF$Y_=T7=O(sQfHs(l!;u}o56w~F5=#0+3qF(|T z?UwTyE!wFqWP?+9l@ZLnVBCyhu;D0;)#h6<_yeR2qVHUU*}$%A+qa8 zM?Ym)&Q;I&fR{R4o|J0Zb>vAoe-uL$F$1QBI4p+n-atrAEbVj&z>u0I#VF5$g(MaU z=XlSR6b$U0A5K|V@@3*J;n}X!(~goUs&3iBMXWHaba`7;l(e~i?__$a?|9z%7QwzpsJ8tf{_hi+#rzHG@0Y_E7|Wrj+)y%X^1HpQ@IZj38$s zkAi`sKZ7lX%x^(Q4pdu=uXi-)eQs;zo-@3k>~{Ig4WRjS?Zm8XX_5&45y zKktbd@WurGb@NQvx;#0Yu|$P;IyFa&aunM%6x!?;TJ8tsa-pQANi zD1HMgY<-3CIe@Q`T?md0f=6K@MwIJV9}`~&LO{0g1&I$x(sE&lH1HAD$iD=TV+^qh zd?K|Fe9Z{)fdmx>7ziyL7`RDkG67%%Sz6Py-z3=Wz?K4g7x(GJr04@Y!VXq{0cnT^ AtpET3 literal 0 HcmV?d00001 diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..24d8a1109 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,15 @@ + +public class Event extends Task { + + protected String timing; + + public Event(String description, String timing) { + super(description); + this.timing = timing; + } + + @Override + public String toString() { + return "[E]" + (super.isDone ? "[X]" + super.description : "[ ]"+ super.description) + "(" + timing + ")" ; // mark done task with X + } +} \ No newline at end of file diff --git a/src/main/java/Task.class b/src/main/java/Task.class index c7810a541a1cf3eb2d22dd2c83ef2ce6b0d0c718..ff0cca345e4f751389998bef11723fc1679d9dd0 100644 GIT binary patch delta 339 zcmYL@PcH*e6vfY-r`}}r52i64icw1aDJ^PcR|z6k?V>>!Lnb1cA)WamllKKIEG=wx zK_pf-?0gL0K-`%~Y|c6N{?2`Q_xh7=y#EZI0qkNYGCssOwCJmm(Zico*uU~G3HeI& zYMO*hD|9cekKNn0d*1UTX4D>?WXlE?u_RGR!^EP!@? z155yqJZi96hZ8h{B4-KBJdl{?)ocO^>P}d8Tr;>1M-p9 delta 374 zcmYLDO)mpc6g}_Fv~N0QS~{f$twB-aTeobm(1jHXAzh4SVxbvg#@cUa-pWQIk=R&R z*l0o`v9j?G*!vOUzII`A&b{ZHdvc$RJH!0=?Ysh5N3Cssw!dn5`y@>Ek|4Q^>&>%> zp-^qVISzwOV)Jx2INuMBTcJQnZnMK|#l$pb1ZFKbsLBWSUhx_9qk{%Bu%ITd!5FN1 z6onUCtssuWSYTP+a9>|#D9c-3mOtE24S}I3UCp~1rg!qt2~&h=WFU}*LB5L-l_F=8 zm=Tx!C)n4>5s3~4fO}ZIc@TJ{0Eenecf)-crCESGI|5@QmAi)Oo1~!XOZ&Qf(K4<& yGD!n+^hG~;)`}bdu0w7C8azsJOi&N#SB@#VnCs#^7D+Q{U&0F3;Qj#;mo+^A diff --git a/src/main/java/Task.java b/src/main/java/Task.java index acc6a58a0..2db3231aa 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -7,8 +7,8 @@ public Task(String description) { this.isDone = false; } - public String getStatusIcon() { - return (isDone ? "[X]"+ this.description : "[ ]"+ this.description); // mark done task with X + public String toString() { + return "[T]" + (isDone ? "[X]"+ this.description : "[ ]"+ this.description); // mark done task with X } public void markTask() { From c87209c972aafb1e4420fb7d098d6c84211e5c48 Mon Sep 17 00:00:00 2001 From: chintaiann Date: Sat, 5 Feb 2022 14:54:56 +0800 Subject: [PATCH 06/12] branch-Level-5 --- src/main/java/Deadline.class | Bin 1063 -> 863 bytes src/main/java/Deadline.java | 2 +- src/main/java/Duke.class | Bin 2425 -> 3666 bytes src/main/java/Duke.java | 149 +++++++++++++++++++++++------- src/main/java/DukeException.class | Bin 0 -> 1026 bytes src/main/java/DukeException.java | 10 ++ src/main/java/Event.class | Bin 1061 -> 861 bytes src/main/java/Event.java | 2 +- src/main/java/Task.class | Bin 1081 -> 1055 bytes src/main/java/Task.java | 2 +- src/main/java/Todo.class | Bin 0 -> 735 bytes src/main/java/Todo.java | 11 +++ text-ui-test/input.txt | 5 + 13 files changed, 146 insertions(+), 35 deletions(-) create mode 100644 src/main/java/DukeException.class create mode 100644 src/main/java/DukeException.java create mode 100644 src/main/java/Todo.class create mode 100644 src/main/java/Todo.java diff --git a/src/main/java/Deadline.class b/src/main/java/Deadline.class index 043c0d74cb306812a7dd471486a6d0d15310e4c0..c8afc89a325386d719918eb43487b66240efd0d7 100644 GIT binary patch delta 225 zcmXAiJ8r^I6hzN^4z_tBPWXfbFb*-8UlY+&W-lpHq))*fthb0rsVI;lQBYB_2Bho+ zWh{#OnVEZMzT>~poi6(Wux3%ZcjvGq4eq%2UnX}gDXj)=I^|DVUN-({R!Qm@l0`gM z!pH~qXmWqHgPX!o_*Ywm5i>)kHS=#lUVFgM^&dg{`6$1HKs};HjH511Y1M_;sp3s_ ov;5_Dxg*-sgsm7u^&4JQIXnqjdh|78u>;i$VwCV*~_6)s1bjRA9bMC$8eBb$U-Mc*>Kb=Ji69quN|dA&LD@45t(mV0)6`5EtG19-TDNbdd~BTi zOmP1+SL$K*s_7Synt6u&$RlCW{+7ZwQ;7Z>_t{8%NvKcgzk{D?u!9hA59Ln}11#hY zMt}!)N|q$Gy8;APt0eO9M9rN@5@>&_+n0wFw_t8wfNsDS_7B?A|1o?B2WV zy&JMfsUK;wWc8AsGV{&0pFr!y)aKIiVH31sbb zoMvY4IrrT6yzg_K_v5_z&CN?!0IbJ*VJIk5QLdu`l>$|J%~7*CVLC(2-2;2Am@iPd z-ga#N5rMM$hTae~gj9re%z}QKcu&^ztt6$~3^&zu1&VC9d3)M+{2o7TnaMT{bNFdx zslPC)aF>c|9rG|>U|xys0%}SsOE^?gUoa3LrFPpHYHR4#us~pLrQE+iFVpb=mJ8?u1$DhrSHNk% ziiSyp8Q)Gc_YkIIr6tvkI#yt%fMUxtf5>UnNo6KE4Wk~-(t8gI+*4$Qv`-gl=#@gN zb*#Zd0-9ru`CYa{>+|cUAEQX4h8E%)$Xa2n#X1$OI@+-Qc3%gCGc>Gy88hMC;f_M! zv^Df=VAL#Z&sudxr<<}2-!(kTlEfS4kZC(j8a_ijNi#iS?1?u@d+jt58+K3gS5ZqCUD&E(n~rX5pY%WwP*KOX zhO9KPrOdQv@%4@)PU48FctT*wRIo&yxHZsOtBNe(>k6B#0txDw}xjK!M+=JB^LuaVv@eF=bLHY z>$Ck~xoqhe#E?M9%M5r$-__JdOE_Oj+dB5jP*rVjQ!?de!EZ?wEv+78l8!yz&nx6F8gfvw>S431`r z`%5~$ES;;`fnx^c+6$767iAVlOHrWW2z6~N>I&m9UXs|43M?-XSu?{*mZ4(|M{Cq_ zd=+2gbd#KhaU3sc_y$Qy*q*Q9guwlsR+`N5=MVEo+C0N{WQL>-DP*)7)e!iWWam{0 zAX>uS%q0yI0&Q1MzGrlIZ||wAD-=V|O{cRfjDd`AL|Fu#<-RfExciO$vNZbgkz}3o zjMkO)D!xsavXXJ=aN`{2%961ylN_+pJI#TF{E%c0OBze$RzoihAcTR#z4I+d2TGwP05&4qX?gx6*>=DX>vz{%-eEeaNtcA8E+VR=itTz4ds zYMaUPw3XX7?#!mF65`VjKUpMas^~Bii5}axcw7EVpl%yIBrE2y$s7|?F(Ly-h6s!3 zdDd&uBzU<*<;BsFFg?%mRJ<#&Yz7CVj;7**z@m>9WwkHxz)U>Fra}HGj7_!;e4gf8 zEl0tz;!_tO&T%5}9X{n}pd2B57q4*(MJpz_8s`4LoQGOHJCC_?tSOFn7e~2X75@by zUF8?CaBJBkmr=Lt0+zIvugGKRgmUIG>UW(7tu?h)L@M%F)mj;;tbRC;PfuW;)VP5f z%H-ahGR7~D=JD7BIyl=@mdBP>HKLZUZq*{%MLb>}Zwb|eYTtxb6FQAqm$8GUdVbkh z6Iz|e&YZHA(&c&d<&-Aw@Be=_?a7IMOllH;rKZp2VNSq|RBCy|C89irPhplEM<%9l z$kRAHO=In4q;^Hr3rP2Ht+AHqe6Ej|3BJ}|!hV3SIdMc#mAm!l9Og**lhO${`g1q>&M`xLE;I9(0Nr z=Y!}HDPF!=o^+gj(h2m4(|A(6hF)<7ec~dX62C&fc%Pll@3BW*#na+%ct%`9jI5aA z0}O~8h_TcRDPfE#^N>&$A*nRMQCg5v)?uI0jty~q7T@BLD^z?> z#hWVb6Dn&SZeWcH-i&K+VrB4Ytx#{#HR^401rcz|j?l*zypB5RrM6Z7TidJ~{6|1a zUB|+L@S0Cb_&U3)f1^(M7s3j@PX@|ave~ZU2b?R6n=>5eaP~v4|1@}>!_T=E=KDLW IHy084FHQiBhyVZp delta 1250 zcmZ{kOH5p46vuzxJnp>=H()8RYk@*xc*9UA109N`(u!2Dwp1!@wOl#_Ob2EV2Bg05 zfz?{A)vJlDY+T63XiDPHw5BUfj2lhe88^nAiHRE%Z4^D15;w-h{l5P_-}#?&{^xt# zF8L!b@b$)xTfjcvyA~Kwy8@K3%cPPjg*lc=O~vfwust;&Q+R9ZPU=)US5&c9Yf?wO z^NHHo6r|C_Pm`j!cHo@7V29$VP=9h}K0TD4joH&(b;ALIgiKo4?c7mS`E3$w?0hUh zJ7Jv;lTP+Jt)8&za^jxy!fu5zZOn3Foe7C`a4S}TapG={bBda+#{KK<^!csoDTP0_5KE?Yk^&F8 zFu*i%gC|AIRD3RNFy~zG2lu*~=S>#aEg90Oy9x7TTNh2v^R%L9+D^oJQ^~V-+Ept^ zq$ksJ&S(C5ugIqhiexhq!amXj*E_P_d#qZW0_>qh_6kh|lt6XpZDPJC7Y!Q?1%{9xUgdjnIhtW;g;L9JWEhTU z4W&1+Ml5ZelS50(UbRX_oK9~#bqIPQ!)REu{P$!PXc^8%^kq$1eisi%43|7UV(FH# z&g9T0dr>%v|FX6JVNY+dQ!e}PDiNX2Yzl30h0eM{!$L0okey;E(0ro}1)8Wy-{2{b zWvOTN?;lq;zH%Gw*=+PJLeACfilsf|$c4(Kk8KRvgSwX~`R+7hancGXE(_0XaE=~QQAj arrayIndex || indexValue2 < 0){ + throw new IndexOutOfBoundsException(); + } + taskList[indexValue2].markTask(); + } + + catch (IndexOutOfBoundsException e){ + dukeEx.wrongIndex(); + } } - else if (anyString.startsWith("todo")) { - String desc = anyString.substring(5); - taskList[arrayIndex] = new Task(desc); - arrayIndex++; + else if (inputString.matches("unmark \\d+")){ + + try { + String[] arrOfStr = inputString.split(" ", 0); + String indexValue = arrOfStr[1]; + int indexValue2 = Integer.parseInt(indexValue) - 1; + if (indexValue2 > arrayIndex || indexValue2 < 0){ + throw new IndexOutOfBoundsException(); + } + taskList[indexValue2].unmarkTask(); + } + + catch (IndexOutOfBoundsException e){ + dukeEx.wrongIndex(); + } } - else if (anyString.startsWith("deadline")){ - int index = anyString.indexOf("/"); - String desc = anyString.substring(9,index); - index++; - String by = anyString.substring(index); - taskList[arrayIndex] = new Deadline(desc,by); - arrayIndex++; + else if (inputString.startsWith("todo")) { + + try { + String desc = inputString.substring(5); + if (desc.isEmpty() || desc.isBlank()) { + throw new IndexOutOfBoundsException(); + } + System.out.println("Got it. I've added this task:"); + taskList[arrayIndex] = new Todo(desc); + System.out.println(taskList[arrayIndex].toString()); + arrayIndex++; + System.out.println("Now you have " + arrayIndex + " tasks in the list."); + } + + catch (IndexOutOfBoundsException e){ + dukeEx.missingDescription("todo"); + } } - else if (anyString.startsWith("event")){ - int index = anyString.indexOf("/"); - String desc = anyString.substring(6,index); - index++; - String by = anyString.substring(index); - taskList[arrayIndex] = new Event(desc,by); - arrayIndex++; + else if (inputString.startsWith("deadline")){ + + try { + + int index = inputString.indexOf("/"); + String desc = inputString.substring(9,index); + if (desc.isEmpty() || desc.isBlank()) { + throw new IndexOutOfBoundsException(); + } + index++; + String by = inputString.substring(index); + if (by.isEmpty() || by.isBlank()) { + throw new IndexOutOfBoundsException(); + } + taskList[arrayIndex] = new Deadline(desc,by); + System.out.println("Got it. I've added this task:"); + System.out.println(taskList[arrayIndex].toString()); + arrayIndex++; + System.out.println("Now you have " + arrayIndex + " tasks in the list."); + } + + catch (IndexOutOfBoundsException e){ + dukeEx.missingDescription("deadline"); + } + + } + + else if (inputString.startsWith("event")){ + + try { + + int index = inputString.indexOf("/"); + String desc = inputString.substring(6,index); + if (desc.isEmpty() || desc.isBlank()) { + throw new IndexOutOfBoundsException(); + } + index++; + String by = inputString.substring(index); + if (by.isEmpty() || by.isBlank()) { + throw new IndexOutOfBoundsException(); + } + taskList[arrayIndex] = new Event(desc,by); + System.out.println("Got it. I've added this task:"); + System.out.println(taskList[arrayIndex].toString()); + arrayIndex++; + System.out.println("Now you have " + arrayIndex + " tasks in the list."); + } + + catch (IndexOutOfBoundsException e){ + dukeEx.missingDescription("event"); + } + + + + } - else if (anyString.equals("list")){ + else if (inputString.equals("list")){ System.out.println("Here are the tasks in your list : "); for (int i = 0; i> z*>TEfhS^=Em3zrBT_~Q;A&t2JVFovlVOSh`RD0IRHla+{G2{;WFUpjT6Qy0%B~rA@ zSxS2|g9R)yth7Z-R*a5>d#_xRH0y+RmSM9naPAjEo=P{$#p|XJSu6#(ok0%Ee~TYa z$PjdV`k30tO^SM&#vO(iM@PriJU`HNdBGd%TxzZ?r#`s($VHNf9=GbV+~LQu6jpMV z^tfmUrSk#qGR*IFTXKZ3RK?UK!@{A`@?E!GlgWvw#bn90m9^B(p0rV-uILRvB}O;; zxf#N$=_ZlfSAF4LRx?PyX;}GlE2(am?eZsIloQl%trX@=Q z76)wai^!Rz$M9v8kt^UJ=o_Kyv9#-l#^Nf`T_Qp6o&gG{j=8@0hUR6XpsW= z5cA&Nmc7r&7}3VtK0uzwjg$nJy9kz00Uf=k*jCY7~Dpeb-F6=Y#}M1KKW NbPGw_#xs<#`UkhN2;u+$ literal 0 HcmV?d00001 diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java new file mode 100644 index 000000000..6db368cbb --- /dev/null +++ b/src/main/java/DukeException.java @@ -0,0 +1,10 @@ +public class DukeException extends Exception{ + + public void missingDescription(String type){ + System.out.println("OOPS! The description of " + type + " cannot be empty!"); + } + + public void wrongIndex() { + System.out.println("OOPS! Index given is out of array size. Please try again!"); + } +} diff --git a/src/main/java/Event.class b/src/main/java/Event.class index 8bf4fed99ce5fcca12d8702b64d28df7d64645e2..33e375f77ece4ecab3e10d911a9a238b03198f24 100644 GIT binary patch delta 218 zcmW+vxedZV5S+Wi4=3Azd5z6ugLy1L1!Ob>5d|R8gLO3!kq{suIUs_B5|C&G*dy3y zo}E3~Z&N-$#SOp;^IUGE1c&FKf~wlHMEa!o4(e#+rzrm()PpU(NTP?ng@G1^it#&3 z)Qg9ulp$3Mo(c<76^pge1Vc-0MYL;EkOx8Cf&m*6Wzy)4b`U$Ezf60wE8Oe?t3VAn g6T_fy&A;kWLWdAXfG$m&*pMp5h>)ahOi42YKQ&1jjsO4v delta 414 zcmXX=%`O9B6g_uHr`jnsZBai}rK6pqt$&Gyq$EVFDj}LiMop?TQ|UC8wYM9y@&Lk; zgh;xuvhoBrp1{Hzh&yF-&$;)U^L^*jb?f%L|Fm8KtYXFToUC*~K(~Y*_zA9xxn47L z0v$MKSwa93!F#NmrF!MOQK=a+CqokY&~M!j3rfQJh|4kvA(;b%jxa=6z9z-`+OwKb zh2YCKw9?s*cD}0}Rdo^L1pldap{1*uQBLO@^@>rp*C^AS@E{3QM9O((%5KtIc81Vd z*e{YB8HYt3HcJo-8%0V`k|1pvhF;HAHPh5h5exRApwg0kCFEkm+-ii|rnp!KqgPG6 zfYhmHh>yGyBKEfsx*SFH-?+_2VntD(;JZN&LvIT~;11Fs9{`w$Erfvwb_$5_bhT4H pj4>A>1U5y)_{WL1Ar6Hx$onMQrrR^!o>|PX;`Q)(9*bB;_!nHPL?ZwI diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 24d8a1109..34144b831 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -10,6 +10,6 @@ public Event(String description, String timing) { @Override public String toString() { - return "[E]" + (super.isDone ? "[X]" + super.description : "[ ]"+ super.description) + "(" + timing + ")" ; // mark done task with X + return "[E]" + super.toString() + "(" + timing + ")" ; // mark done task with X } } \ No newline at end of file diff --git a/src/main/java/Task.class b/src/main/java/Task.class index ff0cca345e4f751389998bef11723fc1679d9dd0..18ece3055424b3b0f3f5674892a696cec8d559f7 100644 GIT binary patch delta 334 zcmYL@zcR#77{!10CYxjf(x4Rh1Na0KO+`hS79=Qe zK}AJF$=@K}m^RJ3XYPCV&Xf1<`Cq@;2XMq;*Z+1#(A}T5nls0$F}Uor!m7(!K*+l3 zsn2>%QMkTpDvwP|v863bmrbPz&O4pf-O24unzmAxUGtz5wQn+gQJg?AX?!PEk*PV+ z{S?#Ik)KaRm1s42rTj=m#LXCn9>G74LB=>d%ataQS;`Xw%m};a@XTdatoeLlORI8d zOG`=Njq;0-%7ec6P@!F9NUXR|!08hRDKd(~f`qk{FN)gtl5`~b+{kC0ZQ1zZ?y$!J F(H~@*D^LIc diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 2db3231aa..a66a0b33f 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -8,7 +8,7 @@ public Task(String description) { } public String toString() { - return "[T]" + (isDone ? "[X]"+ this.description : "[ ]"+ this.description); // mark done task with X + return (isDone ? "[X]"+ this.description : "[ ]"+ this.description); // mark done task with X } public void markTask() { diff --git a/src/main/java/Todo.class b/src/main/java/Todo.class new file mode 100644 index 0000000000000000000000000000000000000000..f54fa0f471a1c91fa6fa6a0ceb8972dc3ce3b7f4 GIT binary patch literal 735 zcmaJ<%T5A85UfUI0ax*X?>D0Hk?03tJV;_RK|Mh9U_1;kk(G6Z>Yl1ee}27x060WGjTnYJ#C;4SL5Np`X%Z5LfeP#qVS2lCFCN7~ zDAe6S*+zl7E9_jkrlgM)(uAbd9h{Ke-sxvg@;SbbQH&90A4F3YwWn4-HY#MWz_psn3E)w#;b_4aOo3iV=qxwYDtd5=t&%JuP#Lm!Dq3WSD`I6Sn zcB|0up$GZXSb1v60rZ<5{$=%E)@-5omb)X0A`Hucm4zgh`D$(|w?y#Il#)>~6vjy7 zVU4ia=WdW_4>`ih|5V?!|ULl7|3lAe@~ literal 0 HcmV?d00001 diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..fe385149c --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,11 @@ +public class Todo extends Task{ + + public Todo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} \ No newline at end of file diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..0a2ad522f 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,5 @@ +todo borrow book +deadline return book /by Sunday +event project meeting /at Mon 2-4pm + + \ No newline at end of file From 527ea2d333cae4974faf01221da0aadf3bd2350a Mon Sep 17 00:00:00 2001 From: chintaiann Date: Mon, 7 Feb 2022 16:02:44 +0800 Subject: [PATCH 07/12] Level 5 --- src/main/java/{ => duke}/Deadline.class | Bin src/main/java/{ => duke}/Deadline.java | 2 +- src/main/java/{ => duke}/Duke.class | Bin src/main/java/{ => duke}/Duke.java | 4 ++-- src/main/java/{ => duke}/DukeException.class | Bin src/main/java/{ => duke}/DukeException.java | 1 + src/main/java/{ => duke}/Event.class | Bin src/main/java/{ => duke}/Event.java | 2 +- src/main/java/{ => duke}/Task.class | Bin src/main/java/{ => duke}/Task.java | 1 + src/main/java/{ => duke}/Todo.class | Bin src/main/java/{ => duke}/Todo.java | 1 + 12 files changed, 7 insertions(+), 4 deletions(-) rename src/main/java/{ => duke}/Deadline.class (100%) rename src/main/java/{ => duke}/Deadline.java (96%) rename src/main/java/{ => duke}/Duke.class (100%) rename src/main/java/{ => duke}/Duke.java (99%) rename src/main/java/{ => duke}/DukeException.class (100%) rename src/main/java/{ => duke}/DukeException.java (95%) rename src/main/java/{ => duke}/Event.class (100%) rename src/main/java/{ => duke}/Event.java (95%) rename src/main/java/{ => duke}/Task.class (100%) rename src/main/java/{ => duke}/Task.java (97%) rename src/main/java/{ => duke}/Todo.class (100%) rename src/main/java/{ => duke}/Todo.java (93%) diff --git a/src/main/java/Deadline.class b/src/main/java/duke/Deadline.class similarity index 100% rename from src/main/java/Deadline.class rename to src/main/java/duke/Deadline.class diff --git a/src/main/java/Deadline.java b/src/main/java/duke/Deadline.java similarity index 96% rename from src/main/java/Deadline.java rename to src/main/java/duke/Deadline.java index f767cf44e..8c05b1cfe 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/duke/Deadline.java @@ -1,4 +1,4 @@ - +package duke; public class Deadline extends Task { protected String by; diff --git a/src/main/java/Duke.class b/src/main/java/duke/Duke.class similarity index 100% rename from src/main/java/Duke.class rename to src/main/java/duke/Duke.class diff --git a/src/main/java/Duke.java b/src/main/java/duke/Duke.java similarity index 99% rename from src/main/java/Duke.java rename to src/main/java/duke/Duke.java index 9e2c3e20b..552c3678d 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,6 +1,6 @@ -import java.util.Scanner; - +package duke; +import java.util.Scanner; public class Duke { public static void main(String[] args) throws IndexOutOfBoundsException{ System.out.println("---------------------"); diff --git a/src/main/java/DukeException.class b/src/main/java/duke/DukeException.class similarity index 100% rename from src/main/java/DukeException.class rename to src/main/java/duke/DukeException.class diff --git a/src/main/java/DukeException.java b/src/main/java/duke/DukeException.java similarity index 95% rename from src/main/java/DukeException.java rename to src/main/java/duke/DukeException.java index 6db368cbb..9f3a3b60f 100644 --- a/src/main/java/DukeException.java +++ b/src/main/java/duke/DukeException.java @@ -1,3 +1,4 @@ +package duke; public class DukeException extends Exception{ public void missingDescription(String type){ diff --git a/src/main/java/Event.class b/src/main/java/duke/Event.class similarity index 100% rename from src/main/java/Event.class rename to src/main/java/duke/Event.class diff --git a/src/main/java/Event.java b/src/main/java/duke/Event.java similarity index 95% rename from src/main/java/Event.java rename to src/main/java/duke/Event.java index 34144b831..ee3a16cbd 100644 --- a/src/main/java/Event.java +++ b/src/main/java/duke/Event.java @@ -1,4 +1,4 @@ - +package duke; public class Event extends Task { protected String timing; diff --git a/src/main/java/Task.class b/src/main/java/duke/Task.class similarity index 100% rename from src/main/java/Task.class rename to src/main/java/duke/Task.class diff --git a/src/main/java/Task.java b/src/main/java/duke/Task.java similarity index 97% rename from src/main/java/Task.java rename to src/main/java/duke/Task.java index a66a0b33f..59b016784 100644 --- a/src/main/java/Task.java +++ b/src/main/java/duke/Task.java @@ -1,3 +1,4 @@ +package duke; public class Task { protected String description; protected boolean isDone; diff --git a/src/main/java/Todo.class b/src/main/java/duke/Todo.class similarity index 100% rename from src/main/java/Todo.class rename to src/main/java/duke/Todo.class diff --git a/src/main/java/Todo.java b/src/main/java/duke/Todo.java similarity index 93% rename from src/main/java/Todo.java rename to src/main/java/duke/Todo.java index fe385149c..7b18243d9 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/duke/Todo.java @@ -1,3 +1,4 @@ +package duke; public class Todo extends Task{ public Todo(String description) { From 69c93f06a9b09e80e764921cffaf9cca01b35898 Mon Sep 17 00:00:00 2001 From: chintaiann Date: Fri, 11 Feb 2022 20:59:15 +0800 Subject: [PATCH 08/12] Level-6 implemented ArrayList and added delete function for tasks --- src/main/java/duke/Duke.java | 74 +++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 552c3678d..e82a1c820 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,5 +1,5 @@ package duke; - +import java.util.ArrayList; import java.util.Scanner; public class Duke { public static void main(String[] args) throws IndexOutOfBoundsException{ @@ -7,18 +7,46 @@ public static void main(String[] args) throws IndexOutOfBoundsException{ System.out.println(("Hello! I'm Duke")); System.out.println(("What can i do for you?")); System.out.println("---------------------"); - Task[] taskList = new Task[100]; - Boolean continueProgram = true; - int arrayIndex = 0; + // Task[] taskList = new Task[100]; + //using Arraylist instead. + ArrayList taskList = new ArrayList(); + // int arrayIndex = 0; + boolean continueProgram = true; DukeException dukeEx = new DukeException(); while (continueProgram) { Scanner sc = new Scanner(System.in); String inputString = sc.nextLine(); + // terminating sequence if (inputString.equals("bye")) { System.out.println("Bye! Hope to see you again."); continueProgram = false; } + + //deleting task + else if (inputString.matches("delete \\d+")){ + try { + String[] arrOfStr = inputString.split(" ", 0); + String indexValue = arrOfStr[1]; + int indexValue2 = Integer.parseInt(indexValue) - 1; + if (indexValue2 > taskList.size()-1 || indexValue2 < 0){ + throw new IndexOutOfBoundsException(); + } + + Task removedTask = taskList.get(indexValue2); + taskList.remove(indexValue2); + System.out.println("Noted. I've removed this task:"); + System.out.println(removedTask.toString()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); + + } + + catch (IndexOutOfBoundsException e){ + dukeEx.wrongIndex(); + } + } + + //marking a task by index else if (inputString.matches("mark \\d+")){ try { @@ -26,10 +54,11 @@ else if (inputString.matches("mark \\d+")){ String indexValue = arrOfStr[1]; int indexValue2 = Integer.parseInt(indexValue) - 1; //index given is out of array size - if (indexValue2 > arrayIndex || indexValue2 < 0){ + if (indexValue2 > taskList.size()-1 || indexValue2 < 0){ throw new IndexOutOfBoundsException(); } - taskList[indexValue2].markTask(); + // taskList[indexValue2].markTask(); + taskList.get(indexValue2).markTask(); } catch (IndexOutOfBoundsException e){ @@ -37,16 +66,18 @@ else if (inputString.matches("mark \\d+")){ } } + //unmarking a task by index else if (inputString.matches("unmark \\d+")){ try { String[] arrOfStr = inputString.split(" ", 0); String indexValue = arrOfStr[1]; int indexValue2 = Integer.parseInt(indexValue) - 1; - if (indexValue2 > arrayIndex || indexValue2 < 0){ + if (indexValue2 > taskList.size()-1 || indexValue2 < 0){ throw new IndexOutOfBoundsException(); } - taskList[indexValue2].unmarkTask(); + // taskList[indexValue2].unmarkTask(); + taskList.get(indexValue2).unmarkTask(); } catch (IndexOutOfBoundsException e){ @@ -62,10 +93,9 @@ else if (inputString.startsWith("todo")) { throw new IndexOutOfBoundsException(); } System.out.println("Got it. I've added this task:"); - taskList[arrayIndex] = new Todo(desc); - System.out.println(taskList[arrayIndex].toString()); - arrayIndex++; - System.out.println("Now you have " + arrayIndex + " tasks in the list."); + taskList.add(new Todo(desc)); + System.out.println(taskList.get(taskList.size()-1).toString()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); } catch (IndexOutOfBoundsException e){ @@ -87,11 +117,11 @@ else if (inputString.startsWith("deadline")){ if (by.isEmpty() || by.isBlank()) { throw new IndexOutOfBoundsException(); } - taskList[arrayIndex] = new Deadline(desc,by); + // taskList[arrayIndex] = new Deadline(desc,by); + taskList.add(new Deadline(desc,by)); System.out.println("Got it. I've added this task:"); - System.out.println(taskList[arrayIndex].toString()); - arrayIndex++; - System.out.println("Now you have " + arrayIndex + " tasks in the list."); + System.out.println(taskList.get(taskList.size()-1).toString()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); } catch (IndexOutOfBoundsException e){ @@ -114,11 +144,11 @@ else if (inputString.startsWith("event")){ if (by.isEmpty() || by.isBlank()) { throw new IndexOutOfBoundsException(); } - taskList[arrayIndex] = new Event(desc,by); + // taskList[arrayIndex] = new Event(desc,by); + taskList.add(new Event(desc,by)); System.out.println("Got it. I've added this task:"); - System.out.println(taskList[arrayIndex].toString()); - arrayIndex++; - System.out.println("Now you have " + arrayIndex + " tasks in the list."); + System.out.println(taskList.get(taskList.size()-1).toString()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); } catch (IndexOutOfBoundsException e){ @@ -132,8 +162,8 @@ else if (inputString.startsWith("event")){ else if (inputString.equals("list")){ System.out.println("Here are the tasks in your list : "); - for (int i = 0; i Date: Sat, 12 Feb 2022 15:39:08 +0800 Subject: [PATCH 09/12] Level-7 implement fileWriter --- src/main/java/duke/Duke.java | 208 ++++++++++++++++++++++++++++++++++ src/main/java/duke/File.class | 4 + tasks.txt | 4 + 3 files changed, 216 insertions(+) create mode 100644 src/main/java/duke/File.class create mode 100644 tasks.txt diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 552c3678d..91946845a 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,24 +1,125 @@ package duke; import java.util.Scanner; +import java.io.File; +import java.io.IOException; +import java.io.FileWriter; + public class Duke { public static void main(String[] args) throws IndexOutOfBoundsException{ System.out.println("---------------------"); System.out.println(("Hello! I'm Duke")); System.out.println(("What can i do for you?")); System.out.println("---------------------"); +<<<<<<< Updated upstream Task[] taskList = new Task[100]; Boolean continueProgram = true; int arrayIndex = 0; +======= + ArrayList taskList = new ArrayList(); + //file organization + try { + File myTasks = new File("tasks.txt"); + if (myTasks.createNewFile()){ + System.out.println("File is created!"); + }else{ + System.out.println("File exists, reading it to taskList!"); + Scanner s = new Scanner(myTasks); // create a Scanner using the File as the source + while (s.hasNext()){ + String nextString = s.nextLine(); + String[] splitString = nextString.split("\\|"); + String typeTask = splitString[0].replaceAll(" ",""); + String marked = splitString[1].replaceAll(" ",""); + String desc = splitString[2]; + System.out.println(typeTask); + System.out.println(marked); + System.out.println(desc); + String todo = "T"; + String deadline = "D"; + String event = "E"; + String toMark = "1"; + if (typeTask.equals(todo)) { + taskList.add(new Todo(desc)); + if (marked.equals(toMark)) { + taskList.get(taskList.size()-1).markTask(); + } + } + + else if (typeTask.equals(deadline)) { + String deadlineDate = splitString[3]; + taskList.add(new Deadline(desc,deadlineDate)); + if (marked.equals(toMark)) { + taskList.get(taskList.size()-1).markTask(); + } + } + + else if (typeTask.equals(event)) { + String eventDate = splitString[3]; + taskList.add(new Event(desc,eventDate)); + if (marked.equals(toMark)) { + taskList.get(taskList.size()-1).markTask(); + } + } + } + s.close(); + } + + } catch (IOException e) { + e.printStackTrace(); + } + + + + + // Task[] taskList = new Task[100]; + //using Arraylist instead. + // int arrayIndex = 0; + String filePath = "tasks.txt"; + boolean continueProgram = true; +>>>>>>> Stashed changes DukeException dukeEx = new DukeException(); while (continueProgram) { Scanner sc = new Scanner(System.in); String inputString = sc.nextLine(); +<<<<<<< Updated upstream +======= + updateFile(filePath,taskList); + // terminating sequence +>>>>>>> Stashed changes if (inputString.equals("bye")) { System.out.println("Bye! Hope to see you again."); continueProgram = false; } +<<<<<<< Updated upstream +======= + + //deleting task + else if (inputString.matches("delete \\d+")){ + try { + String[] arrOfStr = inputString.split(" ", 0); + String indexValue = arrOfStr[1]; + int indexValue2 = Integer.parseInt(indexValue) - 1; + if (indexValue2 > taskList.size()-1 || indexValue2 < 0){ + throw new IndexOutOfBoundsException(); + } + + Task removedTask = taskList.get(indexValue2); + taskList.remove(indexValue2); + System.out.println("Noted. I've removed this task:"); + System.out.println(removedTask.toString()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); + updateFile(filePath,taskList); + + } + + catch (IndexOutOfBoundsException e){ + dukeEx.wrongIndex(); + } + } + + //marking a task by index +>>>>>>> Stashed changes else if (inputString.matches("mark \\d+")){ try { @@ -29,7 +130,13 @@ else if (inputString.matches("mark \\d+")){ if (indexValue2 > arrayIndex || indexValue2 < 0){ throw new IndexOutOfBoundsException(); } +<<<<<<< Updated upstream taskList[indexValue2].markTask(); +======= + // taskList[indexValue2].markTask(); + taskList.get(indexValue2).markTask(); + updateFile(filePath,taskList); +>>>>>>> Stashed changes } catch (IndexOutOfBoundsException e){ @@ -46,7 +153,13 @@ else if (inputString.matches("unmark \\d+")){ if (indexValue2 > arrayIndex || indexValue2 < 0){ throw new IndexOutOfBoundsException(); } +<<<<<<< Updated upstream taskList[indexValue2].unmarkTask(); +======= + // taskList[indexValue2].unmarkTask(); + taskList.get(indexValue2).unmarkTask(); + updateFile(filePath,taskList); +>>>>>>> Stashed changes } catch (IndexOutOfBoundsException e){ @@ -62,10 +175,23 @@ else if (inputString.startsWith("todo")) { throw new IndexOutOfBoundsException(); } System.out.println("Got it. I've added this task:"); +<<<<<<< Updated upstream taskList[arrayIndex] = new Todo(desc); System.out.println(taskList[arrayIndex].toString()); arrayIndex++; System.out.println("Now you have " + arrayIndex + " tasks in the list."); +======= + taskList.add(new Todo(desc)); + System.out.println(taskList.get(taskList.size()-1).toString()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); + String textToAdd = "T" + "|" + " 0 " + "|" + desc; + try { + appendData(filePath,textToAdd); + } + catch (IOException e) { + System.out.println("Failed to write event data to text file."); + } +>>>>>>> Stashed changes } catch (IndexOutOfBoundsException e){ @@ -89,9 +215,21 @@ else if (inputString.startsWith("deadline")){ } taskList[arrayIndex] = new Deadline(desc,by); System.out.println("Got it. I've added this task:"); +<<<<<<< Updated upstream System.out.println(taskList[arrayIndex].toString()); arrayIndex++; System.out.println("Now you have " + arrayIndex + " tasks in the list."); +======= + System.out.println(taskList.get(taskList.size()-1).toString()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); + String textToAdd = "D" + "|" + " 0 " + "|" + desc + "|" + by; + try { + appendData(filePath,textToAdd); + } + catch (IOException e) { + System.out.println("Failed to write deadline data to text file."); + } +>>>>>>> Stashed changes } catch (IndexOutOfBoundsException e){ @@ -116,9 +254,23 @@ else if (inputString.startsWith("event")){ } taskList[arrayIndex] = new Event(desc,by); System.out.println("Got it. I've added this task:"); +<<<<<<< Updated upstream System.out.println(taskList[arrayIndex].toString()); arrayIndex++; System.out.println("Now you have " + arrayIndex + " tasks in the list."); +======= + System.out.println(taskList.get(taskList.size()-1).toString()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); + + String textToAdd = "E" + "|" + " 0 " + "|" + desc + "|" + by; + try { + appendData(filePath,textToAdd); + } + catch (IOException e) { + System.out.println("Failed to write event data to text file."); + } + +>>>>>>> Stashed changes } catch (IndexOutOfBoundsException e){ @@ -150,4 +302,60 @@ else if (inputString.equals("list")){ } + public static void appendData(String filePath, String textToAppend) throws IOException { + FileWriter fw = new FileWriter(filePath,true); + fw.write(System.getProperty( "line.separator" )); + fw.write(textToAppend); + fw.close(); + } + + public static void writeToFile(String filePath, String textToAdd) throws IOException { + FileWriter fw = new FileWriter(filePath); + fw.write(textToAdd); + fw.close(); + } + + public static void updateFile(String filePath, ArrayList taskList) { + for (int i = 0; i Date: Thu, 24 Feb 2022 21:22:14 +0800 Subject: [PATCH 10/12] Level-9 implement OOP + find function --- src/main/java/META-INF/MANIFEST.MF | 3 + src/main/java/duke/Duke.java | 341 ++---------------- src/main/java/duke/DukeException.java | 8 +- src/main/java/duke/Parser.java | 129 +++++++ src/main/java/duke/Storage.java | 145 ++++++++ src/main/java/duke/Ui.java | 59 +++ .../java/duke/{ => tasklist}/Deadline.class | Bin .../java/duke/{ => tasklist}/Deadline.java | 3 +- src/main/java/duke/{ => tasklist}/Event.class | Bin src/main/java/duke/{ => tasklist}/Event.java | 3 +- src/main/java/duke/{ => tasklist}/Task.class | Bin src/main/java/duke/{ => tasklist}/Task.java | 6 +- src/main/java/duke/tasklist/TaskList.java | 97 +++++ src/main/java/duke/{ => tasklist}/Todo.class | Bin src/main/java/duke/{ => tasklist}/Todo.java | 3 +- tasks.txt | 6 +- 16 files changed, 476 insertions(+), 327 deletions(-) create mode 100644 src/main/java/META-INF/MANIFEST.MF create mode 100644 src/main/java/duke/Parser.java create mode 100644 src/main/java/duke/Storage.java create mode 100644 src/main/java/duke/Ui.java rename src/main/java/duke/{ => tasklist}/Deadline.class (100%) rename src/main/java/duke/{ => tasklist}/Deadline.java (93%) rename src/main/java/duke/{ => tasklist}/Event.class (100%) rename src/main/java/duke/{ => tasklist}/Event.java (93%) rename src/main/java/duke/{ => tasklist}/Task.class (100%) rename src/main/java/duke/{ => tasklist}/Task.java (82%) create mode 100644 src/main/java/duke/tasklist/TaskList.java rename src/main/java/duke/{ => tasklist}/Todo.class (100%) rename src/main/java/duke/{ => tasklist}/Todo.java (89%) diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..6e864153e --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: duke.Duke + diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index d8c74e1af..7850cd6a5 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,329 +1,42 @@ package duke; -import java.util.ArrayList; -import java.util.Scanner; -import java.io.File; -import java.io.IOException; -import java.io.FileWriter; +import duke.tasklist.*; public class Duke { - public static void main(String[] args) throws IndexOutOfBoundsException{ - System.out.println("---------------------"); - System.out.println(("Hello! I'm Duke")); - System.out.println(("What can i do for you?")); - System.out.println("---------------------"); - ArrayList taskList = new ArrayList(); - //file organization - try { - File myTasks = new File("tasks.txt"); - if (myTasks.createNewFile()){ - System.out.println("File is created!"); - }else{ - System.out.println("File exists, reading it to taskList!"); - Scanner s = new Scanner(myTasks); // create a Scanner using the File as the source - while (s.hasNext()){ - String nextString = s.nextLine(); - String[] splitString = nextString.split("\\|"); - String typeTask = splitString[0].replaceAll(" ",""); - String marked = splitString[1].replaceAll(" ",""); - String desc = splitString[2]; - System.out.println(typeTask); - System.out.println(marked); - System.out.println(desc); - String todo = "T"; - String deadline = "D"; - String event = "E"; - String toMark = "1"; - if (typeTask.equals(todo)) { - taskList.add(new Todo(desc)); - if (marked.equals(toMark)) { - taskList.get(taskList.size()-1).markTask(); - } - } - - else if (typeTask.equals(deadline)) { - String deadlineDate = splitString[3]; - taskList.add(new Deadline(desc,deadlineDate)); - if (marked.equals(toMark)) { - taskList.get(taskList.size()-1).markTask(); - } - } - - else if (typeTask.equals(event)) { - String eventDate = splitString[3]; - taskList.add(new Event(desc,eventDate)); - if (marked.equals(toMark)) { - taskList.get(taskList.size()-1).markTask(); - } - } - } - s.close(); - } - - } catch (IOException e) { - e.printStackTrace(); - } - - String filePath = "tasks.txt"; - boolean continueProgram = true; - - //using Arraylist instead. - boolean continueProgram = true; - - DukeException dukeEx = new DukeException(); - while (continueProgram) { - Scanner sc = new Scanner(System.in); - String inputString = sc.nextLine(); - if (inputString.equals("bye")) { - System.out.println("Bye! Hope to see you again."); - continueProgram = false; - } - - - //deleting task - else if (inputString.matches("delete \\d+")){ - try { - String[] arrOfStr = inputString.split(" ", 0); - String indexValue = arrOfStr[1]; - int indexValue2 = Integer.parseInt(indexValue) - 1; - if (indexValue2 > taskList.size()-1 || indexValue2 < 0){ - throw new IndexOutOfBoundsException(); - } - - Task removedTask = taskList.get(indexValue2); - taskList.remove(indexValue2); - System.out.println("Noted. I've removed this task:"); - System.out.println(removedTask.toString()); - System.out.println("Now you have " + taskList.size() + " tasks in the list."); - - updateFile(filePath,taskList); - - - } - - catch (IndexOutOfBoundsException e){ - dukeEx.wrongIndex(); - } - } - - //marking a task by index - else if (inputString.matches("mark \\d+")){ + private Storage storage; + private TaskList tasks; + private Ui ui; - try { - String[] arrOfStr = inputString.split(" ", 0); - String indexValue = arrOfStr[1]; - int indexValue2 = Integer.parseInt(indexValue) - 1; - //index given is out of array size - if (indexValue2 > taskList.size()-1 || indexValue2 < 0){ - throw new IndexOutOfBoundsException(); - } - - - taskList.get(indexValue2).markTask(); - updateFile(filePath,taskList); - } - - catch (IndexOutOfBoundsException e){ - dukeEx.wrongIndex(); - } - } - - //unmarking a task by index - else if (inputString.matches("unmark \\d+")){ - - try { - String[] arrOfStr = inputString.split(" ", 0); - String indexValue = arrOfStr[1]; - int indexValue2 = Integer.parseInt(indexValue) - 1; - if (indexValue2 > taskList.size()-1 || indexValue2 < 0){ - throw new IndexOutOfBoundsException(); - } - taskList.get(indexValue2).unmarkTask(); - updateFile(filePath,taskList); - - } - - catch (IndexOutOfBoundsException e){ - dukeEx.wrongIndex(); - } - } - - else if (inputString.startsWith("todo")) { - - try { - String desc = inputString.substring(5); - if (desc.isEmpty() || desc.isBlank()) { - throw new IndexOutOfBoundsException(); - } - System.out.println("Got it. I've added this task:"); - - - taskList.add(new Todo(desc)); - System.out.println(taskList.get(taskList.size()-1).toString()); - System.out.println("Now you have " + taskList.size() + " tasks in the list."); - String textToAdd = "T" + "|" + " 0 " + "|" + desc; - try { - appendData(filePath,textToAdd); - } - catch (IOException e) { - System.out.println("Failed to write event data to text file."); - } - - } - - catch (IndexOutOfBoundsException e){ - dukeEx.missingDescription("todo"); - } - } - - else if (inputString.startsWith("deadline")){ - - try { - - int index = inputString.indexOf("/"); - String desc = inputString.substring(9,index); - if (desc.isEmpty() || desc.isBlank()) { - throw new IndexOutOfBoundsException(); - } - index++; - String by = inputString.substring(index); - if (by.isEmpty() || by.isBlank()) { - throw new IndexOutOfBoundsException(); - } - // taskList[arrayIndex] = new Deadline(desc,by); - taskList.add(new Deadline(desc,by)); - System.out.println("Got it. I've added this task:"); - - System.out.println(taskList.get(taskList.size()-1).toString()); - System.out.println("Now you have " + taskList.size() + " tasks in the list."); - String textToAdd = "D" + "|" + " 0 " + "|" + desc + "|" + by; - try { - appendData(filePath,textToAdd); - } - catch (IOException e) { - System.out.println("Failed to write deadline data to text file."); - } - - } - - catch (IndexOutOfBoundsException e){ - dukeEx.missingDescription("deadline"); - } - - } - - else if (inputString.startsWith("event")){ - - try { - - int index = inputString.indexOf("/"); - String desc = inputString.substring(6,index); - if (desc.isEmpty() || desc.isBlank()) { - throw new IndexOutOfBoundsException(); - } - index++; - String by = inputString.substring(index); - if (by.isEmpty() || by.isBlank()) { - throw new IndexOutOfBoundsException(); - } - // taskList[arrayIndex] = new Event(desc,by); - taskList.add(new Event(desc,by)); - System.out.println("Got it. I've added this task:"); - System.out.println(taskList.get(taskList.size()-1).toString()); - System.out.println("Now you have " + taskList.size() + " tasks in the list."); - - String textToAdd = "E" + "|" + " 0 " + "|" + desc + "|" + by; - try { - appendData(filePath,textToAdd); - } - catch (IOException e) { - System.out.println("Failed to write event data to text file."); - } - } - - catch (IndexOutOfBoundsException e){ - dukeEx.missingDescription("event"); - } - - - - - } - - else if (inputString.equals("list")){ - System.out.println("Here are the tasks in your list : "); - for (int i = 0; i taskList) { - for (int i = 0; i l.getTaskSize()-1 || indexValue2 < 0){ + throw new DukeException("Index given is out of bounds."); + } + ArrayList taskList = l.markTask(indexValue2); + s.updateFile(taskList); + return 1; + + case "unmark": + arrOfStr = userInput.split(" ", 0); + indexValue = arrOfStr[1]; + indexValue2 = Integer.parseInt(indexValue) - 1; + //index given is out of array size + if (indexValue2 > l.getTaskSize()-1 || indexValue2 < 0){ + throw new DukeException("Index given is out of bounds."); + } + taskList = l.unmarkTask(indexValue2); + s.updateFile(taskList); + return 1; + + case "delete": + arrOfStr = userInput.split(" ", 0); + indexValue = arrOfStr[1]; + indexValue2 = Integer.parseInt(indexValue) - 1; + //index given is out of array size + if (indexValue2 > l.getTaskSize()-1 || indexValue2 < 0){ + throw new DukeException("Index given is out of bounds."); + } + taskList = l.deleteTask(indexValue2); + s.updateFile(taskList); + return 1; + + case "list": + l.printList(); + return 1; + + + + case "bye": + return 0; + + default: + throw new DukeException("Oops! I do not recognize this command. Please try again."); + } + } +} diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java new file mode 100644 index 000000000..bd9c084cd --- /dev/null +++ b/src/main/java/duke/Storage.java @@ -0,0 +1,145 @@ +package duke; + +import duke.tasklist.Task; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; +import duke.tasklist.*; + +/** + * Storage class is used to load tasks from the file and saving them to taskList + * We also have different functions which we will use in our commands to update the text file as we update the taskList. + */ +public class Storage { + private String filePath; + private File file; + private Scanner input; + + public Storage(String filePath) { + try { + this.filePath = filePath; + this.file = new File(filePath); + input = new Scanner(file); + } catch (FileNotFoundException e) { + createFileAndDirectory(); + } + } + + public String getFilePath() { + return this.filePath; + } + + + public void createFileAndDirectory() { + try { + file.createNewFile(); + throw new IOException(); + } catch (IOException e) { + System.out.println("Error creating file."); + } + } + + public ArrayList loadTaskList() throws DukeException { + ArrayList taskList = new ArrayList<>(); + if (!file.exists() || !file.isFile()) { + return taskList; + } + + while (input.hasNext()){ + String nextString = input.nextLine(); + String[] splitString = nextString.split("\\|"); + String typeTask = splitString[0].replaceAll(" ",""); + String marked = splitString[1].replaceAll(" ",""); + String desc = splitString[2]; + System.out.println(typeTask); + System.out.println(marked); + System.out.println(desc); + String todo = "T"; + String deadline = "D"; + String event = "E"; + String toMark = "1"; + if (typeTask.equals(todo)) { + taskList.add(new Todo(desc)); + if (marked.equals(toMark)) { + taskList.get(taskList.size()-1).markTask(); + } + } + + else if (typeTask.equals(deadline)) { + String deadlineDate = splitString[3]; + taskList.add(new Deadline(desc,deadlineDate)); + if (marked.equals(toMark)) { + taskList.get(taskList.size()-1).markTask(); + } + } + + else if (typeTask.equals(event)) { + String eventDate = splitString[3]; + taskList.add(new Event(desc,eventDate)); + if (marked.equals(toMark)) { + taskList.get(taskList.size()-1).markTask(); + } + } + } + return taskList; + } + + public void appendData(String textToAppend) throws IOException { + String filePath = this.filePath; + FileWriter fw = new FileWriter(filePath,true); + fw.write(System.getProperty( "line.separator" )); + fw.write(textToAppend); + fw.close(); + } + + public void writeToFile(String textToAdd) throws IOException { + filePath = this.filePath; + FileWriter fw = new FileWriter(filePath); + fw.write(textToAdd); + fw.close(); + } + + public void updateFile(ArrayList taskList) { + for (int i = 0; i taskList; + + + public TaskList(ArrayList a) { + this.taskList = a; + } + + public TaskList() { + this.taskList = new ArrayList(); + } + + public int getTaskSize() { + return this.taskList.size(); + } + + public void printList() { + System.out.println("Here are the tasks in your list : "); + for (int i = 0; i deleteTask(int indexValue2) { + + Task removedTask = taskList.get(indexValue2); + taskList.remove(indexValue2); + System.out.println("Noted. I've removed this task:"); + System.out.println(removedTask.toString()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); + return this.taskList; + } + + public String addTodo(String desc) { + + System.out.println("Got it. I've added this task:"); + taskList.add(new Todo(desc)); + System.out.println(taskList.get(taskList.size()-1).toString()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); + String textToAdd = "T" + "|" + " 0 " + "|" + desc; + // return this string so Storage can use to add to text file + return textToAdd; + + } + + public String addDeadline(String desc, String by) { + taskList.add(new Deadline(desc, by)); + System.out.println("Got it. I've added this task:"); + System.out.println(taskList.get(taskList.size() - 1).toString()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); + String textToAdd = "D" + "|" + " 0 " + "|" + desc + "|" + by; + return textToAdd; + + } + + public String addEvent(String desc, String by) { + + taskList.add(new Event(desc,by)); + System.out.println("Got it. I've added this task:"); + System.out.println(taskList.get(taskList.size()-1).toString()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); + + String textToAdd = "E" + "|" + " 0 " + "|" + desc + "|" + by; + return textToAdd; + } + + public ArrayList markTask(int indexValue2) { + taskList.get(indexValue2).markTask(); + return(this.taskList); + } + + public ArrayList unmarkTask(int indexValue2) { + taskList.get(indexValue2).unmarkTask(); + return(this.taskList); + } + + public void find(String keyword){ + System.out.println("Here are the matching tasks in your list: "); + for (int i = 0; i Date: Thu, 24 Feb 2022 21:45:41 +0800 Subject: [PATCH 11/12] Update README.md --- docs/README.md | 160 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 153 insertions(+), 7 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..b8e70f33e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,28 +2,174 @@ ## Features -### Feature-ABC +### Feature - Adding of Task - Todo, Event, Deadline -Description of the feature. +You can now add a task of any one of the three types. -### Feature-XYZ -Description of the feature. +### Feature - Deletion of Task + +Delete any task according to its index in the list of tasks. + +### Feature - Unmark/mark any task. + +Mark or unmark any task in the list of task. + +### Feature - List all tasks. + +List all the current tasks in the list. + +### Feature - Find a task, given a specific search word. + +Enter a word and search for all tasks that contain this word. ## Usage -### `Keyword` - Describe action +### `todo` - Describe action + +Describe the action and its outcome. + +Example of usage: + +`todo enter description here` + +Expected outcome: + +Description of the outcome. + +``` +Got it. I've added this task: +[T][ ]enter description here +Now you have 1 tasks in the list. +``` + +### `deadline` - Describe action Describe the action and its outcome. Example of usage: -`keyword (optional arguments)` +`deadline ip assignment /by today 2359` Expected outcome: Description of the outcome. ``` -expected output +Got it. I've added this task: +[D][ ]ip assignment (by today 2359) +Now you have 1 tasks in the list. ``` + +### `event` - Describe action + +Describe the action and its outcome. + +Example of usage: + +`event final exam /at 29 February 9pm` + +Expected outcome: + +Description of the outcome. + +``` +Got it. I've added this task: +[E][ ]final exam (at 29 February 9pm) +Now you have 3 tasks in the list. +``` + + +### `find` - Describe action + +Describe the action and its outcome. + +Example of usage: + +`find final` + +Expected outcome: + +Description of the outcome. + +``` +Here are the matching tasks in your list: +3.[E][ ]final exam (at 29 February 9pm) +``` + +### `mark` - Describe action + +Describe the action and its outcome. + +Example of usage: + +`mark 3` + +Expected outcome: + +Description of the outcome. + +``` +[T][ ]enter description here +[D][ ]ip assignment (by today 2359) +[E][X]final exam (at 29 February 9pm) +``` + +### `unmark` - Describe action + +Describe the action and its outcome. + +Example of usage: + +`unmark 3` + +Expected outcome: + +Description of the outcome. + +``` +[T][ ]enter description here +[D][ ]ip assignment (by today 2359) +[E][ ]final exam (at 29 February 9pm) +``` + +### `list` - Describe action + +Describe the action and its outcome. + +Example of usage: + +`list` + +Expected outcome: + +Description of the outcome. + +``` +Here are the tasks in your list : +1.[T][ ]enter description here +2.[D][ ]ip assignment (by today 2359) +3.[E][ ]final exam (at 29 February 9pm) +``` + +### `delete` - Describe action + +Describe the action and its outcome. + +Example of usage: + +`delete 2` + +Expected outcome: + +Description of the outcome. + +``` +Noted. I've removed this task: +[D][ ]ip assignment (by today 2359) +Now you have 2 tasks in the list. +[T][ ]enter description here +[E][ ]final exam (at 29 February 9pm) + +``` + From 43b0166ee9e2967bba7abe65b499fe60d9eac239 Mon Sep 17 00:00:00 2001 From: chintaiann Date: Thu, 24 Feb 2022 22:51:58 +0800 Subject: [PATCH 12/12] v0.2 Final changes before release --- src/main/java/duke/Parser.java | 25 +++++++++++++++++------ src/main/java/duke/Storage.java | 36 +++++++++++++++++++++++++++++++++ src/main/java/duke/Ui.java | 21 +++++++++++++------ tasks.txt | 3 +-- 4 files changed, 71 insertions(+), 14 deletions(-) diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 32af4fcd9..06eabcf30 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -7,7 +7,6 @@ /** * Parser helps to make sense of the user input and uses methods from TaskList to do operations on the ArrayList of tasks. - */ public class Parser { public static int parse(String userInput, TaskList l,Storage s) throws DukeException { @@ -28,7 +27,12 @@ public static int parse(String userInput, TaskList l,Storage s) throws DukeExcep } desc = l.addTodo(desc); try { - s.appendData(desc); + if (l.getTaskSize() == 1) { + s.writeToFile(desc); + } + else { + s.appendData(desc); + } } catch (IOException e) { System.out.println("Error while appending to text file."); } @@ -49,7 +53,13 @@ public static int parse(String userInput, TaskList l,Storage s) throws DukeExcep } desc = l.addEvent(desc,by); try { - s.appendData(desc); + if (l.getTaskSize() == 1) { + s.writeToFile(desc); + } + else { + s.appendData(desc); + } + } catch (IOException e) { System.out.println("Error while appending to text file."); } @@ -69,7 +79,12 @@ public static int parse(String userInput, TaskList l,Storage s) throws DukeExcep } desc = l.addDeadline(desc,by); try { - s.appendData(desc); + if (l.getTaskSize() == 1) { + s.writeToFile(desc); + } + else { + s.appendData(desc); + } } catch (IOException e) { System.out.println("Error while appending to text file."); } @@ -117,8 +132,6 @@ public static int parse(String userInput, TaskList l,Storage s) throws DukeExcep l.printList(); return 1; - - case "bye": return 0; diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index bd9c084cd..0e9ef5e17 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -19,13 +19,25 @@ public class Storage { private File file; private Scanner input; + + /** + * reads in the link to our text file and saves it to variable input + * if text file does not exist, we create a new file + * @param filePath + */ public Storage(String filePath) { try { this.filePath = filePath; this.file = new File(filePath); + if (this.file.createNewFile()) { + System.out.println("File is created!"); + }else{ + System.out.println("File exists, reading it to taskList!"); } input = new Scanner(file); } catch (FileNotFoundException e) { createFileAndDirectory(); + } catch (IOException e) { + e.printStackTrace(); } } @@ -43,6 +55,12 @@ public void createFileAndDirectory() { } } + /** + * function reads in our text file and saves it to an ArrayList of tasks. + * + * @return + * @throws DukeException + */ public ArrayList loadTaskList() throws DukeException { ArrayList taskList = new ArrayList<>(); if (!file.exists() || !file.isFile()) { @@ -85,9 +103,16 @@ else if (typeTask.equals(event)) { } } } + input.close(); return taskList; } + /** + * Function to append one line of data to our text file + * For adding of tasks + * @param textToAppend + * @throws IOException + */ public void appendData(String textToAppend) throws IOException { String filePath = this.filePath; FileWriter fw = new FileWriter(filePath,true); @@ -96,6 +121,12 @@ public void appendData(String textToAppend) throws IOException { fw.close(); } + /** + * Function to write the first line to a text file. + * @param textToAdd + * @throws IOException + */ + public void writeToFile(String textToAdd) throws IOException { filePath = this.filePath; FileWriter fw = new FileWriter(filePath); @@ -103,6 +134,11 @@ public void writeToFile(String textToAdd) throws IOException { fw.close(); } + /** + * Function to completely erase text file and update it according to our ArrayList. + * Used when we delete tasks, mark/unmark tasks + * @param taskList + */ public void updateFile(ArrayList taskList) { for (int i = 0; i