From 0f0c35ed0b3e800b0b98ed90c898ab15aa3a9b13 Mon Sep 17 00:00:00 2001 From: Hauser Date: Wed, 9 Jan 2019 18:06:24 -0600 Subject: [PATCH 01/16] submit calculator --- Calculator/.classpath | 6 +++ Calculator/.project | 17 +++++++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++++ Calculator/bin/Calc/Calculator.class | Bin 0 -> 1790 bytes Calculator/src/Calc/Calculator.java | 48 ++++++++++++++++++ 5 files changed, 82 insertions(+) create mode 100644 Calculator/.classpath create mode 100644 Calculator/.project create mode 100644 Calculator/.settings/org.eclipse.jdt.core.prefs create mode 100644 Calculator/bin/Calc/Calculator.class create mode 100644 Calculator/src/Calc/Calculator.java diff --git a/Calculator/.classpath b/Calculator/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/Calculator/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Calculator/.project b/Calculator/.project new file mode 100644 index 0000000..afb56be --- /dev/null +++ b/Calculator/.project @@ -0,0 +1,17 @@ + + + Calculator + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Calculator/.settings/org.eclipse.jdt.core.prefs b/Calculator/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/Calculator/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Calculator/bin/Calc/Calculator.class b/Calculator/bin/Calc/Calculator.class new file mode 100644 index 0000000000000000000000000000000000000000..c1aed98ab764386d1465622dd5b9027895dbae21 GIT binary patch literal 1790 zcma)5U31$+6g?Y%NH&6|cAbPc32p<_ZrYfSVjyk;Z9=K3+lIOrLMT+WmQ+QSj4XA? z13!ToUic00zzcmyI&_8~z>i`$D>DSdSbj-l>HKYY5AD9o#x?{RK^;^9MvL6U!FWIggtO=y5wXQ&V-LqsKDdY@fkR?vr zcIC}*(3Achv*$>GLfh+`PS^BpwI4gv!F_uqaI*c(wM{|}OxqQhs&2OrukQrD?d~*d z-5gG$sG)F#TxWL_$bo@VD3O>Kl4mJSw!Qi$GXv&JbI{Z=Eik+3NOL4B(ha0v`PTMF zLB)+2FX!Ycvny3$w7Pa8Oc zMS%%b;UUGAI}8sf=COd+l$fsz%#86#PYhXy6^y0-3(!jo1_d z?;3ay?-Sp&EIY707M-cKTD6usY#O)}9gf0Y;G6wGIoAw)5IF~-6WBv%S2-^mxDq+P z552(VvuW56n0~f9u7tK@NngiRUUS*9Rw{X{jf zC{2}d)4;7r;=qd=P{*eN`OcW|N<~M9`x|4fYX2Fl-LN0pmRzZ@mrZ|%ZC-p%E0YIX zl6-j_KibpH!a2~R&g3Wwh?YPu7ChRgs3#kp!l`lL?Ge~0GV&cS^!xIvt!6Kp>Uf}+ zm0UPYIa3^aAWMrA%fH55ovYxQIkyk}4;mB5kAr|TUZ8En0bF0?E{B(JB2E^YjL_-( z?GYvmQ+t?sf`zR|sO;m__R=2CKE~3jI(m~w`qtQsKWu=i(%W5O5mJb^m zmqfLasArh9cx+ToY!dZ;67?)mtH(y=$R|;q RB Date: Wed, 9 Jan 2019 18:09:16 -0600 Subject: [PATCH 02/16] add fibonacci --- FibonacciSeq/.classpath | 6 ++++++ FibonacciSeq/.project | 17 +++++++++++++++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++++++++++ .../bin/FibonacciSeq/FibonacciSeq.class | Bin 0 -> 722 bytes .../src/FibonacciSeq/FibonacciSeq.java | 20 ++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 FibonacciSeq/.classpath create mode 100644 FibonacciSeq/.project create mode 100644 FibonacciSeq/.settings/org.eclipse.jdt.core.prefs create mode 100644 FibonacciSeq/bin/FibonacciSeq/FibonacciSeq.class create mode 100644 FibonacciSeq/src/FibonacciSeq/FibonacciSeq.java diff --git a/FibonacciSeq/.classpath b/FibonacciSeq/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/FibonacciSeq/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/FibonacciSeq/.project b/FibonacciSeq/.project new file mode 100644 index 0000000..b8d0818 --- /dev/null +++ b/FibonacciSeq/.project @@ -0,0 +1,17 @@ + + + FibonacciSeq + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/FibonacciSeq/.settings/org.eclipse.jdt.core.prefs b/FibonacciSeq/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/FibonacciSeq/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/FibonacciSeq/bin/FibonacciSeq/FibonacciSeq.class b/FibonacciSeq/bin/FibonacciSeq/FibonacciSeq.class new file mode 100644 index 0000000000000000000000000000000000000000..7a6d3c4a851a1fb611fb3cdd7bec1400378737d5 GIT binary patch literal 722 zcmZuvO^?!06g>}G3T>HTz(J>|K@4N4wbMAS!{r&gnF946wc2E#FIMz{`$T-#m^)B2j99ROi zGx=VI6Pb*|7txuDbAi&4PIUf6pxEvV1+1s(NVzDY;=@KsV7IRm^?WgnRQ5_n6D3gZ zr?H$2Wu{HNzO?dFJr`*8H)n1c=u&(tbt2GgzwTcc8RVHx#@)`af;}`G)VFL7KF)JB z^>GRNw3sgFcz;FKY50=NoO~sxT^9nEeO$qTKxM4*6BTgx)6 z>*G2O1)Q0Yo6w-)m|e(h%r`au<5s}d$w++=5Iq6!L}&ASuHsore07k^`0X<}Td&3) zq>C(8$J#7!Z*xBnjTzje^CG_?7^#aAqr)m>7R>g8?h7cUkeT{R2;!m)=`8@Bae| CcZ%Nt literal 0 HcmV?d00001 diff --git a/FibonacciSeq/src/FibonacciSeq/FibonacciSeq.java b/FibonacciSeq/src/FibonacciSeq/FibonacciSeq.java new file mode 100644 index 0000000..e02350e --- /dev/null +++ b/FibonacciSeq/src/FibonacciSeq/FibonacciSeq.java @@ -0,0 +1,20 @@ +package FibonacciSeq; + +public class FibonacciSeq { + + public static void main(String[] args) { + // TODO Auto-generated method stub + System.out.println(getfebSeq(4)); + } + + public static int getfebSeq(int index) { + int firstsecpos = 1; + + if (index == 0 || index == 1) { + return firstsecpos; + } else { + return getfebSeq(index - 1) + getfebSeq(index - 2); + } + } + +} From e953cd9c8fced407b5fe6a84f26cd564d1f41db0 Mon Sep 17 00:00:00 2001 From: Hauser Date: Wed, 9 Jan 2019 18:11:43 -0600 Subject: [PATCH 03/16] submit rps --- RockPaperScissors/.classpath | 6 ++ RockPaperScissors/.project | 17 +++++ .../.settings/org.eclipse.jdt.core.prefs | 11 +++ .../bin/rockPS/RockPaperScissors.class | Bin 0 -> 2220 bytes .../src/rockPS/RockPaperScissors.java | 69 ++++++++++++++++++ 5 files changed, 103 insertions(+) create mode 100644 RockPaperScissors/.classpath create mode 100644 RockPaperScissors/.project create mode 100644 RockPaperScissors/.settings/org.eclipse.jdt.core.prefs create mode 100644 RockPaperScissors/bin/rockPS/RockPaperScissors.class create mode 100644 RockPaperScissors/src/rockPS/RockPaperScissors.java diff --git a/RockPaperScissors/.classpath b/RockPaperScissors/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/RockPaperScissors/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/RockPaperScissors/.project b/RockPaperScissors/.project new file mode 100644 index 0000000..f5d918c --- /dev/null +++ b/RockPaperScissors/.project @@ -0,0 +1,17 @@ + + + RockPaperScissors + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/RockPaperScissors/.settings/org.eclipse.jdt.core.prefs b/RockPaperScissors/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/RockPaperScissors/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/RockPaperScissors/bin/rockPS/RockPaperScissors.class b/RockPaperScissors/bin/rockPS/RockPaperScissors.class new file mode 100644 index 0000000000000000000000000000000000000000..ceffe548b3f25d99d8338f1f458dc600c12b2b77 GIT binary patch literal 2220 zcmZ`(+j0{}5IrLc?OI-pEnhGflXVD=B+C{d<|;#oNdN`;63dtv5|Xt%krzw5Vzsiv zL#k56SHKfb@aphjQ=uv!kUz;kBvj7qO5lqkZO!)d_H>^<-93N3`{Pdlli1J@5g78^ z()xTcyP#fHO?t(WU9Y=dT|-o$=aIExWh<6b&d#kok|kdtHf1}ue@&nxnOYKv-f&lC z93AL1a0oGhBL&-$vyJMC^cJm^iWEo`+>%vUvOHVuo64xaX4eId7yd7Pj=rmw?FbAe z9~3^|DEgl5lyj-2PV}NrLt+og;*+{Bs|NZpK!k3CfCs|Ewws;jNuTGXRn6%*DsWn5 zZ3bzZt-Ld4)moS46Sv`+HM_JP$1$AHa9p4-0I}DPfs+^(&}zzcgQ`;q8$j9YfHmrZWD- zwwy5ME7lX!DzhP3mZ;^G8Mm)ZU#fQBUm~`$(TWrnzH1jr0*8yfRa&31YQb!1m=Wj= zd^CK!k}Z}jhfSc`ea^re5vG~x}d51|f`#O#SimLdFob4v}Y}wr=sU>B!WZ+&< zR7d{etC>~GWdrxs5FaX4+&V`$##v!=G1V}s-GG=?(8}{15)D7L>J*qPuwC7191qc{ zmK6gfu=O+*EAMb9qse?Kuj6M*Y6f+zF=#M|Iv&w+YZ}>R9)0mXxh0u%liOV}h(c4` z(n3Jwc~tEb%Q_zOTi)5QDz=KPhI!6mQh~I%>C$(RqgawRZFNlz9=HN0R1q-3=I-E) z36e^Xh;h}p%knLhHoXJ=cM1{2xvI~~w2Q0Jlnor_t`prjLJbd#2%`K0{%iCk2DdTv z2B!*d@bL`yZ*gWh@#zjyW82`9<=2+>9JQJE+OfA?}Jz|{1Bk& zRQG5z#ujZ9WRkVlsa;2fXS#75RX9X2Kwoaai}_v}C8AK*WawWE zX?Q5&{~$t|7?oFQ6aC+`RSZ2%vnN>ZSYmoBosg8D!x#&MXBbK+?3P9e%1pL3E4R#) zpv=lN+ox>j&E87X_7gM7gwHeii=2r|Ecz9eGlykd#jm)A-*7!3MwN*0;gJOOd&*W) V4Wm+L^L6$1M#6_WpSlPd{{bOF<@Nvo literal 0 HcmV?d00001 diff --git a/RockPaperScissors/src/rockPS/RockPaperScissors.java b/RockPaperScissors/src/rockPS/RockPaperScissors.java new file mode 100644 index 0000000..19c33d3 --- /dev/null +++ b/RockPaperScissors/src/rockPS/RockPaperScissors.java @@ -0,0 +1,69 @@ +package rockPS; +import java.util.Random; +import java.util.Scanner; + +public class RockPaperScissors { + public static void main(String[] args) { + System.out.println("Rock Paper Scissors, make your pick"); + + String yourHand = yourHand(); + String computerHand = generateHand(); + + System.out.println("You: " + yourHand); + System.out.println("Opponent: " + computerHand); + + String winningMove = winningMoves(yourHand, computerHand); + + if (yourHand.equals(winningMove)) { + System.out.println("You won!"); + } else if (winningMove == computerHand) { + System.out.println("Womp, womp. The computer won."); + } else if (winningMove == "Tie"){ + System.out.println("It was a tie. Play again!"); + } + + } + + public static String yourHand() { + Scanner reader = new Scanner(System.in); + String yourPick = reader.nextLine(); + reader.close(); + + return yourPick; + } + + public static String generateHand() { + Random randNumGen = new Random(); + int compNum = randNumGen.nextInt(3); + String compHand; + + if (compNum == 0) { + compHand = "Rock"; + } else if (compNum == 1) { + compHand = "Paper"; + } else { + compHand = "Scissors"; + } + + return compHand; + } + + public static String winningMoves(String pickOne, String pickTwo) { + if (pickOne.equals(pickTwo)) { + return "Tie"; + } + else if ((pickOne.equals("Rock") || pickTwo.equals("Rock")) && (pickOne.equals("Scissors") || pickTwo.equals("Scissors"))) { + return "Rock"; + } + else if ((pickOne.equals("Rock") || pickTwo.equals("Rock")) && (pickOne.equals("Paper") || pickTwo.equals("Paper"))) { + return "Paper"; + } + else if ((pickOne.equals("Paper") || pickTwo.equals("Paper")) && (pickOne.equals("Scissors") || pickTwo.equals("Scissors"))) { + return "Scissors"; + } else { + return "Invalid"; + } + } + + +} From 25f178afaed1324cb1ac695c29253c72790c3ff7 Mon Sep 17 00:00:00 2001 From: Hauser Date: Wed, 9 Jan 2019 18:12:41 -0600 Subject: [PATCH 04/16] submit pig latin --- PigLatin/.classpath | 6 ++ PigLatin/.project | 17 ++++ PigLatin/.settings/org.eclipse.jdt.core.prefs | 11 +++ PigLatin/bin/Main.class | Bin 0 -> 2800 bytes PigLatin/src/Main.java | 76 ++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 PigLatin/.classpath create mode 100644 PigLatin/.project create mode 100644 PigLatin/.settings/org.eclipse.jdt.core.prefs create mode 100644 PigLatin/bin/Main.class create mode 100644 PigLatin/src/Main.java diff --git a/PigLatin/.classpath b/PigLatin/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/PigLatin/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/PigLatin/.project b/PigLatin/.project new file mode 100644 index 0000000..1221824 --- /dev/null +++ b/PigLatin/.project @@ -0,0 +1,17 @@ + + + PigLatin + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/PigLatin/.settings/org.eclipse.jdt.core.prefs b/PigLatin/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/PigLatin/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/PigLatin/bin/Main.class b/PigLatin/bin/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..7e3ab5663c3f598b0aa383b592384a899806b44f GIT binary patch literal 2800 zcmZ`*TXz#x6#h;!=}h7PA*H3*3qb_h^oB)2dsA93jiv=D7K_(uGHnN^GjTGZ)*D{% ze!nkxL7)1HELUL3TKoWCeD=W~qD#c@%uFT4x|+`HnX~sk-~PURcJj;LKVJiIH@;I5 z6Hq1%%Tb{Sq)!>Ajegs37W$9OoidBQK*O-*SpKL$yt8YDzTjszM6wiGPK zoT@I(nci_@&Nc-y1-EF}Glpl$=jf&4FIp95E6BZum}iN1f#%Mq3ODzh_C3p480wly zVk;U|WY!^?Ua9!zl8$X?A{w_!a7|&b<@O(Cq|bQMSQ^r>U10V&H_Y;5WXsk<);4_0 z$@-q*RA{zRJlW6+}cZ=mHmeJSif ztBTtN8UyI-ch}K|b^*040og3EsdJ+WRqPbl8pKz9%kG~p8jfRnvhZCx?!az=m?Y?C zg?Xo3U8^vK4(yQv>=kH<@)JhAOV^Ba>eSJNoPg$-FZog_fo+{#{{!eI{ zpN>JW1rn9AZBfL1_5N!uut8g>7!lZhYqyM5ExTlTGV%R79>8I8f7-CC=8<`Uz4fWX zjvm^u`eBSqI@?nacu2>?c!ZtJl1`hRf7Dti$nLo%-5S!3$Q(vq$D??R4R4gorc)B= zt%vfzu~9WcDGXy$$5f!5?}q*wjuO@JsE65#vb}kf3~zz7H*P=~_veWqJzNfP);Ak9 zNLDMR7qpE$x3_Xj2gX;bHdRWL4bSH`!s35kVAHg36knJ$%E19waZD=ktd8gKJfn(~ z{V=1H&V1LnBy~|@G{#)o{hW{ zq0MV}mE&dESkdr0jTLFU!P9802&Bk;iNo#@lid*URhOE4sYQ3GOb=T0J;8}0d3jgI zdw8F`*rv1KF9yRjFBd-4@ew|z4wdR$B{)xVCg$@SHt7L;D&0SmGi4(WHb>d5SUx-B z$b3Kr6VF>-#h0g$bdD3WZTcK|l`(VP^~}g=YxMH)JeQ((scE2J3%YXT>J4P{S@{?FJ^I)tUkr44k$OcNrQ@~RdlF05PY5{$-DkQN+Bwa zsgOYY#Eg=CCl{~bnY3{M-JxY(z^>4;E?|3Txfif0w5s1j%UywSF_$Tk*z?$z%ghHx zM=rA%7)`m16&QLh^8$@?LB!HUhLtaJ$B?gPVg_0G{TE*5j<$Id1(QL?^nUd-ef|NYc zZ&2Bx+ys;hWZXmf_EN4cN|Zwrx(Tg^uzIl@eO$SV-$Vle$cdndMi-_u_-De7Ue8EhQ0GBba)`Cw%SOJBd<>F{AvWM4Uhl^kzd$E=HSk~^E2W5) z80PRfx!_o*ziiYPv+Twf_>vWk@mI@NWFW>2ZTLE1%2>xr28ruXh4_oVZvKQ4`;$15 ya&|{8Fh%bed1 Date: Fri, 11 Jan 2019 16:39:52 -0600 Subject: [PATCH 05/16] add stats --- .gitignore | 1 + ArrayVList/.classpath | 6 + ArrayVList/.gitignore | 1 + ArrayVList/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ ArrayVList/src/ArrayVList/ArrayVList.java | 122 ++++++++++++++++++ Statistics/.classpath | 6 + Statistics/.gitignore | 1 + Statistics/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ Statistics/src/Statistics.java | 63 +++++++++ 11 files changed, 256 insertions(+) create mode 100644 .gitignore create mode 100644 ArrayVList/.classpath create mode 100644 ArrayVList/.gitignore create mode 100644 ArrayVList/.project create mode 100644 ArrayVList/.settings/org.eclipse.jdt.core.prefs create mode 100644 ArrayVList/src/ArrayVList/ArrayVList.java create mode 100644 Statistics/.classpath create mode 100644 Statistics/.gitignore create mode 100644 Statistics/.project create mode 100644 Statistics/.settings/org.eclipse.jdt.core.prefs create mode 100644 Statistics/src/Statistics.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e10e727 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.metadata/ diff --git a/ArrayVList/.classpath b/ArrayVList/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/ArrayVList/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/ArrayVList/.gitignore b/ArrayVList/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/ArrayVList/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/ArrayVList/.project b/ArrayVList/.project new file mode 100644 index 0000000..ec546ed --- /dev/null +++ b/ArrayVList/.project @@ -0,0 +1,17 @@ + + + ArrayVList + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/ArrayVList/.settings/org.eclipse.jdt.core.prefs b/ArrayVList/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/ArrayVList/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/ArrayVList/src/ArrayVList/ArrayVList.java b/ArrayVList/src/ArrayVList/ArrayVList.java new file mode 100644 index 0000000..70b0cab --- /dev/null +++ b/ArrayVList/src/ArrayVList/ArrayVList.java @@ -0,0 +1,122 @@ +package ArrayVList; +import java.util.ArrayList; +import java.util.List; + +public class ArrayVList { + public static void main(String[] args) { + String StringOfColors[] = {"red","blue","yellow"}; + + for (int i = 0; i < StringOfColors.length; i++) + System.out.println(StringOfColors[i]); + + //just showing a two dimensional array + String[][] twoDArray = new String[3][3]; + + /* very specific because I say ArrayList rather than just List. a "special type of lightbulb"*/ + ArrayList listOfColors = new ArrayList(); + + /*I want a just a light bulb, any kind*/ + List listOfColors2 = new ArrayList(); + + listOfColors.add("red"); + listOfColors.add("blue"); + listOfColors.add("yellow"); + + //just examples of getting size and getting specific value of array location + int s = listOfColors2.size(); + String blue = listOfColors.get(1); + + MyList colors = new MyList(); + + colors.add("Yellow"); + colors.add("Blue"); + colors.add("Red"); + colors.add("Green"); + colors.add("Black"); + + for (int i = 0; i < colors.size(); i++) { + System.out.println(i + " " + colors.get(i)); + } + + String red = colors.get(2); + int s2 = colors.size(); + + colors.remove(4); + + for (int i = 0; i < StringOfColors.length; i++) { + System.out.println(i + " " + colors.get(i)); + } + + } + + public static class MyList { + + String[] store = new String[10]; + int size = 0; + + /** + * Adds a string to the list + * @param s the string to add to the list + */ + public void add(String s) { + //figure out the add logic + + if(size == store.length) { + String[] tmp = new String[size+10]; + + for(int i = 0; i < store.length; i++) { + tmp[i] = store[i]; + } + + store = tmp; + + } + store[size] = s; + + size += 1; + + } + + /** + * Returns the current size of the list + * @return the current size of the list + */ + public int size() { + return size; + } + + /** + * Returns the string at the position passed in + * @param i the position passed in + * @return the string at the position + */ + public String get(int i) { + return store[i]; + } + + /** + * Removes the element from the list at the given position + * @param i the position to remove from the list + */ + public void remove(int i) { + //figure out the remove element logic + if(i > size) { + return; + } else { + String[] tmp = new String[size]; + for(int j = 0; j < size; i++) { + if(j != i) { + tmp[j] = store[i]; + } + } + + store = tmp; + store[size] = null; + size -= 1; + } + + } + } + + +} diff --git a/Statistics/.classpath b/Statistics/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/Statistics/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Statistics/.gitignore b/Statistics/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Statistics/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Statistics/.project b/Statistics/.project new file mode 100644 index 0000000..e98850d --- /dev/null +++ b/Statistics/.project @@ -0,0 +1,17 @@ + + + Statistics + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Statistics/.settings/org.eclipse.jdt.core.prefs b/Statistics/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/Statistics/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Statistics/src/Statistics.java b/Statistics/src/Statistics.java new file mode 100644 index 0000000..4832000 --- /dev/null +++ b/Statistics/src/Statistics.java @@ -0,0 +1,63 @@ +import java.util.Scanner; + +public class Statistics { + public static void main(String[] args) { + System.out.println("Please enter a list of numbers delimmited by comma."); + + Scanner reader = new Scanner(System.in); + String numberList = reader.nextLine(); + reader.close(); + + String[] numbString = numberList.split(","); + int[] numbs = new int[numbString.length]; + + for (int i = 0; i < numbs.length; i++) { + numbs[i] = Integer.parseInt(numbString[i]); + } + + int minNumb = calcMin(numbs); + int maxNumb = calcMax(numbs); + int sumNumb = calcSum(numbs); + int lengthNumb = numbs.length; + double avgNumb = (double)sumNumb / lengthNumb; + + System.out.println(minNumb); + System.out.println(maxNumb); + System.out.println(lengthNumb); + System.out.println(sumNumb); + System.out.println(avgNumb); + + + } + + public static int calcMin(int[] numbArray) { + int currentMin = numbArray[0]; + for (int i = 1; i < numbArray.length; i++) { + if (numbArray[i] <= currentMin) { + currentMin = numbArray[i]; + } + + } + return currentMin; + } + + public static int calcMax(int[] numbArray) { + int currentMax = numbArray[0]; + for (int i = 1; i < numbArray.length; i++) { + if (numbArray[i] >= currentMax) { + currentMax = numbArray[i]; + } + + } + return currentMax; + } + + public static int calcSum(int[] numbArray) { + int sum = 0; + for(int i = 0; i < numbArray.length; i++) { + sum += numbArray[i]; + } + return sum; + } + +} From a504791fef44e00f44c745c1280a22e1e86a5a7a Mon Sep 17 00:00:00 2001 From: Hauser Date: Fri, 18 Jan 2019 15:46:18 -0600 Subject: [PATCH 06/16] adding TicTacToe --- TicTacToe/.classpath | 6 ++ TicTacToe/.gitignore | 1 + TicTacToe/.project | 17 ++++ .../.settings/org.eclipse.jdt.core.prefs | 11 +++ TicTacToe/src/TicTacToe.java | 88 +++++++++++++++++++ 5 files changed, 123 insertions(+) create mode 100644 TicTacToe/.classpath create mode 100644 TicTacToe/.gitignore create mode 100644 TicTacToe/.project create mode 100644 TicTacToe/.settings/org.eclipse.jdt.core.prefs create mode 100644 TicTacToe/src/TicTacToe.java diff --git a/TicTacToe/.classpath b/TicTacToe/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/TicTacToe/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/TicTacToe/.gitignore b/TicTacToe/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/TicTacToe/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/TicTacToe/.project b/TicTacToe/.project new file mode 100644 index 0000000..d6bf9b5 --- /dev/null +++ b/TicTacToe/.project @@ -0,0 +1,17 @@ + + + TicTacToe + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/TicTacToe/.settings/org.eclipse.jdt.core.prefs b/TicTacToe/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/TicTacToe/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/TicTacToe/src/TicTacToe.java b/TicTacToe/src/TicTacToe.java new file mode 100644 index 0000000..9b41c16 --- /dev/null +++ b/TicTacToe/src/TicTacToe.java @@ -0,0 +1,88 @@ +import java.util.Scanner; + +public class TicTacToe { + + static String player = " X"; + static String[][] board = new String[][]{ + {" "," "," "}, + {" "," "," "}, + {" "," "," "} + }; + + public static void main(String[] args) { + System.out.println("Let's play tic tac toe."); + printBoard(); + + System.out.println("It's player "+player+"'s turn"); + + while(!didPlayerWin()) { + playTurn(); + } + + } + + + public static void playTurn( ) { + System.out.println("You will enter the row and column for your position placement."); + System.out.print("Enter Row: "); + + Scanner reader = new Scanner(System.in); + int playerRow = Integer.parseInt(reader.nextLine()); + + System.out.print("Enter Column: "); + int playerCol = Integer.parseInt(reader.nextLine()); + + if(board[playerRow][playerCol] != " ") { + System.out.println("Invalid move. Player already in position."); + playTurn(); + } else { + board[playerRow][playerCol] = player; + } + + + printBoard(); + + if(didPlayerWin()) { + System.out.println("Player " + player + " wins!"); + } else { + player = (player == " X") ? " O" : " X"; + System.out.println("It's player "+player+"'s turn"); + playTurn(); + } + + reader.close(); + + } + + public static void printBoard() { + System.out.println(" 0 1 2"); + System.out.println("0 " + String.join(" |",board[0])); + System.out.println(" -----------"); + System.out.println("1 " + String.join(" |",board[1])); + System.out.println(" -----------"); + System.out.println("2 " + String.join(" |",board[2])); + } + + public static boolean didPlayerWin() { + if ((board[0][0] == player && board[0][1] == player && board[0][2] == player) || + (board[1][0] == player && board[1][1] == player && board[1][2] == player) || + (board[2][0] == player && board[2][1] == player && board[2][2] == player) + ) { + return true; + } else if ((board[0][0] == player && board[1][0] == player && board[2][0] == player) || + (board[0][1] == player && board[1][1] == player && board[2][1] == player) || + (board[0][2] == player && board[1][2] == player && board[2][2] == player) + ) { + return true; + } else if ((board[0][0] == player && board[1][1] == player && board[2][2] == player) || + (board[0][2] == player && board[1][1] == player && board[2][0] == player) + ) { + return true; + + } + + return false; + } + + +} From e556525d87cbd74612a1d56c49a8e4314ba60ce8 Mon Sep 17 00:00:00 2001 From: Hauser Date: Thu, 24 Jan 2019 22:40:14 -0600 Subject: [PATCH 07/16] adding Gradebook --- GradeBook/.classpath | 6 ++ GradeBook/.gitignore | 1 + GradeBook/.project | 17 ++++ .../.settings/org.eclipse.jdt.core.prefs | 11 +++ GradeBook/src/GradeBook.java | 78 +++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 GradeBook/.classpath create mode 100644 GradeBook/.gitignore create mode 100644 GradeBook/.project create mode 100644 GradeBook/.settings/org.eclipse.jdt.core.prefs create mode 100644 GradeBook/src/GradeBook.java diff --git a/GradeBook/.classpath b/GradeBook/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/GradeBook/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/GradeBook/.gitignore b/GradeBook/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/GradeBook/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/GradeBook/.project b/GradeBook/.project new file mode 100644 index 0000000..53d01ac --- /dev/null +++ b/GradeBook/.project @@ -0,0 +1,17 @@ + + + GradeBook + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/GradeBook/.settings/org.eclipse.jdt.core.prefs b/GradeBook/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/GradeBook/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/GradeBook/src/GradeBook.java b/GradeBook/src/GradeBook.java new file mode 100644 index 0000000..0ea2628 --- /dev/null +++ b/GradeBook/src/GradeBook.java @@ -0,0 +1,78 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Scanner; + +/* + * Your program should ask the user to input the total number of students in the gradebook. +Your program should ask the user to input each student's name, and a list of grades for that student (as a comma-separated string). +Your program should print out each student's name and the average grade for that student. +Guidelines: + +Your program should store the students and the associated grades (as a comma-seperated string) in a Map +Your program should compute the average grade for each student, and create a new Map that stores the students and their corresponding grade average. +Use the Map that contains the students and their average grade to retrieve and print out the results. +When implementing your solution, use helper methods and include comments in your code. + */ +public class GradeBook { + public static void main(String[] args) { + //Prompting user for input and recording response in scanner + System.out.print("Input total number of students: "); + Scanner reader = new Scanner(System.in); + String studentsInput = reader.nextLine(); + + //instantiate hashmap for students and grades + Map gradeBook = new HashMap(); + + //instantiate hashmap for students and averages + Map studentAvgs = new HashMap(); + + //creating student arraylist to add students so I can reference from map later + ArrayList students = new ArrayList(); + + //Prompting user to input student grades + for(int i=1; i<=Integer.parseInt(studentsInput);i++) { + System.out.println("Input the student name."); + String studentEntry = reader.nextLine(); + + students.add(studentEntry); + + System.out.println("Input student grades seperated by comma."); + String studentGrades = reader.nextLine(); + + List gradeArray = new ArrayList(Arrays.asList(studentGrades.split(","))); + + //add grades to mapped student and add up total of grades + int gradeTotal = 0; + for(int j=0; j < gradeArray.size(); j++) { + gradeBook.put(studentEntry, gradeArray.get(j)); + gradeTotal += Integer.parseInt(gradeArray.get(j)); + } + + //calculate average + double studentAvg = (double) gradeTotal/gradeArray.size(); + + //add student and average to avg map + studentAvgs.put(studentEntry, studentAvg); + } + + /* + Iterator itr = studentAvgs.values().iterator(); + while (itr.hasNext()) { + System.out.println(itr.next()); + } + */ + //print out student names and averages + for(int i=0; i Date: Fri, 25 Jan 2019 15:47:12 -0600 Subject: [PATCH 08/16] upload assignments --- ArrayVList/src/ArrayVList/ArrayVList.java | 12 ++- GradeBook/src/GradeBook.java | 1 - TryCatch/.classpath | 6 ++ TryCatch/.gitignore | 1 + TryCatch/.project | 17 ++++ TryCatch/.settings/org.eclipse.jdt.core.prefs | 11 +++ TryCatch/src/TryCatch.java | 97 +++++++++++++++++++ 7 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 TryCatch/.classpath create mode 100644 TryCatch/.gitignore create mode 100644 TryCatch/.project create mode 100644 TryCatch/.settings/org.eclipse.jdt.core.prefs create mode 100644 TryCatch/src/TryCatch.java diff --git a/ArrayVList/src/ArrayVList/ArrayVList.java b/ArrayVList/src/ArrayVList/ArrayVList.java index 70b0cab..0720693 100644 --- a/ArrayVList/src/ArrayVList/ArrayVList.java +++ b/ArrayVList/src/ArrayVList/ArrayVList.java @@ -1,6 +1,7 @@ package ArrayVList; import java.util.ArrayList; import java.util.List; +import java.util.Scanner; public class ArrayVList { public static void main(String[] args) { @@ -21,7 +22,14 @@ public static void main(String[] args) { listOfColors.add("red"); listOfColors.add("blue"); listOfColors.add("yellow"); - + System.out.println("Hey Matt, it's future matt. Just checking in. Stay safe. Cheers."); + System.out.println("Do you have anything to say to him?"); + Scanner reader = new Scanner(System.in); + String yourPick = reader.nextLine(); + reader.close(); + System.out.println('"'+ yourPick + '"'); + System.out.println("me too, thanks"); + //just examples of getting size and getting specific value of array location int s = listOfColors2.size(); String blue = listOfColors.get(1); @@ -104,7 +112,7 @@ public void remove(int i) { return; } else { String[] tmp = new String[size]; - for(int j = 0; j < size; i++) { + for(int j = 0; j < size-1; i++) { if(j != i) { tmp[j] = store[i]; } diff --git a/GradeBook/src/GradeBook.java b/GradeBook/src/GradeBook.java index 0ea2628..ea09472 100644 --- a/GradeBook/src/GradeBook.java +++ b/GradeBook/src/GradeBook.java @@ -1,7 +1,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Scanner; diff --git a/TryCatch/.classpath b/TryCatch/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/TryCatch/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/TryCatch/.gitignore b/TryCatch/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/TryCatch/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/TryCatch/.project b/TryCatch/.project new file mode 100644 index 0000000..4ec7e44 --- /dev/null +++ b/TryCatch/.project @@ -0,0 +1,17 @@ + + + TryCatch + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/TryCatch/.settings/org.eclipse.jdt.core.prefs b/TryCatch/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/TryCatch/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/TryCatch/src/TryCatch.java b/TryCatch/src/TryCatch.java new file mode 100644 index 0000000..b537ebf --- /dev/null +++ b/TryCatch/src/TryCatch.java @@ -0,0 +1,97 @@ +/*ur program should: + +Should meet all the requirements of the previous Rock Paper Scissors assignment. +This implementation should make of use to the try catch mechanism to capture and handle incorrect user input. +Guidelines: + +The method that accepts input from the user should throw an exception if the user enters invalid input. +The calling method should use a try/catch block to handle the bad input and print a nice message to the user. +*/ +import java.util.Random; +import java.util.Scanner; + +public class TryCatch { + public static void main(String[] args) { + + System.out.println("Rock Paper Scissors, make your pick"); + + String yourHand = yourHand(); + String computerHand = generateHand(); + + System.out.println("You: " + yourHand); + System.out.println("Opponent: " + computerHand); + + String winningMove = winningMoves(yourHand, computerHand); + + if (yourHand.toLowerCase().equals(winningMove)) { + System.out.println("You won!"); + } else if (winningMove.contentEquals(computerHand.toLowerCase())) { + System.out.println("Womp, womp. The computer won."); + } else if (winningMove == "Tie"){ + System.out.println("It was a tie. Play again!"); + } + + + } + + public static void checkUserInput (String s) { + if(!(s.toLowerCase().equals("rock") || s.toLowerCase().equals("paper") || s.toLowerCase().equals("scissors"))) { + throw new IllegalArgumentException(); + } + } + + public static String yourHand() { + Scanner reader = new Scanner(System.in); + String yourPick = ""; + + boolean validPick = true; + while(validPick) { + try { + yourPick = reader.nextLine(); + checkUserInput(yourPick); + validPick = false; + + } catch (Exception e) { + System.out.println("Program is throwing an exception: " + e); + System.out.println("Please enter a valid move: Rock, Paper, or Scissors."); + } + } + + reader.close(); + return yourPick; + } + + public static String generateHand() { + Random randNumGen = new Random(); + int compNum = randNumGen.nextInt(3); + String compHand; + + if (compNum == 0) { + compHand = "Rock"; + } else if (compNum == 1) { + compHand = "Paper"; + } else { + compHand = "Scissors"; + } + + return compHand; + } + + public static String winningMoves(String pickOne, String pickTwo) { + if (pickOne.toLowerCase().equals(pickTwo.toLowerCase())) { + return "Tie"; + } + else if ((pickOne.toLowerCase().equals("rock") || pickTwo.toLowerCase().equals("rock")) && (pickOne.toLowerCase().equals("scissors") || pickTwo.toLowerCase().equals("scissors"))) { + return "rock"; + } + else if ((pickOne.toLowerCase().equals("rock") || pickTwo.toLowerCase().equals("rock")) && (pickOne.toLowerCase().equals("paper") || pickTwo.toLowerCase().equals("paper"))) { + return "paper"; + } + else if ((pickOne.toLowerCase().equals("paper") || pickTwo.toLowerCase().equals("paper")) && (pickOne.toLowerCase().equals("scissors") || pickTwo.toLowerCase().equals("scissors"))) { + return "scissors"; + } else { + return "Invalid"; + } + + } +} From 536275ca9932d8e6f05ce74e1f388fa03c3feeac Mon Sep 17 00:00:00 2001 From: Hauser Date: Thu, 31 Jan 2019 08:11:15 -0600 Subject: [PATCH 09/16] add DL proj --- DriversLicense/.classpath | 6 + DriversLicense/.gitignore | 1 + DriversLicense/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ DriversLicense/src/DriversLicense.java | 108 ++++++++++++++++++ DriversLicense/src/LicenseProgram.java | 57 +++++++++ 6 files changed, 200 insertions(+) create mode 100644 DriversLicense/.classpath create mode 100644 DriversLicense/.gitignore create mode 100644 DriversLicense/.project create mode 100644 DriversLicense/.settings/org.eclipse.jdt.core.prefs create mode 100644 DriversLicense/src/DriversLicense.java create mode 100644 DriversLicense/src/LicenseProgram.java diff --git a/DriversLicense/.classpath b/DriversLicense/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/DriversLicense/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/DriversLicense/.gitignore b/DriversLicense/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/DriversLicense/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/DriversLicense/.project b/DriversLicense/.project new file mode 100644 index 0000000..26f992f --- /dev/null +++ b/DriversLicense/.project @@ -0,0 +1,17 @@ + + + DriversLicense + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/DriversLicense/.settings/org.eclipse.jdt.core.prefs b/DriversLicense/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/DriversLicense/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/DriversLicense/src/DriversLicense.java b/DriversLicense/src/DriversLicense.java new file mode 100644 index 0000000..051bfa1 --- /dev/null +++ b/DriversLicense/src/DriversLicense.java @@ -0,0 +1,108 @@ +import java.time.LocalDate; +import java.time.Period; + + +/* + * The DriversLicense class must include the following attributes: + +First Name +Last Name +DOB +Height +Gender +Your DriversLicense class should have a getFullName() method that returns the full name by concatenating the first name and the last name attributes. + +Your DriversLicenseclass should have a getAge() method that returns the age by based on the DOB attribute. + */ +public class DriversLicense { + /** + * instantiating attributes of DL + */ + private String firstName; + private String lastName; + private LocalDate dateOfBirth; + private String height; + private String gender; + + /** + * default constructor method that takes in no parameters + */ + protected DriversLicense() { + + } + + /** + * overloaded constructor that assigns all attributes of DL + * @param fn firstname + * @param ln lastname + * @param dob dateofbirth + * @param h height + * @param g gender + */ + protected DriversLicense(String fn, String ln, LocalDate dob, String h, String g) { + firstName = fn; + lastName = ln; + dateOfBirth = dob; + height = h; + gender = g; + } + + /** + * getters and setters + * @return first name + */ + protected String getFirstName() { + return firstName; + } + + protected void setFirstName(String firstName) { + this.firstName = firstName; + } + + protected String getLastName() { + return lastName; + } + + protected void setLastName(String lastName) { + this.lastName = lastName; + } + + protected LocalDate getDOB() { + return dateOfBirth; + } + + protected void setDOB(LocalDate dateOfBirth) { + this.dateOfBirth = dateOfBirth; + } + + protected String getHeight() { + return height; + } + + protected void setHeight(String height) { + this.height = height; + } + + protected String getGender() { + return gender; + } + + protected void setGender(String gender) { + this.gender = gender; + } + + protected String getFullName() { + return firstName + " " + lastName; + } + + public int getAge() { + LocalDate currentDate = LocalDate.now(); + if ((dateOfBirth != null) && (currentDate != null)) { + return Period.between(dateOfBirth, currentDate).getYears(); + } else { + return 0; + } + } + + +} \ No newline at end of file diff --git a/DriversLicense/src/LicenseProgram.java b/DriversLicense/src/LicenseProgram.java new file mode 100644 index 0000000..96c0a32 --- /dev/null +++ b/DriversLicense/src/LicenseProgram.java @@ -0,0 +1,57 @@ +import java.time.LocalDate; + +/* + * Create a DriversLicense Java project with two classes, DriversLicense and LicenseProgram. + +You"ll use the LicenseProgram class to run your program and create DriversLicense instances. +The LicenseProgram class will contain one main method (and nothing else). +When run, LicenseProgram should create three different instances of a DriversLicense and print out the full name and age on each license. +Include comments in your code. At the minimum, include a comment for each method to explain what it does. If you submit code without any comments, 5 points will be subtracted from your assignment score. + */ +public class LicenseProgram { + public static void main(String[] args) { + + /* + * creating each persons bday objects + */ + LocalDate person1BDay = LocalDate.of(1940, 10, 9); + LocalDate person2Bday = LocalDate.of(1942, 6, 14); + LocalDate person3BDay = LocalDate.of(1942, 2, 25); + LocalDate person4BDay = LocalDate.of(1940, 7, 7); + + + /* + * instantiating person1 driverlicense object using overloaded constructor + */ + DriversLicense person1 = new DriversLicense("John","Lennon",person1BDay,"5 10","Male"); + System.out.println(person1.getFullName()); + System.out.println(person1.getAge()); + + /* + * instantiating person2 driver license object using default constructor + */ + DriversLicense person2 = new DriversLicense(); + + /* + * using setters to set attributes to person2 object + */ + person2.setFirstName("Paul"); + person2.setLastName("McCartney"); + person2.setDOB(person2Bday); + person2.setHeight("5 11"); + person2.setGender("Male"); + person2.getFullName(); + System.out.println(person2.getFullName()); + System.out.println(person2.getAge()); + + DriversLicense person3 = new DriversLicense("George","Harrison",person3BDay,"5 10","Male"); + System.out.println(person3.getFullName()); + System.out.println(person3.getAge()); + + DriversLicense person4 = new DriversLicense("Ringo","Star",person4BDay,"5 6","Male"); + System.out.println(person4.getFullName()); + System.out.println(person4.getAge()); + + + } +} From 4f7968cd53292117ee1d9b9983e67f8fbf883749 Mon Sep 17 00:00:00 2001 From: Hauser Date: Fri, 1 Feb 2019 16:18:30 -0600 Subject: [PATCH 10/16] parking garage add --- ParkingGarage/.classpath | 6 + ParkingGarage/.gitignore | 1 + ParkingGarage/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ ParkingGarage/src/Car.java | 45 +++++++ ParkingGarage/src/GarageManager.java | 85 ++++++++++++++ ParkingGarage/src/ParkingGarage.java | 111 ++++++++++++++++++ 7 files changed, 276 insertions(+) create mode 100644 ParkingGarage/.classpath create mode 100644 ParkingGarage/.gitignore create mode 100644 ParkingGarage/.project create mode 100644 ParkingGarage/.settings/org.eclipse.jdt.core.prefs create mode 100644 ParkingGarage/src/Car.java create mode 100644 ParkingGarage/src/GarageManager.java create mode 100644 ParkingGarage/src/ParkingGarage.java diff --git a/ParkingGarage/.classpath b/ParkingGarage/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/ParkingGarage/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/ParkingGarage/.gitignore b/ParkingGarage/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/ParkingGarage/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/ParkingGarage/.project b/ParkingGarage/.project new file mode 100644 index 0000000..7ef66aa --- /dev/null +++ b/ParkingGarage/.project @@ -0,0 +1,17 @@ + + + ParkingGarage + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/ParkingGarage/.settings/org.eclipse.jdt.core.prefs b/ParkingGarage/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/ParkingGarage/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/ParkingGarage/src/Car.java b/ParkingGarage/src/Car.java new file mode 100644 index 0000000..310a45a --- /dev/null +++ b/ParkingGarage/src/Car.java @@ -0,0 +1,45 @@ + +public class Car { + private String color; + private String licenseNum; + private String make; + private String model; + + protected Car() { + + } + + protected Car(String myColor, String myLicenseNum, String myMake, String myModel) { + color = myColor; + licenseNum = myLicenseNum; + make = myMake; + model = myModel; + } + + public String getColor() { + return color; + } + public void setColor(String color) { + this.color = color; + } + public String getLicenseNum() { + return licenseNum; + } + public void setLicenseNum(String licenseNum) { + this.licenseNum = licenseNum; + } + public String getMake() { + return make; + } + public void setMake(String make) { + this.make = make; + } + public String getModel() { + return model; + } + public void setModel(String model) { + this.model = model; + } + + +} diff --git a/ParkingGarage/src/GarageManager.java b/ParkingGarage/src/GarageManager.java new file mode 100644 index 0000000..14485a1 --- /dev/null +++ b/ParkingGarage/src/GarageManager.java @@ -0,0 +1,85 @@ +/* + * Requirements +Your program should implement a Car class, a ParkingGarage class, and a GarageManager class. +The GarageManager Class and the Main method +The GarageManager class will contain the main(String[] args) method for your program. It doesn't need to contain anything else. + +Your main() method will act as the "driver" for this program. + +In your main() method, you should: + +Instantiate a few ParkingGarage instances with different capacities. +Instantiate a few cars, and proceed to park them and unpark them from the garages. +Guidelines +Your implementation should be broken down into different methods. + +Each method should have a well defined "job". + +Include comments in your code. At the minimum, include a comment for each method to explain what it does. If you submit code without any comments, 5 points will be subtracted from your assignment score. + */ +public class GarageManager { + public static void main(String args[]) { + /* + * instantiate a few different garages. two different ways constructor and overloaded + */ + ParkingGarage garage1 = new ParkingGarage(); + ParkingGarage garage2 = new ParkingGarage(4); + + /* + * instantiating some cars + */ + + Car car1 = new Car(); + Car car2 = new Car(); + Car car3 = new Car("white","DJK4LDK","Subaru","Crosstrek"); + Car car4 = new Car("silver","WOD3K5D","Honda","Civic"); + Car car5 = new Car("tan","FJ9DLKS","Toyota","4Runner"); + Car car6 = new Car("purple","SDHF3D","Hyundai","Elantra"); + Car car7 = new Car("green","FJD3DL","Subaru","WRX"); + + /* + * assigning attributes to parking garage + */ + + garage1.setCapacity(1); + + /* + * assigning attributes to cars + */ + + car1.setColor("red"); + car1.setLicenseNum("DJEL4K4"); + car1.setMake("Jeep"); + car1.setModel("Patriot"); + + car2.setColor("black"); + car2.setLicenseNum("DFJDS3"); + car2.setMake("Nissan"); + car2.setModel("Maxima"); + + garage1.park(car1, 0); + garage1.park(car2, 0); + garage2.park(car3, 1); + garage2.park(car4, 2); + garage2.park(car5, 3); + garage2.park(car6, 3); + garage2.park(car7, 4); + + System.out.println(""); + + garage1.printInventory(); + garage2.printInventory(); + + System.out.println(""); + + garage2.vacate(0); + garage2.vacate(0); + garage2.vacate(1); + garage2.vacate(2); + garage2.vacate(3); + garage2.vacate(10); + + + + } +} diff --git a/ParkingGarage/src/ParkingGarage.java b/ParkingGarage/src/ParkingGarage.java new file mode 100644 index 0000000..90e08db --- /dev/null +++ b/ParkingGarage/src/ParkingGarage.java @@ -0,0 +1,111 @@ +/* + * Your implementation of the ParkingGarage class should have a car array(Car[]) to represent the parking spots. The "spot number" of each parking spot is its array index (starting with spot 0). + +Your ParkingGarage constructor should take in capacity as input. This will represent the capacity of the parking garage instance. + +Your ParkingGarage class should implement: + +park(Car car, int spot) method, that will add the car to a parking spot. +If the user attempts to add the car to a spot that doesn't exist (outside the array), catch the exception and notify the user. +If there's already a car parked in the spot, notify the user that the car cannot be parked in that spot. +vacate(int spot) method, that will remove the car from the specified spot. +If the user attempts to remove a car from an empty spot, notify the user that no car is present in that spot. +printInventory() method, that prints out to the console the the listing of all the cars with a brief description. For each car, please include: +The spot number (array index) of the car in the parking garage +The car's color, license #, make, and model + */ +public class ParkingGarage { + //initiating variables that serve as attributes for the parking garage + private Car[] parkingSpots; + private int capacity; + + /* + * constructor that takes in capacity parameter, assigns to capacity attribute and initializes car array that adds spots to "Garage" + */ + protected ParkingGarage() { + + } + + protected ParkingGarage(int capacity) { + this.capacity = capacity; + parkingSpots = new Car[capacity]; + } + + /* + * park method that will adds car object to the car array. + */ + protected void park(Car parkingCar, int spot) { + try { + + if(parkingSpots[spot] == null) { + parkingSpots[spot] = parkingCar; + System.out.println(parkingCar.getMake() + " " + parkingCar.getModel() + " parked in spot "+ (spot+1)); + } else { + System.out.println("Can't park " + parkingCar.getMake() + " " + parkingCar.getModel() + ". " +"Spot " + (spot+1) + " already has a car in it."); + } + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Exception occured. That spot doesn't exist in this parking garage."); + } finally { + System.out.println("--------------------------------"); + } + + } + + //Getters and setters + public Car[] getParkingSpots() { + return parkingSpots; + } + + public int getCapacity() { + return capacity; + } + + public void setCapacity(int capacity) { + this.capacity = capacity; + parkingSpots = new Car[capacity]; + } + + /** + * method to vacate car from parking spot + * @param spot that you want to remove car from + */ + protected void vacate(int spot) { + + try { + String carInSpot = parkingSpots[spot].getMake() + " " + parkingSpots[spot].getModel(); + if(parkingSpots[spot] != null) { + parkingSpots[spot] = null; + System.out.println(carInSpot + " has been towed."); + } else { + System.out.println("This spot is already vacated."); + } + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Exception occured. That spot doesn't exist in this parking garage."); + } catch (NullPointerException e) { + System.out.println("There is no car to tow from this spot."); + } finally { + System.out.println("--------------------------------"); + } + + + } + + protected void printInventory() { + for(int i=0; i Date: Sun, 10 Feb 2019 13:28:42 -0600 Subject: [PATCH 11/16] Car lots assignment push --- CarLots/.classpath | 6 ++ CarLots/.gitignore | 1 + CarLots/.project | 17 +++++ CarLots/.settings/org.eclipse.jdt.core.prefs | 11 +++ CarLots/src/Car.java | 42 ++++++++++++ CarLots/src/CarLot.java | 64 ++++++++++++++++++ CarLots/src/CarType.java | 4 ++ CarLots/src/Program.java | 52 +++++++++++++++ CarLots/src/Truck.java | 24 +++++++ CarLots/src/Vehicle.java | 70 ++++++++++++++++++++ 10 files changed, 291 insertions(+) create mode 100644 CarLots/.classpath create mode 100644 CarLots/.gitignore create mode 100644 CarLots/.project create mode 100644 CarLots/.settings/org.eclipse.jdt.core.prefs create mode 100644 CarLots/src/Car.java create mode 100644 CarLots/src/CarLot.java create mode 100644 CarLots/src/CarType.java create mode 100644 CarLots/src/Program.java create mode 100644 CarLots/src/Truck.java create mode 100644 CarLots/src/Vehicle.java diff --git a/CarLots/.classpath b/CarLots/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/CarLots/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/CarLots/.gitignore b/CarLots/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/CarLots/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/CarLots/.project b/CarLots/.project new file mode 100644 index 0000000..0c19a3d --- /dev/null +++ b/CarLots/.project @@ -0,0 +1,17 @@ + + + CarLots + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/CarLots/.settings/org.eclipse.jdt.core.prefs b/CarLots/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/CarLots/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/CarLots/src/Car.java b/CarLots/src/Car.java new file mode 100644 index 0000000..c55d01f --- /dev/null +++ b/CarLots/src/Car.java @@ -0,0 +1,42 @@ +/* + * type (coupe, hatchback, or sedan) +number of doors + */ +public class Car extends Vehicle { + + private CarType type; + private int numDoors; + + /* + * car constructor that gets 4 attributes from parent super class and has to assign two attributes of its own + */ + public Car(String licenseNum, String make, String model, double price, CarType type, int numDoors) { + super(licenseNum, make, model, price); + this.type = type; + this.numDoors = numDoors; + } + + @Override + public String basicDetails() { + return "Car is a " + getType() + " and has " + getNumDoors() + " doors."; + } + + public CarType getType() { + return type; + } + + public void setType(CarType type) { + this.type = type; + } + + public int getNumDoors() { + return numDoors; + } + + public void setNumDoors(int numDoors) { + this.numDoors = numDoors; + } + + + +} diff --git a/CarLots/src/CarLot.java b/CarLots/src/CarLot.java new file mode 100644 index 0000000..25b0387 --- /dev/null +++ b/CarLots/src/CarLot.java @@ -0,0 +1,64 @@ +import java.util.List; + +/* + * CarLot should have the following fields: +name +a list of vehicles +CarLot should have methods to do the following actions: +add a vehicle to the lot +print the inventory of the car lot, including number of vehicles and details about each vehicle + */ +public class CarLot { + private String name; + private List vehicleList; + + /* + * creating constructors + */ + public CarLot() { + + } + + public CarLot(String name, List vehicleList) { + this.setName(name); + this.vehicleList = vehicleList; + } + + /* + * print lot method that prints lot details then uses print vehicle method for each vehicle in lot + */ + public void printLot() { + System.out.println("Lot: " + getName() + " has " + vehicleList.size() + " cars in it."); + for(Vehicle v: vehicleList) { + System.out.print(v.printVehicle()); + } + System.out.println(""); + } + + /** + * method to add vehicle object to vehicle list array + * @param vehicleAdding object being added + */ + public void addVehicle(Vehicle vehicleAdding) { + vehicleList.add(vehicleAdding); + } + + /* + * getters and setters + */ + public List getVehicleList() { + return vehicleList; + } + + public void setVehicleList(List vehicleList) { + this.vehicleList = vehicleList; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/CarLots/src/CarType.java b/CarLots/src/CarType.java new file mode 100644 index 0000000..c02434f --- /dev/null +++ b/CarLots/src/CarType.java @@ -0,0 +1,4 @@ + +public enum CarType { + COUPE, HATCHBACK, SEDAN +} diff --git a/CarLots/src/Program.java b/CarLots/src/Program.java new file mode 100644 index 0000000..cadebf5 --- /dev/null +++ b/CarLots/src/Program.java @@ -0,0 +1,52 @@ +import java.util.ArrayList; +import java.util.List; + +/* + * Create a CarLotProgram class that will contain your main method and act as a "driver" for your program. + +For this assignment you do not have to build an interactive program. + +In your main method: +You should instantiate 2 different car lots, and add various vehicles to the car lots. +Print out the inventory for each of the car lots, showing the details for each vehicle. +When printing out the details, print the appropriate info for a car, or a truck accordingly. + */ +public class Program { + + public static void main(String[] args) { + + /** + * instantiating car lots + */ + List mattsCarsForSale = new ArrayList(); + CarLot lot1 = new CarLot("Matt's used cars for less", mattsCarsForSale); + List ravensCarsForSale = new ArrayList(); + CarLot lot2 = new CarLot("Raven's Cars Depot", ravensCarsForSale); + + /** + * creating vehicle objects of various sub types + */ + Vehicle subaru = new Car("FJ3DK03","Subaru","Crosstrek",22000,CarType.HATCHBACK,4); + Vehicle jeep = new Car("DKE3L0D","Jeep","Patriot",17000,CarType.HATCHBACK,4); + Vehicle honda = new Car("F23DB03","Honda","Civic SI",26000,CarType.COUPE,2); + Vehicle f150 = new Truck("FJ3DK03","Ford","F-150",22000,6); + Vehicle tacoma = new Truck("FJ3DK03","Toyota","Tacoma",22000,4); + + /** + * adding vehicle objects to lots + * adds the vehicle object to list array + */ + lot2.addVehicle(jeep); + lot2.addVehicle(subaru); + lot1.addVehicle(honda); + lot1.addVehicle(f150); + lot2.addVehicle(tacoma); + + lot1.printLot(); + lot2.printLot(); + + + + } + +} diff --git a/CarLots/src/Truck.java b/CarLots/src/Truck.java new file mode 100644 index 0000000..4569924 --- /dev/null +++ b/CarLots/src/Truck.java @@ -0,0 +1,24 @@ +/* + * bed size + */ +public class Truck extends Vehicle { + private int bedSize; + + public Truck(String licenseNum, String make, String model, double price, int bedSize) { + super(licenseNum, make, model, price); + this.setBedSize(bedSize); + } + + public int getBedSize() { + return bedSize; + } + + public void setBedSize(int bedSize) { + this.bedSize = bedSize; + } + + @Override + public String basicDetails() { + return "Truck with bed size of " + Integer.toString(getBedSize()); + } +} diff --git a/CarLots/src/Vehicle.java b/CarLots/src/Vehicle.java new file mode 100644 index 0000000..8528616 --- /dev/null +++ b/CarLots/src/Vehicle.java @@ -0,0 +1,70 @@ +/* + * Vehicle should have the following fields: +license number +make +model +price +Vehicle should have methods to do the following actions: +print a description of the vehicle, including license number, make, model, and price + */ +public abstract class Vehicle { + private String licenseNum; + private String make; + private String model; + private double price; + + public Vehicle(String licenseNum, String make, String model, double price) { + this.licenseNum = licenseNum; + this.make = make; + this.model = model; + this.price = price; + } + + /** + * abstract method that every subclass will need to have + * will have specifics details for each subclass not specific to vehicle + * @return + */ + public abstract String basicDetails(); + + /** + * print vehicle method that uses the basicdetails abstract that every subclass of vehicle will have + * + * @return basic details plus attributes of every vehicle + */ + public String printVehicle() { + return basicDetails() + "\n" + getLicenseNum() + " " + getMake() + " " + getModel() + " " + getPrice() + "\n" + "\n"; + } + + /** + * getters and setters + * @return + */ + public String getLicenseNum() { + return licenseNum; + } + public void setLicenseNum(String licenseNum) { + this.licenseNum = licenseNum; + } + public String getMake() { + return make; + } + public void setMake(String make) { + this.make = make; + } + public String getModel() { + return model; + } + public void setModel(String model) { + this.model = model; + } + public double getPrice() { + return price; + } + public void setPrice(double price) { + this.price = price; + } + + + +} From 9772db3d8c4ee196446a5e595f4a1d12049512ac Mon Sep 17 00:00:00 2001 From: Hauser Date: Sun, 10 Feb 2019 17:51:52 -0600 Subject: [PATCH 12/16] adding Rent assignment --- Rentable/.classpath | 6 ++ Rentable/.gitignore | 1 + Rentable/.project | 17 ++++ Rentable/.settings/org.eclipse.jdt.core.prefs | 11 +++ Rentable/src/Condo.java | 36 +++++++ Rentable/src/Program.java | 97 +++++++++++++++++++ Rentable/src/Rentable.java | 7 ++ Rentable/src/Room.java | 30 ++++++ Rentable/src/Tool.java | 30 ++++++ 9 files changed, 235 insertions(+) create mode 100644 Rentable/.classpath create mode 100644 Rentable/.gitignore create mode 100644 Rentable/.project create mode 100644 Rentable/.settings/org.eclipse.jdt.core.prefs create mode 100644 Rentable/src/Condo.java create mode 100644 Rentable/src/Program.java create mode 100644 Rentable/src/Rentable.java create mode 100644 Rentable/src/Room.java create mode 100644 Rentable/src/Tool.java diff --git a/Rentable/.classpath b/Rentable/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/Rentable/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Rentable/.gitignore b/Rentable/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Rentable/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Rentable/.project b/Rentable/.project new file mode 100644 index 0000000..f39121a --- /dev/null +++ b/Rentable/.project @@ -0,0 +1,17 @@ + + + Rentable + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Rentable/.settings/org.eclipse.jdt.core.prefs b/Rentable/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/Rentable/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Rentable/src/Condo.java b/Rentable/src/Condo.java new file mode 100644 index 0000000..2e9a156 --- /dev/null +++ b/Rentable/src/Condo.java @@ -0,0 +1,36 @@ + +public class Condo implements Rentable { + public String name; + public double weeklyRate; + + /** + * constructor for condo, similar to room + * @param name will be description of Condo + * @param w price for condo + */ + public Condo(String name, double weeklyRate){ + this.name = name; + this.weeklyRate = weeklyRate; + } + + /** + * auto generated metods from rentable interface contract + */ + @Override + public String getDescription() { + return name; + } + + @Override + public double getDailyRate() { + // TODO Auto-generated method stub + return (double)(weeklyRate / 7.00); + } + + @Override + public double getPrice(double days) { + // TODO Auto-generated method stub + return (double)((weeklyRate / 7) * days); + } + +} diff --git a/Rentable/src/Program.java b/Rentable/src/Program.java new file mode 100644 index 0000000..84ff7f2 --- /dev/null +++ b/Rentable/src/Program.java @@ -0,0 +1,97 @@ +import java.util.Scanner; + +public class Program { + + public static void main(String[] args) { + /* + * instantiating rentable objects + */ + Rentable hotelRoom = new Room("Hilton", 125.87); + Rentable vacationCondo = new Condo("Paradise Resorts", 2380.98); + Rentable visegripTool = new Tool("Park Tools", 7.87); + Rentable hammerTool = new Tool("Hefty", 5.66); + Rentable hostelRoom = new Room("Hip Hostel", 45.43); + Rentable timeshareCondo = new Condo("Mountain Bliss", 2083.88); + + Rentable[] objectsForRent = new Rentable[8]; + + objectsForRent[0] = hotelRoom; + objectsForRent[1] = vacationCondo; + objectsForRent[2] = visegripTool; + objectsForRent[3] = hammerTool; + objectsForRent[4] = hostelRoom; + objectsForRent[5] = timeshareCondo; + + //I can also assign array value directly to object + objectsForRent[6] = new Room("Marriot", 104.56); + objectsForRent[7] = new Tool("Crank Brothers", 10.32); + + //I can also initialize array and assign objects all in one line + Rentable[] objectsForRentElsewhere = {new Condo("Cabin in the Woods", 790.43), new Room("Luxury Downtown Airbnb in Ausitn", 230.44)}; + + System.out.println("Available to rent!"); + System.out.println("-------------------------------------------------"+"\n"); + + Scanner reader = new Scanner(System.in); + String rentAnswer = "No"; + int daysOfStay = 0; + + do { + /** + * looping through each rentable object to display details, prompt user for price + */ + for(Rentable r: objectsForRent) { + + if(rentAnswer.toLowerCase().equals("no")) { + System.out.println((r.getClass().toString()).substring(6) + ": " + r.getDescription() + ", daily rate of $" + r.getDailyRate()); + } + + if(rentAnswer.toLowerCase().equals("yes")) { + if(r instanceof Room) { + System.out.println("Room: " + r.getDescription() + ", total rent cost $" + r.getPrice(daysOfStay)); + } + + if(r instanceof Condo) { + System.out.println("Condo: " + r.getDescription() + ", total rent cost $" + r.getPrice(daysOfStay)); + } + + if(r instanceof Tool) { + System.out.println("Tool: " + r.getDescription() + ", total rent cost $" + r.getPrice(daysOfStay)); + } + + } + + } + + + System.out.println("\n" + "Would you like to get price estimate for your stay?"); + boolean validPick = false; + while(!validPick) { + try { + rentAnswer = reader.next(); + checkUserInput(rentAnswer); + validPick = true; + + } catch (Exception e) { + System.out.println("Please enter a yes or no."); + } + } + + if(rentAnswer.equalsIgnoreCase("yes")) { + System.out.println("How many days?"); + daysOfStay = reader.nextInt(); + } else break; + + } + while(rentAnswer.equalsIgnoreCase("Yes")); + + reader.close(); + + } + public static void checkUserInput(String s) { + if(!(s.toLowerCase().equals("yes") || s.toLowerCase().equals("no"))) { + throw new IllegalArgumentException(); + } + } + +} diff --git a/Rentable/src/Rentable.java b/Rentable/src/Rentable.java new file mode 100644 index 0000000..b63fe57 --- /dev/null +++ b/Rentable/src/Rentable.java @@ -0,0 +1,7 @@ + +public interface Rentable { + + public String getDescription(); + public double getDailyRate(); + public double getPrice(double days); +} diff --git a/Rentable/src/Room.java b/Rentable/src/Room.java new file mode 100644 index 0000000..38ca84d --- /dev/null +++ b/Rentable/src/Room.java @@ -0,0 +1,30 @@ + +public class Room implements Rentable { + + public String name; + public double dailyRate; + + public Room(String name, double dailyRate) { + this.name = name; + this.dailyRate = dailyRate; + } + + @Override + public String getDescription() { + // TODO Auto-generated method stub + return name; + } + + @Override + public double getDailyRate() { + // TODO Auto-generated method stub + return dailyRate; + } + + @Override + public double getPrice(double days) { + // TODO Auto-generated method stub + return (double)(dailyRate * days); + } + +} diff --git a/Rentable/src/Tool.java b/Rentable/src/Tool.java new file mode 100644 index 0000000..38eae4d --- /dev/null +++ b/Rentable/src/Tool.java @@ -0,0 +1,30 @@ + +public class Tool implements Rentable { + + public String name; + public double hourlyRate; + + public Tool(String name, double hourlyRate) { + this.name = name; + this.hourlyRate = hourlyRate; + } + + @Override + public String getDescription() { + // TODO Auto-generated method stub + return name; + } + + @Override + public double getDailyRate() { + // TODO Auto-generated method stub + return (double)(hourlyRate * 24); + } + + @Override + public double getPrice(double days) { + // TODO Auto-generated method stub + return (double)(hourlyRate * 24 * days); + } + +} From 79f9840a07a41dde82d67925d243dc86ecb4f122 Mon Sep 17 00:00:00 2001 From: "Hauser, Matthew" Date: Wed, 13 Feb 2019 20:33:51 -0600 Subject: [PATCH 13/16] submit assessment --- TimesheetApp/.classpath | 6 + TimesheetApp/.gitignore | 1 + TimesheetApp/.project | 17 ++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ TimesheetApp/src/ConsoleUtils.java | 112 +++++++++++ TimesheetApp/src/Controller.java | 178 ++++++++++++++++++ TimesheetApp/src/Main.java | 9 + TimesheetApp/src/Timesheet.java | 82 ++++++++ TimesheetApp/src/TimesheetEntry.java | 91 +++++++++ 9 files changed, 507 insertions(+) create mode 100644 TimesheetApp/.classpath create mode 100644 TimesheetApp/.gitignore create mode 100644 TimesheetApp/.project create mode 100644 TimesheetApp/.settings/org.eclipse.jdt.core.prefs create mode 100644 TimesheetApp/src/ConsoleUtils.java create mode 100644 TimesheetApp/src/Controller.java create mode 100644 TimesheetApp/src/Main.java create mode 100644 TimesheetApp/src/Timesheet.java create mode 100644 TimesheetApp/src/TimesheetEntry.java diff --git a/TimesheetApp/.classpath b/TimesheetApp/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/TimesheetApp/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/TimesheetApp/.gitignore b/TimesheetApp/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/TimesheetApp/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/TimesheetApp/.project b/TimesheetApp/.project new file mode 100644 index 0000000..c5b5e8c --- /dev/null +++ b/TimesheetApp/.project @@ -0,0 +1,17 @@ + + + TimesheetApp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/TimesheetApp/.settings/org.eclipse.jdt.core.prefs b/TimesheetApp/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/TimesheetApp/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/TimesheetApp/src/ConsoleUtils.java b/TimesheetApp/src/ConsoleUtils.java new file mode 100644 index 0000000..5553163 --- /dev/null +++ b/TimesheetApp/src/ConsoleUtils.java @@ -0,0 +1,112 @@ +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Scanner; + +public class ConsoleUtils { + + /* Member variables */ + + private Scanner scanner; + private DateTimeFormatter timeFormatter; + + /* Constructor */ + + public ConsoleUtils(){ + scanner = new Scanner(System.in); + timeFormatter = DateTimeFormatter.ofPattern("MM/dd/yy HH:mm"); + } + + /* Methods */ + + /* + * Prints the menu of actions to the console + */ + public void printHelp(){ + System.out.println("Valid commands: "); + System.out.println(" list [PROJECT] [-a] list entries; project and/or active flag are optional"); + System.out.println(" add add an entry, and set the start time"); + System.out.println(" stop ID update the entry's end time"); + System.out.println(" delete ID delete entry with the ID"); + System.out.println(" help print help"); + System.out.println(" quit quit the app"); + System.out.println(); + + } + + /* + * Prints an informational message to the console + */ + public void info(String msg){ + System.out.println("["+msg+"]"); + System.out.println(); + } + + /* + * Prints an error message to the console + */ + public void error(String msg){ + System.out.println("[ERROR: "+msg+"]"); + System.out.println(); + } + + /* + * Prompts the user to enter input + * Returns the text entered by the user + */ + public String promptString(String label){ + System.out.print(label+" "); + return scanner.nextLine(); + } + + /* + * Prints a list of TimesheetEntry objects in a pretty table + */ + public void printList(List entries){ + int longestProject = 7; + int longestTask = 4; + + for(TimesheetEntry entry : entries){ + if(entry.getProjectName().length() > longestProject){ + longestProject = entry.getProjectName().length(); + } + if(entry.getTask().length() > longestTask) { + longestTask = entry.getTask().length(); + } + } + + String projectHeader = String.format("%"+longestProject+"s", "Project"); + String projectUnderline = ""; + for(int i=0;i "); + String[] actionParts = input.split(" "); + String action = actionParts[0].trim(); // Primary action + + // Figure out what to do depending on the user's primary action + if (action.equals("add")) { + + processAddAction(); + + } else if (action.equals("delete")) { + + processDeleteAction(actionParts); + + } else if (action.equals("stop")) { + + processStopAction(actionParts); + + } else if (action.equals("list")) { + + processListAction(actionParts); + + } else if (action.equals("quit")) { + + quit = true; + + } else if (action.equals("help")) { + + ConsoleUtils helper = new ConsoleUtils(); + helper.printHelp(); + + } else if(action.length() ==0 ){ + + // do nothing. + + } else { + + // Your code here + + } + } + + } + + /* + * The user requested that a given TimesheetEntry be stopped (marked as complete) + * This method conveys that request to the Timesheet + */ + public void processStopAction(String[] actionParts){ + + if(actionParts.length > 2){ + consoleUtils.error("Too many inputs to stop command"); + return; + } + + int id = Integer.parseInt(actionParts[1]); + + timesheet.stop(timesheet.get(id)); + } + + /* + * The user requested that a given TimesheetEntry be deleted + * This method conveys that request to the Timesheet + */ + public void processDeleteAction(String[] actionParts){ + + if(actionParts.length > 2){ + consoleUtils.error("Too many inputs to delete command"); + return; + } + + int id = Integer.parseInt(actionParts[1]); + + timesheet.delete(timesheet.get(id)); + } + + /* + * The user wants to view a list of timesheet entries + * This method conveys that request to the Timesheet, + * along with any special options (active-only, filter by project name) + */ + public void processListAction(String[] actionParts){ + + if(actionParts.length > 3){ + consoleUtils.error("Too many inputs to list command"); + return; + } else { + List entry = new ArrayList(); + if(actionParts.length == 2) { + if(actionParts[1].equals("-a")) { + entry = timesheet.list(true, null); + consoleUtils.printList(entry); + } else { + entry = timesheet.list(false, actionParts[1].toString()); + consoleUtils.printList(entry); + } + } else if (actionParts.length == 3) { + if(actionParts[1].equals("-a")) { + entry = timesheet.list(true, actionParts[2].toString()); + consoleUtils.printList(entry); + } else if(actionParts[2].equals("-a")) { + entry = timesheet.list(true, actionParts[1].toString()); + consoleUtils.printList(entry); + } + } else { + entry = timesheet.list(false, null); + consoleUtils.printList(entry); + } + + } + + + } + + /* + * The user wants to add a new entry to the Timesheet + * This method conveys that request to the Timesheet, along with + * the specified project name and task description + */ + public void processAddAction(){ + + String project = null; + + //implementing try catch to ensure user only enters one word + boolean oneWord = false; + while(!oneWord) { + try { + project = consoleUtils.promptString("Project Name (one word only):"); + verifyOneWord(project); + oneWord = true; + + } catch (Exception e) { + System.out.println("Program is throwing an exception: " + e); + System.out.println("Please enter only one word for project name."); + } + } + + String description = consoleUtils.promptString("Task:"); + timesheet.add(project, description); + + } + + //method that checks if user only enters one word it trims the string, and then checks if it contains a space + public static void verifyOneWord (String s) { + if(s.trim().contains(" ")) { + throw new IllegalArgumentException(); + } + } +} \ No newline at end of file diff --git a/TimesheetApp/src/Main.java b/TimesheetApp/src/Main.java new file mode 100644 index 0000000..e6e23e3 --- /dev/null +++ b/TimesheetApp/src/Main.java @@ -0,0 +1,9 @@ + +public class Main { + public static void main(String[] args) { + + Controller menuActions = new Controller(); + + menuActions.start(); + } +} diff --git a/TimesheetApp/src/Timesheet.java b/TimesheetApp/src/Timesheet.java new file mode 100644 index 0000000..c8124aa --- /dev/null +++ b/TimesheetApp/src/Timesheet.java @@ -0,0 +1,82 @@ +import java.util.List; +import java.time.LocalDateTime; +import java.util.ArrayList; + +public class Timesheet { + private List database; + + /** + * constructor initializes a new list of type arraylist + */ + public Timesheet() { + database = new ArrayList(); + } + + public void add(String project, String task) { + TimesheetEntry userTimesheet = new TimesheetEntry(project, task); + database.add(userTimesheet); + } + + /** + * when called + * @return the list array of current timesheet entries + */ + public List list(boolean activeOnly, String name){ + if(activeOnly && (name != null)) { + List activeProjectDatabase = new ArrayList(); + for (TimesheetEntry e : database) { + LocalDateTime listEndTime = e.getEndTime(); + if(listEndTime == null && (e.getProjectName().equals(name))) { + activeProjectDatabase.add(e); + } + } + return activeProjectDatabase; + } else if(name != null) { + List projectDatabase = new ArrayList(); + for(TimesheetEntry e: database) { + if(e.getProjectName().equals(name)) { + projectDatabase.add(e); + } + } + return projectDatabase; + } else if(activeOnly) { + List activeDatabase = new ArrayList(); + for (TimesheetEntry e : database) { + LocalDateTime listEndTime = e.getEndTime(); + if(listEndTime == null) { + activeDatabase.add(e); + } + } + return activeDatabase; + } else { + return database; + } + + } + + /** + * method that will return timesheet entry from id entry + * @param id is given + * @return the timesheet entry for that id + */ + public TimesheetEntry get(int id) { + if(database.get(id-1) != null) { + return database.get(id-1); + } else + return null; + + } + + /** + * deletes a timesheetentry + * @param entry to delete + */ + public void delete(TimesheetEntry entry) { + int entryDelete = database.indexOf(entry); + database.remove(entryDelete); + } + + public void stop(TimesheetEntry entry) { + entry.updateEndTime(); + } +} diff --git a/TimesheetApp/src/TimesheetEntry.java b/TimesheetApp/src/TimesheetEntry.java new file mode 100644 index 0000000..36ec94d --- /dev/null +++ b/TimesheetApp/src/TimesheetEntry.java @@ -0,0 +1,91 @@ +import java.time.LocalDateTime; + +public class TimesheetEntry { + private String projectName; + private String task; + private int id; + private LocalDateTime startTime; + private LocalDateTime endTime; + + private static int NEXTID = 1; + + //constructor that initializes timesheet + public TimesheetEntry(String myProject, String myTask) { + this.projectName = myProject; + this.task = myTask; + this.startTime = LocalDateTime.now(); + this.id = NEXTID; + NEXTID++; + } + + //getters and setters + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public String getTask() { + return task; + } + + public void setTask(String task) { + this.task = task; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public LocalDateTime getStartTime() { + return startTime; + } + + public void setStartTime(LocalDateTime startTime) { + this.startTime = startTime; + } + + public LocalDateTime getEndTime() { + return endTime; + } + + public void setEndTime(LocalDateTime endTime) { + this.endTime = endTime; + } + + public static int getNEXTID() { + return NEXTID; + } + + public static void setNEXTID(int nEXTID) { + NEXTID = nEXTID; + } + + /* + * + */ + public void updateEndTime() { + try { + checkEndTime(endTime); + if(this.endTime == null) { + endTime = LocalDateTime.now(); + } + } catch (Exception e) { + System.out.println(e); + } + + } + + public static void checkEndTime (LocalDateTime dt) { + if(dt != null) { + throw new IllegalArgumentException("The task has already ended."); + } + } + +} From 527f8d19a08a0db085b8269f627253ed3b71127d Mon Sep 17 00:00:00 2001 From: "Hauser, Matthew" Date: Wed, 27 Feb 2019 14:12:35 -0600 Subject: [PATCH 14/16] word guess game --- WordGuess/.classpath | 6 + WordGuess/.gitignore | 1 + WordGuess/.project | 17 + .../.settings/org.eclipse.jdt.core.prefs | 11 + WordGuess/src/WordGuessGame.java | 169 + WordGuess/words_alpha.txt | 370099 +++++++++++++++ 6 files changed, 370303 insertions(+) create mode 100644 WordGuess/.classpath create mode 100644 WordGuess/.gitignore create mode 100644 WordGuess/.project create mode 100644 WordGuess/.settings/org.eclipse.jdt.core.prefs create mode 100644 WordGuess/src/WordGuessGame.java create mode 100644 WordGuess/words_alpha.txt diff --git a/WordGuess/.classpath b/WordGuess/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/WordGuess/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/WordGuess/.gitignore b/WordGuess/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/WordGuess/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/WordGuess/.project b/WordGuess/.project new file mode 100644 index 0000000..5ebc43e --- /dev/null +++ b/WordGuess/.project @@ -0,0 +1,17 @@ + + + WordGuess + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/WordGuess/.settings/org.eclipse.jdt.core.prefs b/WordGuess/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/WordGuess/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/WordGuess/src/WordGuessGame.java b/WordGuess/src/WordGuessGame.java new file mode 100644 index 0000000..b25cea2 --- /dev/null +++ b/WordGuess/src/WordGuessGame.java @@ -0,0 +1,169 @@ +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Random; +import java.util.Scanner; + +public class WordGuessGame { + static String wordProgress = ""; + static String word = generateWord(); + + public static void main(String[] args) { + //prints initial word, should show as hidden + printWordProgress(); + + //prompt user to enter letter + System.out.println("Choose a lower-case letter."); + Scanner reader = new Scanner(System.in); + String chosenLetter = ""; + + + //keep prompting until user enters valid letter + //program will run until word is complete + while(!wordComplete()) { + boolean isLetter = false; + while(!isLetter) { + try { + chosenLetter = reader.nextLine(); + checkUserInput(chosenLetter); + isLetter = true; + //catch if user doesn't enter letter + } catch (IllegalArgumentException e) { + System.out.println("Please enter a letter."); + //catch if user enters same letter + } catch (IllegalStateException e) { + System.out.println("You've already entered that letter."); + } + } + playTurn(chosenLetter); + + } + + reader.close(); + + + } + + /** + * method run. tests letter + * @param chosenLetter given to test + */ + private static void playTurn(CharSequence chosenLetter) { + //check if word contains the letter + if(word.contains(chosenLetter)) { + System.out.println("you guessed right!"); + //loop through word + for(int i=0; i