├── .gitignore ├── data ├── day18.log └── day18.txt └── src ├── ArraysExercises.java ├── Bob.java ├── ConsoleExercises.java ├── ConsoleIoLecture.java ├── ControlFlowExercises.java ├── ControlStatementsLec.java ├── DungeonGame.java ├── HelloWorld.java ├── HighLow.java ├── MethodLecture.java ├── MethodsExercises.java ├── Person.java ├── ServerNameGenerator.java ├── StringExercise.java ├── StringLecture.java ├── SyntaxLecture.java ├── abstractClassesInterfaces └── McFranchise.java ├── arraysLecture ├── ArraysLec.java └── Dog.java ├── collections ├── ArrayLists.java ├── CollectionsLecture.java └── HashMaps.java ├── fileIo ├── FileReader.java ├── README.md ├── jolts.log └── jolts.txt ├── inheritanceLecture ├── AutoShop │ ├── Car.java │ ├── Chevy.java │ ├── Ford.java │ ├── Technician.java │ └── Toyota.java ├── Developer.java ├── Employee.java ├── JavaDeveloper.java ├── Manager.java └── Teacher.java ├── madlib ├── IoUtils.java ├── MadLib.java ├── MadLibAnswer.java ├── MadLibGame.java └── MadLibUtils.java ├── oopLecture ├── Arithmetic.java ├── Dog.java ├── DogHelper.java ├── OopLecture.java ├── Person.java ├── Post.java └── Student.java ├── shapes ├── Circle.java ├── CircleApp.java ├── Measurable.java ├── Quadrilateral.java ├── Rectangle.java ├── Shape.java ├── ShapesTest.java └── Square.java └── util ├── Input.java └── InputTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | *.iml 3 | .DS_Store 4 | out/* -------------------------------------------------------------------------------- /data/day18.log: -------------------------------------------------------------------------------- 1 | Successfully read the day18.txt file! 2 | -------------------------------------------------------------------------------- /data/day18.txt: -------------------------------------------------------------------------------- 1 | 9 * 8 + 2 + (4 * (2 * 2 + 9 * 2) * 9 * 3 * 8) + 8 * 5 2 | 8 * (9 + 5 + 5 * 6 + 8 * 3) * 5 * 7 * 4 + 9 3 | (9 + (2 * 6 + 7 * 5)) * (7 + 7 * 5 + (6 + 2 + 6) * (7 * 8 * 8 + 9)) + 4 * 2 4 | ((8 + 3 * 6 * 2) * 9 + 3) + 5 + 6 * 3 5 | 6 * (9 + 6 * (7 + 4 + 2 + 5 + 6) * 7 + 3 * (5 * 8 * 6 + 6 * 7 * 8)) + (8 * 8 + 4) + (5 * (2 + 9) * 8) * 4 * 2 6 | (8 * 6 + 8) + 6 * 8 * (9 * (6 + 8 * 3 + 8) + (7 * 9 * 6 * 3) * 3 + 8 * 4) 7 | 3 * 4 * 8 * 7 + (4 + 5 + 8 * (3 + 3 + 3 * 6) + 4 + (3 * 8 * 8 * 6)) + (8 + 8 * (4 + 2 + 5 * 8 + 9)) 8 | 8 * ((2 + 8 * 8 * 2 + 3) * 8 + 7 * 4) * (5 + 6) + 4 * 7 9 | 5 * (6 * 2 * 3 + 9) * (3 + 3 * (6 + 6 * 3) + 3 * 5 * 2) 10 | 5 * (7 + (2 * 7 * 2 * 6) * (9 * 7 + 8 * 7)) * 8 * 5 11 | 4 * (7 + 2 + (2 * 5 + 2 * 4 * 8)) 12 | 6 * 3 + (7 * 3) 13 | 8 * 9 + (3 + (3 * 5 + 3 * 8 * 8) + 8) + 3 14 | 2 * 3 + (4 + 7 + 2) 15 | 8 + 2 * 6 + 9 + 7 * (9 + (9 * 9) + 3 * (8 * 3 * 7) + 2 + (7 + 5 * 5 * 2 + 9)) 16 | 6 + 9 * (6 * 9 + 5 + 7) 17 | 3 * (5 + 5) 18 | (4 + 9 * 7 * 8 * (5 * 6 + 4 * 7)) * 6 19 | 5 + (3 * 7 + 5) 20 | (5 + 2 * (3 * 2 + 6 + 3)) + (2 * 7 * 9 * 2) * (8 * 3 * 5) 21 | 2 * ((3 + 7 + 4) * 4 + 3 * 3) + 4 + 2 22 | (8 * 3) * 5 * 9 + (7 + 8 + 4 * (2 * 8 + 8 * 3)) + 3 23 | 5 + (4 * 8) + 3 + 7 + 6 24 | 4 + 9 + 4 + 5 * 9 + (9 + 2 * 2 * (5 * 6) + 8) 25 | 9 + (5 + (6 + 6 * 4) * 8 * (7 * 9 * 3 + 8 * 3)) * 5 * 9 + 6 26 | 2 + 6 * 4 + ((9 + 8 + 6 + 9) * 7 + 2 + 5 * 3 + 3) * (9 * (5 * 4 + 4) + 3 * 7 + (6 + 4 * 9 + 5 + 4 + 5)) * 4 27 | 3 * 6 + 4 + (7 * (5 + 5 * 5) + (3 * 4 * 7 + 3) * 5 + 5 * 5) 28 | 8 + 8 * 7 + (6 + (9 + 2)) + 4 29 | 2 * 3 * (6 + (2 * 9) + 7 * 3 * 3 + 6) + 6 + 4 30 | 8 + 8 + 8 * ((7 + 5 + 9) * 6 + 9 + 9) 31 | (3 * 7) + 5 * (9 * 6) * 2 + (9 * 9) 32 | 7 + 8 + 6 + 6 * 4 * 2 33 | 6 * 3 + 5 * (4 * (6 + 3 + 5 * 9 * 8) * (4 + 7) * (2 * 6) + 3 * 9) * 9 34 | ((2 * 2 + 9 * 4) + 3 + (3 + 5)) * 6 + 8 * 9 35 | 4 + 6 + (3 * (2 + 2 + 2 + 2) + 6 + 9 + 3 + (5 + 9 + 9 + 6)) 36 | (5 + (3 * 7 * 7 + 7 * 2)) + (9 * 3 * 6 + 8 + 5 + 8) * 8 * 5 + 9 37 | 4 + 6 * 7 + (2 + 3 + 4 * 8 * (3 * 4 * 9 * 2 * 5 * 6)) + 9 38 | 4 + ((6 + 9) * 7 * (8 * 7 * 4 + 7 + 5 + 3) * 9 * 6) * 9 + (3 * (6 * 7 + 6 + 2 * 4) * 3 + (4 + 8 + 9 + 7 + 8 + 9) * 6 + (6 + 9 + 2 * 3)) * 7 39 | 6 * ((8 * 6 * 7 * 7 * 9 * 7) + (9 + 8 * 5 * 8) + 5 * (9 + 2 * 6)) 40 | 2 + 8 + 8 + 9 * (9 * (7 + 8 * 4 + 4 * 8 + 6)) 41 | 2 * 6 * 4 * ((2 * 2 * 6 * 7 + 3 * 8) + (7 + 8 + 7) * 4 + 9) + 7 * (4 + (5 + 7 * 9)) 42 | (6 * (5 + 6 + 3 * 5 + 4 + 2) + 9 * 2 * 6) + 2 * (8 * (6 * 3)) * 2 + 4 43 | 9 + 5 + 5 * ((3 * 3 * 8) * (2 * 9 + 7) * 4 + 4) * (3 + 6 * 5) 44 | ((9 * 8 * 8) * 4 * 6 * 7) + 4 + 4 + 2 * 7 * 8 45 | (5 * 4) + 6 * 3 + 8 * 2 46 | 7 * 8 * 2 + 2 * 7 47 | 2 * 2 * 9 + 4 * ((4 + 3 * 5 * 6 + 5 + 8) + 4 + 7 * 6 + (4 + 6 * 9 * 5 + 5)) + 3 48 | 3 + (2 * 3 * 9 * 7 * (5 + 6 * 6 * 5 + 4) + 7) 49 | (9 * 7 * 7 * (9 * 9) + 5 + 3) + 9 * 7 + 9 + 9 + (3 * 9 * 2 * 2 + 2) 50 | 7 + 3 + (4 * 6 + (5 * 6 * 2)) * 3 51 | 9 + (3 * (8 * 5 * 6 + 8)) * ((8 + 6 + 9 + 8 + 5 * 6) + 6) + 6 + 4 * 2 52 | 3 + 2 * 6 + 8 * 7 * (9 * 6 + 3 * 7) 53 | 4 * 9 + 4 + 7 + ((9 * 8) + 7 + 8 * 9 * 4) * 9 54 | (9 * 3 * 7 * 6 + 3) * 3 + 5 + (4 + 7 + 9) + 2 * 2 55 | 4 * 6 + ((6 + 5 + 3 + 8 + 7) + 5 + 6 + 2 + 5) * 3 56 | 6 + 3 * 6 + 8 * 2 + 6 57 | (6 + 6 * (8 * 8 + 7 * 8 + 2)) + 9 * (6 + (7 * 9) + (6 + 6 + 3) + 8 * 5 + 6) * 5 58 | 9 + 4 * (5 * 4 * 5 + 4 * (4 + 7 * 9) + 2) + (6 * 7 * (2 + 5 * 5 * 6) * 8) + 8 * 3 59 | 3 * 4 * 6 * 9 * 7 + ((9 + 9 + 2) + (8 * 2 + 9 + 2 + 5) * 9 + (9 + 7 * 5 * 3 + 7 + 8) + 4) 60 | (4 * 8 + 4 + 9 * 8) * 7 * 8 * 5 + 6 + 2 61 | 7 * (9 * (9 * 3 * 5) * 7 + 5 * 3 + 9) + 3 62 | (6 * (9 + 4) * 4 * (5 * 7 * 4 + 6 * 5)) * 2 + 9 + 5 63 | 4 + ((5 + 3 * 7 * 8 + 3) + (8 * 3 + 5 + 9 * 7 * 8) + 5 + 3 + (2 + 3 * 7 + 2) + 8) 64 | (2 * 4 * 7 * 2 + 7 * (3 + 8 + 9 + 7 + 9)) * 3 * (9 + (6 + 5 * 7 * 7) * 2 + (4 * 3 * 5 * 8 * 2 + 6)) * 6 + (8 + 6 + (9 * 6)) 65 | 4 * 9 + (8 * (6 + 5 + 7 * 8 * 7 * 3) + 9 * 8 * 5) + 5 66 | 2 * 6 + (5 * (6 * 9 * 8 * 9) * 3) + 4 + 8 67 | 2 * 8 68 | (8 * (4 + 6 + 5 + 3 * 5) + (2 * 5 * 8 * 9 + 3 + 6) * 2 * 6 * 2) * 3 + (8 + 6 * 2 + 4 + 7) 69 | ((6 + 4 * 8) * 3 * 5) * 3 70 | (7 * 8 + 5 + 5) * 8 + (5 * 7 * 8 * 9) * (8 + 6 + (3 + 9)) * 5 71 | 7 * (6 * (6 + 8 + 6) * 7 * 3 * 9 + (9 + 8 * 5 * 3 * 6)) + 5 + 5 72 | 3 + (6 * 3 + 7) * 4 73 | (7 + 8 + 3 + 5 * 2) + 2 74 | 4 + (7 * 7 * 3 + (6 + 6) * 8 + 6) + (4 * (9 + 7 + 5 * 4) * 2) * 6 * (2 * 3) + 4 75 | 2 * ((3 + 5 * 6 + 6 + 3 * 6) + 5) + 5 76 | 4 * 6 + (3 + 2 + 2 * 6 * 4 * 5) * 6 + (9 + 2 + 2 + (9 * 2 * 2 * 3 + 8) * (7 + 6 + 3 + 5)) + 8 77 | 4 * 3 * (6 + 8 + (6 + 2 + 4 * 7 * 7 * 6) * 9 * 7) * 7 78 | 8 * (8 * 2 + 8 + (3 * 2)) 79 | 5 + ((4 * 8) * (3 * 9 * 8 * 8) * 6 * 2 * 2 + 6) + 3 80 | 2 * 7 * 6 * (7 * 8 + 4 + 5) * (2 * 5) + 7 81 | 3 * 5 * (5 * 2 + 6 + 9 + 8 * 4) 82 | (3 + 3 + 8) + 3 * 8 + 6 83 | 2 * (9 * (2 * 2 + 4 * 2 + 8) * 5) * 4 84 | 3 * (2 + 5 * (3 + 4 * 6 + 4 * 5) + 2) * (4 + 8 * 2 * 9 * 7 + 6) + (6 * 4 * 6) * 5 85 | 8 + (5 * 6 * 4 * 8) * (4 * 2 + (2 * 6) * (5 * 9 + 8 + 7 + 2) + 9) + (3 + (8 * 6) + 2 * (5 * 4 + 9 + 7 + 3 * 3) + 9) * 9 86 | (3 + 4) + 5 * 6 + 4 * 7 + (2 + 3 + (5 * 9 + 8 + 2) + 6) 87 | (8 + 5 + 2) + (7 + 3 + 6 + 6 * 9) + 3 * 5 + ((3 + 7 + 3 * 2 * 6) + 6 + 6) 88 | (2 * 6) + 6 89 | 5 + (9 + 6 + 4 * 4 + 6 * (5 * 4 * 2 * 3)) * 8 * 6 90 | (2 + (4 * 5 * 2 + 4)) + 8 * 8 * 8 + 5 91 | 7 * 5 92 | 3 * 2 * 3 + (9 + 4 * 6) * ((3 * 4 + 9 * 5) * 2 + 5 * 6) 93 | (4 * 8 * (5 * 5) + (3 * 5 + 9 * 8 + 4 + 4)) * 5 + 4 * 6 94 | 5 * 6 * (5 * 3 * 3) + 6 * 5 95 | (6 + 4 + (6 + 5 * 6 + 8 * 9 * 9) + 4) + 4 * 5 + 9 + 5 96 | 4 + 2 * 4 * 2 * (5 * 4 + 9 * 8) 97 | 2 + (6 + (9 * 4 * 6 + 8 + 4 + 3) * 6 + (3 * 8 + 6 + 2 * 4) + (4 * 4 * 2 * 8)) 98 | 8 + (2 + 5 * 6 * 7) + (5 * 3 * 6 * 5 + 8) 99 | 7 * 6 * 9 * 8 + (2 + 7) 100 | (2 + 7 + (6 + 5 + 7 * 4 + 7)) + 4 101 | ((7 * 5 + 8 + 2 + 7) + 9 * 2) + 3 + 8 + (9 + 7 + 8 * 6 * (5 + 3 * 5 + 6)) 102 | 8 * 5 + (8 + (7 + 4 * 9 + 2)) + 2 + (7 + 2) * 7 103 | 9 + 4 * 9 + (9 * 6 + 2 * 6 + 5 + (4 * 9 * 6 * 7 + 5 + 8)) * (7 + 4 * 5 * (4 * 8 * 4 * 7) * 6) * 4 104 | 3 * 5 + (2 * 9 + (2 * 5 * 5) * 5 + 8) 105 | 3 * 9 * (8 + 6 + (9 + 2 + 2 + 8 + 4) * 6 + 7 * 3) * 2 106 | 2 + 8 * 7 + (4 * 4 * 5) * 7 * 9 107 | 5 + 9 * 6 * (4 + 9 + (8 * 7 * 9) + 9 * 9) + 6 + 8 108 | 9 * 6 + 9 * (3 * 8 + (9 * 9 * 8 + 2 + 3 * 6) + 5 * 6) * 7 109 | 4 + 6 + (2 + 2) + 7 * (9 + 3 * 5 * (3 + 3 + 8 + 3)) * 9 110 | 3 * ((2 + 4) * 7 * (2 * 3 * 8 * 6 * 7) + 4 + 3) + 7 111 | 9 + 3 + 4 * 8 * 5 + 9 112 | 8 + (4 * 4 + (7 * 5 * 7 + 2) + (9 * 3)) * (2 * 9 * 9 * (6 + 7 * 8 + 9 + 6 + 3) + 3 * (3 * 9 + 7 + 6 + 5 + 8)) + 5 * (5 + (4 + 2 + 8) + (9 * 7 * 4) + 3) * 8 113 | (4 * 8 + 7 * 6 + 5 + 6) * (3 * 6 + 7 + (2 * 3 * 5)) + 4 * 4 * 5 114 | 2 * 6 + 4 * 7 115 | 6 + 8 * 7 * ((5 + 4 * 2 + 7 + 7 + 8) + 9 * 7 * 5) * 3 + (6 + 2) 116 | (6 + 3 * 8) * 4 * 3 117 | 3 * 2 + 8 + (4 * (5 + 2 * 5 * 6) + 3 * 6) 118 | 8 * (4 * 3 + 8 * 5) * 3 * 8 + 8 119 | 5 * 4 + (3 + (2 + 6 * 8 + 3) * 4 * 3 * 6 + 4) + (8 + 6 + 2 * 3) * 4 120 | ((5 + 8) * (6 * 6 + 4 * 8 + 7) + 7 * 3 + (9 * 5 + 9) * (7 * 9)) + 7 + 7 + ((9 + 7 * 4 + 9) + 3) 121 | (9 * 9 + 4) + (3 * 2 * 6 + 6 * 8) 122 | ((3 * 6 + 9 * 9) + 6 * 4) * (9 + 6 + 9 * 2) * 8 * 8 123 | 2 + 8 * (9 * 6 * 5) * 6 * 8 + 9 124 | (6 + 6 + 7) + 7 125 | 8 + 7 * 9 + (9 + 5 + (5 * 5 + 2 * 9 * 8 * 6) + 6 + (4 + 6 * 8 * 2 + 2 + 9) + (5 + 8 + 9 + 4)) 126 | 3 + (7 + 9 * 2 + 6 * 6) * 2 + 5 127 | 3 * 5 + 5 * 6 + (4 * 7 + 6 + 9 * 8 + 7) * 8 128 | 5 + 5 + (5 * 8 + 5 * (4 + 5) + 4) 129 | (4 * (7 + 2 * 4 + 3 + 2 + 2)) * 2 + (4 + 3) 130 | (3 * 3 * 2 * 7 + 6 * (6 * 5 + 9 + 5)) * 4 + 3 * 7 * (4 + 2 * 2 + 8 + 7 * 4) + 7 131 | 6 * 4 + 8 * 7 * (9 * 4 * 6 * (4 * 7 * 7 * 4) * (5 * 2 * 4)) 132 | 4 * 8 * (4 * 2 + 3 * 6) + (8 * 4) + 8 133 | 9 + 5 + 3 + ((3 + 2) + 8 + 5 * 5 + 3) * 5 134 | 4 * ((6 + 6 * 2 * 8) * 9 * (4 + 5 * 8) * 9 * 7 * 2) + 6 135 | 6 * 5 * 2 * 2 * 7 136 | 6 * 6 + (8 * 4 * 5) + 9 137 | 3 * ((9 * 5 + 2 + 3 * 9 + 8) + 2 + (8 * 4 + 8 + 7 * 5) + 7) * 8 + 6 138 | 4 + (2 + 7 + 7 + 2 * 7) 139 | 2 + 3 + (2 + 5 + (3 + 4 + 7 + 5 * 9) * 3) * 8 * 5 * 9 140 | 4 * ((8 + 9 * 4 + 2 * 9) * 9 + 6 * 4 + (3 * 9)) * 3 + 6 + 3 141 | 4 + 4 * (5 * 2 + 6 + 6) + 6 142 | ((5 + 6 * 7 * 2) + 7 * 7 + 9 + 7 * 8) + (9 * 5 + 4 * 5 * 7 * 8) * 3 * 2 143 | 2 * 6 + 6 * (2 + 7 * 3 * 3 + 9 * 2) * 6 144 | (4 * 5 * 2 * 5 * 4) * 6 + (2 + 3) * 2 * 9 + (8 * 6 * 7 + 8) 145 | (3 * 6 + 3) + ((4 + 4 * 3) + 5 + 8 + 8) + 5 146 | 8 * 4 + 3 + (8 * 2) + ((2 + 6 * 3 + 8) * 2 + 4) + 3 147 | 5 * 7 * (6 * 5) * 8 + 9 * 9 148 | 9 * (4 + 8 * 8) * (5 + 7 + 6 + (3 + 2 + 7 + 4)) * ((2 + 8) + 6 * (3 * 3 * 5) + 5) 149 | 6 + (5 * (2 + 6 + 8 * 2 * 7 * 3) * (6 + 8) * 9 + 6) 150 | (9 * 7) * 2 * 6 + 2 + 4 + 6 151 | 3 + 9 * 6 + 4 * (3 * 4) * 5 152 | (8 * 3) + (9 * (3 * 6 + 5) * 9 + 9) + (4 * 3 * 5) + 6 153 | 6 + 3 * (4 + 2 * (2 * 5 + 7 * 2) * (2 + 2 + 5 + 2 * 7 + 7)) * 5 * 9 * 9 154 | 9 * ((5 + 3 + 3 + 5) + 8 * 8 + (9 + 3 * 4 * 7 * 3 + 7) + 7 * 8) * 3 * 6 + 2 + 3 155 | 6 * (7 + 9) + (2 * (7 * 3 + 5) * (6 * 5) * 7) * 6 156 | (5 * 8 + 7 * 5 + 5 * 6) * (3 * 6 + 8) * 8 157 | 4 + ((5 * 6 * 5) * 9 * 2 * 3) * 4 * (2 + 9 + 3 + 6) 158 | (2 + 4 * 2 * 5 + 3) * 9 + ((5 * 8 + 9 * 2 + 3 * 6) + 4 * 4) + 6 + 4 + 7 159 | ((2 + 4) * 3 * 3 + 4 + 3) + 8 * 3 + 4 160 | 7 * (7 + 5 + 7) + 7 * 3 * (8 * 7 * 7) 161 | ((9 + 8 * 6) + 3 * 2 * 5) * 2 * 4 * 9 162 | ((3 * 2 + 2 + 3 + 9) + 8 * 3) * 9 + 8 + 3 + 4 163 | 6 * 4 * 6 + 3 * (3 + 5 + (7 + 8 + 4 + 7 + 6) + 5 * 2 + 7) 164 | ((5 + 5 * 2 + 3) * 7) + 6 + (8 * 3 * 9 + (3 * 9 * 5 + 7 * 4)) * 9 * 8 * 6 165 | (3 + 2 + 2 * 7 + 8 + 8) * (9 + 3) * 8 * 8 166 | 9 * (9 + (2 + 6)) * 2 * 7 167 | 6 * 4 + 2 * (9 + (6 * 2 * 7 * 6) * 7 + 8 + 3) 168 | 5 * 9 + 8 + (9 * 3) + 9 169 | 6 + ((5 * 6 + 6) + (4 * 3 + 3 + 4 * 5 + 4)) 170 | 4 + 6 + 7 * 7 * (2 * 7 * (9 * 4 * 9) + 2 * 5) 171 | (2 + 5) + 9 + 3 + 9 172 | ((7 + 6) * 4 + 6) + 3 * (4 + 4 * 8 + 6 + (7 * 3 + 4 * 9) + (4 + 6)) + 3 * 9 173 | (2 + (8 * 8 + 9 * 8 * 6) * 2 * 3 * 2 + 6) + 6 * 5 * 8 * 6 + (7 * 9 + 6) 174 | 2 + 4 * 8 + (9 * 9 + 3) + (2 * (4 + 4 * 7) * 3 + 6 * 9) * 5 175 | 7 + 7 * 6 * 8 176 | 8 * (7 + 4) + 7 * 8 * 5 + 3 177 | 8 * 3 + (6 + 7 + 2 * 3 + 5) * 3 178 | (7 + 3 + (6 * 5 * 5 * 2 + 5 + 8)) * 8 + 2 + 8 + 5 + 3 179 | ((5 * 9 + 6 * 2 * 7 * 6) * 7 * 5) + ((4 * 3) * 4 * 2 + (8 + 4 * 8 + 4) + (8 + 7 + 3 * 6)) * 6 + 8 + 9 * 5 180 | ((9 * 3 * 3 * 6 + 4 * 3) + (7 * 5 * 9) * 7 * 7 + 2) * 9 181 | 9 * 7 + 4 * (8 * 2 + 5 * (5 + 6) + 8 + 6) * 3 + 5 182 | ((5 + 3) * 5 + 6 + 8 + 5 + 3) * 8 * 6 * 5 * (6 + 8 + 3 * 8) 183 | (4 * 3 * 7 + 6 * 6 + (4 * 5 + 6 + 5 + 8)) + 6 + 7 + 4 + 4 * 5 184 | ((6 + 8 + 5 + 7 * 7 * 6) * (7 * 9 * 4 * 6)) + 5 * 4 * 9 185 | ((9 * 2 * 7 * 7) * 7 * (4 + 9 * 9 * 2 + 6 * 5) + 4 + 2 * 8) + 9 * 7 186 | (4 * 5 + 7 + 3) + 8 187 | 7 + 9 + 4 * 2 + 9 188 | (9 * (4 + 2 * 9 + 5 * 5 * 3)) * 2 * 5 189 | 8 + ((6 * 3 + 4) * 4 + 4 * 9 + 3) * 9 * 6 + 4 + 6 190 | (6 * 4 * 8 + 7 * 5 + 4) * 8 + (5 * 4 * 2 * 3) * 5 191 | 3 + 2 * (8 + 2 * 3 + 3 + (5 + 8 + 4 * 8 * 5)) * (4 * 6 + 8 + 9 * 8) 192 | 2 + 7 + 3 * 6 * 8 * (6 + (3 * 4 * 5 + 4)) 193 | (8 + 3 * 7 * (4 + 6 + 8 * 4 + 8 * 8)) + (9 * 9 * 2 * (3 + 4 * 4 * 8 + 3 + 8) + 6) 194 | ((8 * 9 + 2 * 8) * 5 + 6 + 3 * 3) + 3 * 7 195 | 4 + (2 + (6 * 5 * 3) * 2 + 2 * (3 + 7) * 9) 196 | (5 * 4 * (6 + 4 + 9 + 5) * 4) + 4 * 3 * 4 * ((9 * 6 + 9 + 8 * 8 + 6) * 2 * 7 * 4) * 2 197 | 6 * 6 * (7 + 2 * (8 * 4 + 4)) + 7 * (9 * 6 * (5 + 6 + 2 + 2) + (9 * 4 * 5 * 5 * 5 + 6) * (6 * 6 * 5 * 6 + 8) + 5) 198 | 5 * (4 + (7 + 7 * 9 + 5) * 5 * 9) * 3 199 | 2 + (8 * 6 * 7 * 8 * 6 + 2) * 3 200 | 4 * (9 * 3 * 9 + 3 + 9 * 8) + 3 + (9 + 8 + 4 * 8) 201 | 4 * ((2 + 9 * 7 * 6 * 4 + 9) + 5 * 6 + 7) 202 | (5 + (2 + 3 * 4 + 7) + (4 + 6) + 6) + 9 * 7 + 5 * (7 + 5 * (8 * 7 * 3 + 2 * 4) + 4) + 7 203 | 4 + 4 + (8 + 9 * (9 + 4 * 9 * 4 + 8 + 8) + 3 + 2 * 8) 204 | 5 * (5 + 5 * 3 * 2 + 2 + 3) * (5 + 3 * 8 + 9 + 8 + 7) * 2 205 | 8 + (3 * 9) + ((5 + 7 + 6 + 9) * 8 * 4 + (8 * 3 + 9 * 4 * 3)) + 4 * 4 * (3 + 3 * 7 * 6 * 2 + 7) 206 | 6 * (6 * 4 * 3 * 2) + 8 * 9 * (2 + 5 + 6) 207 | 4 + (8 + (3 + 2 + 6) * 5 + 2 * 7 + 9) + 5 + 4 + 3 * 4 208 | 2 + 4 * ((5 * 4 * 2 + 8) + (5 + 4 + 6 + 9) + 7 * 2 + (4 * 4 + 3 * 6 + 3)) * 6 209 | ((7 + 5 + 6 + 6 * 7) * 6 * 6 + (7 + 6 * 3 * 9) + 4 + 9) * 4 * 8 * 3 210 | 8 * 3 + 7 + 2 * (8 + 7 + 5 + (9 * 4)) * 6 211 | 8 + 3 + (3 + 5 * 6 + 5 + 6 + 3) + 3 * 9 + (2 + 6) 212 | 5 * 4 * (4 * 5 * 6 * 5) + (8 + 7 * 3) + 6 213 | (5 + (7 + 4)) * 2 * (4 + 7 * (2 * 7 * 9) * (6 + 5 * 7 * 4) * 3 * 7) * (6 + 8) * 2 * (4 + (8 * 7 * 9) * 3 + (4 + 5 + 7 + 6 + 9)) 214 | ((2 + 2 + 5 + 8 * 7) + (9 + 6 + 4 + 7) + (7 + 3 + 7 * 7 * 2 * 6) * 6) + 8 215 | 5 + (3 + 6) * 2 + (4 + (3 + 7) * 6 + 8 * 5 * 5) * (2 * 4 * 3) * 7 216 | (4 * 5 * 3 * 8 + 6) + 9 * 2 217 | (2 * 2 * 6 + (7 * 5 + 2 + 4 + 3) + 4) + 3 218 | 9 + 4 + 4 + 6 + 4 219 | 9 + 9 * 9 220 | 6 + 6 + 4 + ((9 * 8) + 3 + 5 + 6 + 6 + 5) + (7 * 6 + 7 + 7 * 8) + (7 * 7 + 7 * 2) 221 | (2 * (4 + 2 * 4) * 7) + 5 * 8 * 7 * (5 * 3 * 5) * 6 222 | (5 + 5 + 5 + 3 + 2) + (9 * 9 + 3) * 6 223 | (5 + 2 + 2) * 5 * 7 * (9 + 6) * ((9 * 4 + 8) * 2) 224 | ((9 * 8 + 9) * 6 + 6) * 6 + 7 * 7 225 | 5 * (9 * 9 * 7 + 2 + 4) * 9 * 8 + 4 * ((4 * 5 + 9) + (9 * 6 + 9 * 8) * 4) 226 | 4 * (7 + 7 + (4 + 6 + 4)) * (6 + 5 * 2 + 5 + 3 + 4) 227 | (4 * 5) + 4 * 4 228 | 4 * 8 * 9 + 4 + 3 * ((9 * 6) * 6 + 3 * (8 * 8 + 2)) 229 | 3 * 7 + 7 * (5 + 5 * 8 * 9) * 7 230 | 5 + (7 + 4) * 6 * 7 231 | 7 * (2 + 2 + 5 + (6 * 6 + 5)) + 7 * 3 + (4 + (6 * 4) * 6 * 9) * 6 232 | 6 * (6 + 9 + 4 * 7) * 8 * 9 233 | ((3 * 6 + 8 + 5) * 9) * 7 + 6 * 8 + 2 * 3 234 | (8 + 9 + 5 + 9 + 5 * (2 + 6 * 3 * 5 + 8 + 8)) + 7 * 7 + (3 + 2 * 4 + 3) + 5 235 | 7 + 7 * 6 + 9 236 | 5 + (3 + 3 + 4 + (8 * 3 * 2)) + 6 * 5 + 8 237 | (3 * 6 + (2 + 2 + 9) * (3 * 2 + 2 * 3 * 8 * 6) + 5) + 3 + 2 + 4 238 | 2 + 6 * ((4 * 8) + 3 + 4 + 4 * (5 * 6 * 4 * 6 * 4) + 9) * 7 * (9 + (6 * 2) + 8 + 8) + (3 + 2) 239 | 8 + (2 + 6) * 3 + 4 + (7 * 4 * 9) 240 | 9 + (7 + 4 + (4 * 9 * 2 + 7 + 7) * (9 + 2 + 7)) * 3 + 3 + 4 + 7 241 | 9 * 5 + 5 + 5 * (2 + 7 + (3 * 2 * 4)) + 3 242 | 9 + 4 + 2 + ((5 + 7 + 6 + 2) + 2) * 8 243 | 7 + ((5 + 2 * 5) + 6 + 6 + 5 * (6 * 8) + 5) * 4 + 4 244 | 4 + (3 + 5 * 4 + 8 * 3 * 4) * 8 * 4 245 | 5 * (6 * 4 * 9 + 4 + (6 + 8 * 8 * 5)) + (6 * 9 + 2 + 6) * ((6 * 6 + 8 + 7) + 7 + 5 * 7) 246 | 2 * 2 + 8 * 8 * 6 + (3 * 6 + (4 * 8 + 4 * 9 * 5 + 6)) 247 | 9 + (9 + 3 * 4 * 7 + 3 + 5) * (6 + 8 * 3 + 2) + 6 + 2 248 | 9 + 5 + 7 * ((9 + 9 * 5 * 8 * 5 + 3) * 8 + (8 * 8 * 5) * 4 * 2) + 3 + 8 249 | 9 * 2 + 8 * 7 250 | 6 + (5 * 6 + (5 * 9 * 2 + 4 * 3 + 2) + 8) + (3 + 4 + 9 + 9 + 5) + 3 + 8 251 | (5 + 4 * (6 * 5 * 7 * 9 * 3) + 6 * 7 + 9) + 6 * 4 + 3 * 6 * 9 252 | (5 + 2 + 2 + 2 * 9 * 3) + 8 + 2 253 | 3 + (8 + 6) * 7 254 | (8 + 9) + 6 + (2 + 4) * 5 + (5 + 6 * 8) * 3 255 | (6 * 2 + (4 + 2 * 2 + 3 * 9 + 8) * 8) + (7 + 5 + (4 * 5 + 7 * 7) + 2 * 8 + (4 + 6 * 6 * 2)) 256 | (8 + 7 * 5 * 4 * 2) * 9 + 5 + 6 + 8 257 | 3 * 7 * (6 * 8 + 6 * (3 * 2 * 4 + 9 * 3 * 3)) + 5 258 | 8 * (6 + (5 * 6) * 8 * 3 + (2 + 9)) 259 | (3 + 9 + 8 * 7) + 3 * 7 * (6 * (6 + 3) * 7 + (9 * 4) + 7 + 6) 260 | 4 * 3 * (3 * 8 * 7 * 8 * 4 * (8 + 2)) * (7 * (4 * 4 * 5 * 7 + 4) + 6 + 4) + 8 261 | (2 + 3) * ((3 * 8) + 2 * 2 + 8 * 8) * (9 + 6) + 2 262 | 4 * 6 + ((2 * 4 * 2 + 6 * 9) + 6) * 9 263 | 9 * 8 * (2 * 7 + 6 * 7 + (8 + 8 * 4 + 9 * 7 + 6)) * 5 * (5 * (5 + 6 + 2) + (3 * 6 * 8 + 9 * 5)) 264 | 2 + 2 * (4 + 5 * (9 + 5 * 3 * 3) + 7 * 7 + 6) * 2 265 | 2 + ((3 + 8 + 6 + 7) * 4 + 8 * 8 + 8) * (4 + 4 * 7 + 2 * 9 * 5) + 7 266 | 8 * (7 + 6 * 7) * 2 * 5 + (9 + 5 + 9 + 9 * 6) + 9 267 | 3 + (4 + (2 + 9 + 4 + 4 * 3 * 7) * (5 + 9 * 5 + 5)) + 2 * 7 * 4 + (2 * 4) 268 | 4 * (2 * (2 + 5) * 9 + 5 + 5 * 3) * (2 * 4 + 4 * (3 + 6 + 2)) 269 | 6 + ((8 + 4) * 3 * 8) 270 | (9 * (8 + 3 * 2 * 9 * 7) + 9 + 5 + (8 * 8 + 8 * 5 * 3 * 4)) * (9 + 5 + 4 * 9) + 3 271 | 2 * 8 + (8 * 4 + 2) * (5 * 5 + 6 + (6 * 4 * 4 * 4 * 3)) + 2 272 | 7 * 4 * (7 * (3 * 4 + 3) + 8) + 9 + 2 * (6 + 7 + (5 + 4 * 2 + 4) * 6) 273 | 5 + (9 * (5 * 7 + 6)) * 4 * 2 274 | 6 + 7 * (8 + 6) * 8 * ((4 + 7 * 5 + 2 * 3) + (2 * 3 * 5 * 6 + 9)) + 9 275 | 6 * (2 + 5 + (8 * 6 * 5 * 4 + 7 * 9) * 8 + 2) + 8 + 5 + 5 276 | 2 + 7 + 8 + (3 + (5 * 6 + 6) + 9) * 3 + (7 * (7 + 6) * 9 * (4 + 5 + 3 + 3) + 4) 277 | 7 * 8 + 2 + 3 + ((7 + 3 * 4 * 3 * 2 + 9) * (6 * 2) * 4 + 6 + 3) * 6 278 | 3 + 4 + 5 279 | (4 + 4 * 3 * 2 * 6) + (9 * 3) 280 | 3 + (9 * 8 * 2 + 7 * 6) + 7 + (3 + (3 * 4 * 2) + 3 * (2 + 3 * 4 * 5 * 4 * 6) * 2) * (6 + 4 * 9) + 5 281 | 7 + (7 * 4 * (9 + 8 + 2 + 2 * 5) + 2 * (4 * 3 + 7 * 8) * 9) * (3 * 9 * 2 * (7 * 8 * 4 + 8 + 5 * 6)) * 3 282 | ((6 + 4 + 5 * 5) * 5 * 2 + (2 + 2) + 9 + (4 * 3 + 9)) + 7 283 | 2 + 2 * 4 + (4 * 9 * 7 * (9 * 8 * 6 * 7)) 284 | 6 + 4 285 | 7 + (3 * 4 + 2) * 8 + 7 * 4 286 | 7 + 4 + 8 + (9 + 7 * 4 * 8 * 4) + 4 * 8 287 | 5 + 8 * 3 * ((8 * 9) * 2 + 6 * (2 + 5 * 8 + 3 * 9) * 4) + 9 + 8 288 | 8 + 6 + 6 289 | 6 * 6 * 6 290 | 6 + 9 + 5 * ((3 * 8 + 6) + 8 * 7 + 3 + 7 + 6) + 2 291 | 4 * 9 + 3 + 8 * ((2 + 2) * 5 * 3) 292 | 6 * (4 + 7 + 4) * 5 * 7 * 7 + 6 293 | 6 + 7 + (6 + 6) * (3 * (8 * 8 * 4 * 4 + 3 * 9) + 2 + 5 + 8) + 5 * 6 294 | 8 * 8 + (9 * 9 * (2 * 3) + 2 + 6) * (5 * (4 + 9 * 5 + 2 + 4 + 7)) 295 | 9 + 5 + 7 * (4 * (4 + 4 * 4 + 7 * 7) * 9 + 6 * 5 * 3) * 5 * 9 296 | (6 + 8 + 4 + 8) + 6 + 9 + ((6 + 4 * 9 * 9) + (6 * 6 + 7 + 9 * 2) * 7) * 5 * 9 297 | 8 + ((7 * 8) + 5 + 6) * 4 * 7 * 9 298 | (6 + 2 + 2 * 3 * (8 * 6) * (5 * 9 * 6)) + 9 * (4 + 3 + (5 * 2) * 2 + 3 + 6) 299 | 4 * 8 + 7 * ((5 + 4 * 6) + 5 + 3) + 3 + 4 300 | 3 + (6 * (8 + 8) * 9) * 4 + 4 * (5 * (9 * 3 * 7 * 4) * (4 + 6 * 8 * 8 * 4) * 8) * 3 301 | 7 * 3 * 4 * 5 * 7 + (3 + 7 + (3 * 5 * 3 * 3 + 3) + 6) 302 | (5 + 5 * 4 + 5 + 7) + (8 + 7 + 8 + 2 + 3) 303 | (9 + 8 + 8 + 3 * 2 + 5) + 4 + (8 * 5 + 3 + 9 * 8) + (7 * 4) + 5 * 2 304 | (5 * 9 * 2 * 9) + 5 * 8 + 4 305 | 9 * 3 * 9 + (9 + 3 + 2) 306 | 4 * 5 * 7 + (7 * 6) + 6 + 9 307 | (3 + 8) + 4 + (7 + 2 * 9) * 7 * 8 + 4 308 | 8 + 3 + 4 + 6 * ((6 + 7 * 4 + 6) + 6 + 3 + 9 * 6) 309 | (4 * 8) * (9 + (2 + 4 * 6 + 4 + 8)) * 3 + 9 * 4 + 8 310 | 5 * 4 + (9 + (2 * 8)) + 9 * 2 311 | 9 * 2 + (3 * 2 + 5 + (3 * 8 + 5 * 2 * 5 + 6) * 5 + 8) * 7 * 2 312 | 8 + (3 * 5 + 2 * 7 + 8 * 2) 313 | 5 + (4 * 7 + 2) + (5 + 8 * 5 + (4 * 9) + (3 + 3)) 314 | ((4 * 5 * 8 + 6 + 8) * 9 * 3 + 4) * 8 + 9 * 7 315 | ((6 * 6 + 5 * 4 + 2 + 4) * 7 + 5 + 9 * 8) * 5 + 9 316 | 5 + (9 + 5 * 9 + 6 * 3) * ((3 * 6) * 2 + 8) + 3 317 | ((6 + 5) * 5 * 6 * 9 * 8) + 3 * 7 318 | (8 * 6 + (5 + 5) + 4) * 7 + 3 + 8 319 | 4 + (2 * 3 * 8 + 3 + 3) * 8 320 | 2 * (7 + 6 + 2 + 3) * 8 + 2 + 2 * (4 * 3 * 5 * 8) 321 | 6 * (8 + (3 * 6 + 8 + 8 + 6) * 9) 322 | ((8 * 3 + 2) * 6 * 2 * (5 + 6 * 2 * 8)) + 8 323 | 6 + (6 * 5 + (5 * 9) * (6 * 5 + 8 * 2 + 5)) * (8 * (3 * 3 * 5) + 9) * 7 324 | (7 + 6 + 2 * 5) + 2 + 6 325 | (8 * 7 * (6 * 4 + 6 * 3) * 6) + 4 * 5 * (5 * (2 * 2 * 9) * 4 + (2 * 6 * 5) + 9 + 9) 326 | ((3 * 2) + 7 + 6 + 4 * 9) + 4 + 2 + 7 + (4 * (7 * 9 * 2) * 3) 327 | (3 * (5 * 9 + 9 + 9 * 9)) + (9 + (4 * 4 * 6) * 9) + 9 * 7 + 4 * 9 328 | 4 + (6 * 6) * (9 * 8) * 9 + (6 + 7 * 5 + (2 + 9)) 329 | (8 + (5 + 7)) + 7 * 8 * 9 + 9 330 | 8 + 4 + 6 * (5 * 3 + 8 + 7) * 6 * 3 331 | 3 + 9 + 6 + (2 + 8 + (8 + 5 * 5) * 4 + 4 * 8) * 9 * 3 332 | (4 + 4 * 3 + 4) * 8 * 4 + 4 + 6 333 | 2 * (3 * 6) + (4 + 3 * 8 + 5 + (6 * 5 * 2 + 5 + 2 * 9)) 334 | 4 * 3 + (7 + 7 * 3 * 5 * 4 * 4) + (8 + 5 * 8) * (2 * 4) + 8 335 | (4 * 9 * 6 + 6) * (6 * (8 + 4 * 9)) + 6 + ((4 + 2 * 9) * (3 + 3 + 6 + 3) + 9 * 9 + 8 * 7) 336 | 2 * 5 + 5 * (8 + 4 * 3 + (7 + 6) * 7 + 3) * 8 337 | ((3 * 4 + 4 * 9) * 6 + 7 * 4 + 7 * 2) * 7 * (7 + 9 + 6 * 8) + (3 * (6 * 6 * 9 * 7 + 4) * 5 * 2 + 3 + 4) * 8 338 | (5 + 6 + 9 + 3 * 3 + (2 + 8 + 5 + 3)) + (2 * 5 + 6 * 9 * 6) * 2 + 9 * ((5 * 9) + 8 * 8 * (7 * 4 * 3 * 4 * 4 * 7)) 339 | 2 + 8 + 4 + 7 * ((8 + 7 + 8 * 3) + 9 * 2 + 6 + 3) + 6 340 | 4 * (8 * 8 * 4) * 9 + (7 + 7 + 2 * 2) * 6 + 8 341 | 3 + (6 * 4 * 6 + 3 * 9 + 3) * 7 + 3 + 4 342 | 3 * 4 343 | (4 * 6 * 4) + 3 + 7 + 6 * 9 + 7 344 | 3 * (6 + 8 * 4 * 2) + 5 + 5 * (4 + 6 + 2 + 6) 345 | (5 + 2 + 4 * 2 * 2) + (5 + 5 * 5 * 3) + 3 * (4 + 9 + 6 * 6 + 2) 346 | ((6 + 9) * 6 + (3 + 7 * 4 + 2 + 5 * 6) + 3 + 5 * 2) * (2 * (5 * 9 + 9) * 5) + 8 347 | 9 * 8 * 9 * 8 348 | 6 * 8 * 4 * 4 + 4 * 4 349 | ((8 * 7 * 6 * 3) + 7 * 2 * 6 * (4 + 6 * 5 * 9 * 5) * 8) * (3 * (4 * 6 + 8 + 2 + 6 * 2) + (2 * 4 + 4 * 7 + 3 * 5) * 9 + 9 + 8) 350 | (3 * 5 * 7 * 4 + (4 + 6 + 6 + 9 * 6 * 3) * 5) * 6 351 | (4 * 4 * 5 * 8 * (3 + 4) + 7) + 6 + 4 + (8 + 3) 352 | 9 * 7 + 8 + 2 * 3 * (3 + (2 * 3 * 7 * 5 * 9) + 8 * 9 * 5) 353 | ((3 * 6) + 3 + 9) + 7 * 8 * 3 * 9 354 | 8 * 4 * (6 * 9) * 3 355 | 9 + ((5 + 3 + 4 * 3 * 9 * 6) * 6 + 9 + 3 + 8 * (5 + 4 + 7)) + 9 * 4 356 | (4 + 6 * 3 + 2 * 9) * (6 * 9 * 4 + 7) + 8 + 8 + 6 357 | (5 * 3 * 6 * 3) * 7 * (5 + 6 * 6 * 5) 358 | 4 * 6 * 8 + ((4 + 7 + 6) * 4 + (4 * 7)) * 8 359 | 6 + ((4 * 9 + 6 + 5 * 5 * 7) * 5 * 3) + 7 360 | (8 * 4 + 8 + 9 * 9) + (5 * 6 + 3 + 6 * (9 + 8 * 7 * 6 * 8 + 6) + 5) * 9 + (6 + 6 * 2 + 2 * 4 + 8) * 5 * (8 + 5 + 2 + 3) 361 | (8 * 2 + (7 * 9) + 8) + 3 362 | 2 + 9 * 6 + 5 * (3 * 7 + 8) + 3 363 | ((9 * 2 * 5) + (9 + 8 + 8 * 9) * 7 * 7 + 9) + 2 + 8 + 3 + (5 + 7) 364 | 5 + 9 + 5 * 4 + 3 + 5 365 | 4 + 9 * (6 * (7 + 7 + 9 * 3) * 5 + 3 * 3) 366 | 2 + 8 + 6 * 8 * (4 + (9 * 8) * 2) + 2 367 | 3 + 7 368 | 8 + 7 + 8 * (5 + 7 * 9 * 9 * 8) 369 | 6 + (3 + (5 * 3) + (9 + 6 * 9) * 4 + 8) 370 | 7 * 2 + (5 * 6 + 2 + 6 * 3 + (9 + 7 + 7 * 8 + 9 * 7)) * 8 * 7 * 7 371 | (6 + 3 * 5 * 6) + (2 * 2 * 5) + 8 * 3 * 3 + 5 372 | (2 * 8 + 6 * (6 + 3 * 2 + 7 * 7 + 6) * 5 + 5) * 3 373 | (6 * 9 + (5 + 9 * 8) + 2 * (6 * 8 * 8 + 6 + 3) * 7) * (7 + 3 * 5) 374 | 4 * 2 + 8 * 9 + 3 375 | 8 * ((5 * 2 * 5 + 9 + 4) * 4 * 2) * 8 + (3 + 2 + 3 * 7 * 8 + 5) + 4 376 | 9 * 9 * 5 377 | 3 * 2 * 8 * (6 + 5 * 9 + 6) -------------------------------------------------------------------------------- /src/ArraysExercises.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | public class ArraysExercises { 4 | public static void main(String[] args) { 5 | 6 | int[] numbers = {1, 2, 3, 4, 5}; 7 | // System.out.println(numbers); // just a pointer to location in memory 8 | System.out.println(Arrays.toString(numbers)); 9 | 10 | 11 | Person[] people = new Person[3]; 12 | people[0] = new Person("Vivian"); 13 | people[1] = new Person("Sophia"); 14 | people[2] = new Person("Justin"); 15 | 16 | for(Person person : people){ 17 | System.out.println(person.getName()); 18 | } 19 | 20 | Person[] newArray = addPerson(people, new Person("Casey")); 21 | 22 | for(Person person: newArray){ 23 | System.out.println(person.getName()); 24 | } 25 | 26 | } 27 | 28 | public static Person[] addPerson(Person[] pplArray, Person personToAdd){ 29 | Person[] tempArray = Arrays.copyOf(pplArray, pplArray.length+1); 30 | tempArray[tempArray.length-1] = personToAdd; 31 | 32 | return tempArray; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Bob.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Bob { 4 | public static void main(String[] args) { 5 | 6 | // Create a class Bob for the following exercise with a main method. Bob is a lackadaisical teenager. In conversation, his responses are very limited. 7 | // Bob answers 'Sure.' if you ask him a question. 8 | // He answers 'Whoa, chill out!' if you yell at him. 9 | // He says 'Fine. Be that way!' if you address him without actually saying anything. 10 | // He answers 'Whatever.' to anything else. 11 | 12 | Scanner sc = new Scanner(System.in); 13 | System.out.print("What will you say to Bob? "); 14 | String userResponse = sc.nextLine().trim(); 15 | System.out.println(userResponse); 16 | 17 | if (userResponse.endsWith("!")) { 18 | System.out.println("Whoa, chill out!"); 19 | } else if (userResponse.endsWith("?")) { 20 | System.out.println("Sure"); 21 | } else if (userResponse.equals("")) { 22 | System.out.println("Fine. Be that way!"); 23 | } else { 24 | System.out.println("Whatever."); 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/ConsoleExercises.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | import static java.lang.Integer.parseInt; 5 | import static java.lang.Float.parseFloat; 6 | 7 | //In Java EVERYTHING is an Object 8 | 9 | 10 | public class ConsoleExercises { 11 | public static void main(String[] args) { 12 | System.out.println("Console exercises!"); 13 | double pi = 3.14159; 14 | 15 | System.out.printf("The value of pi is approximately %.2f.\n", pi); 16 | 17 | Scanner sc = new Scanner(System.in); 18 | 19 | // System.out.println("Please enter an integer"); 20 | // int number = sc.nextInt(); 21 | // sc.nextLine(); 22 | // 23 | // System.out.println("Please enter 3 words"); 24 | // String word1 = sc.nextLine(); 25 | // String word2 = sc.nextLine(); 26 | // String word3 = sc.nextLine(); 27 | // 28 | // System.out.printf("Your three words are %s \n %s \n %s.\n", word1, word2, word3); 29 | // sc.nextLine(); 30 | // 31 | // System.out.println("Give me a sentence please"); 32 | // String someSentence = sc.nextLine(); 33 | // System.out.printf("%s? What is that?", someSentence); 34 | 35 | // CALCULATING PERIMETER AND AREA 36 | 37 | System.out.println("Please enter the length of the classroom."); 38 | int length = parseInt(sc.nextLine()); 39 | 40 | System.out.println("Please enter the width of the classroom."); 41 | int width = parseInt(sc.nextLine()); 42 | 43 | int area = length * width; 44 | int perimeter = (2*length) + (2*width); 45 | 46 | System.out.printf("The area of the classroom is: %d\n", area); 47 | System.out.printf("The perimeter of the classroom is: %d\n", perimeter); 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/ConsoleIoLecture.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ConsoleIoLecture{ 4 | public static void main(String[] args) { 5 | /* *************************************** 6 | print() and println() 7 | ****************************************/ 8 | 9 | // >> this: 10 | // System.out.println("here"); 11 | // System.out.println("there"); 12 | 13 | // >> is equivalent to this: 14 | // System.out.print("here2\n"); 15 | // System.out.print("there2\n"); 16 | 17 | 18 | // >> without the newline characters, print outputs this: 19 | // System.out.print("here"); 20 | // System.out.print("there"); 21 | 22 | 23 | // >> to concatenate, just like JS: 24 | // System.out.println("Hello" + " " + "World"); 25 | 26 | 27 | /* *************************************** 28 | printf()/.format 29 | ****************************************/ 30 | 31 | //TODO TOGETHER: Print a formatted string using the following... printf(formatString, data) 32 | 33 | 34 | 35 | // System.out.printf("Hello%n"); 36 | // System.out.printf("World"); 37 | // 38 | 39 | 40 | String name = "Vivian"; 41 | 42 | // System.out.printf("Hello %s%n", name); //Hello Vivian 43 | // System.out.printf("Hello %S%n", name); //Hello VIVIAN 44 | 45 | 46 | 47 | 48 | 49 | //TODO TOGETHER: 50 | // (1) Create a string variable 51 | // (2) print using printf() with placeholder %s 52 | 53 | 54 | 55 | // TODO: print using printf() with placeholder %S 56 | // this results in capital letters! 57 | 58 | 59 | 60 | //TODO: Remove the %n from the first printf. What do you notice? 61 | // There was not a new line. All the words were on the same line 62 | 63 | // >>>> Multiple Variables 64 | 65 | 66 | //TODO TOGETHER: 67 | // (1) Create 2 variables - int and string 68 | // (2) Print using printf() and placeholders 69 | // note: d : decimal integer [byte, short, int, long] 70 | 71 | 72 | // int three = 3; 73 | // String typeOfPet = "cats"; 74 | // 75 | // System.out.printf("I have %d %s.%n", three, typeOfPet); 76 | 77 | 78 | 79 | 80 | //TODO: 81 | // (1) Print using printf(), multiple variables, and placeholders 82 | 83 | 84 | 85 | // >>>> Currency 86 | 87 | 88 | // %f => float/double formatting 89 | //We can control the precision of the decimal using .___ 90 | 91 | //TODO TOGETHER: 92 | // (1) Create int variable currencyPennies 93 | // (2) Print variable using currency formatting 94 | 95 | // int currencyPennies = 1000; 96 | // System.out.printf("I'll sell you land for $%.2f an acre!%n", currencyPennies/100.00); 97 | 98 | 99 | 100 | 101 | 102 | /* *************************************** 103 | USER INPUT 104 | ****************************************/ 105 | // The Scanner class allows us to get data input that the user enters into the console. 106 | // Scanner Docs ==> http://www.cs.utexas.edu/users/ndale/Scanner.html 107 | 108 | 109 | Scanner userInput = new Scanner(System.in); 110 | 111 | 112 | 113 | // >>>> .next() method 114 | // .next() captures each input usually signified by whitespace. The input is returned as a string 115 | 116 | // System.out.println("Please enter your first, middle, and last name."); 117 | // String firstName = userInput.next(); 118 | // String middleName = userInput.next(); 119 | // String lastName = userInput.next(); 120 | // 121 | // 122 | // System.out.println(firstName); 123 | // System.out.println(middleName); 124 | // System.out.println(lastName); 125 | 126 | 127 | 128 | // >>>> .nextInt() method 129 | // .nextInt() captures the first valid int value 130 | 131 | // System.out.println("Please enter your age."); 132 | // int age = userInput.nextInt(); 133 | // System.out.println(age); 134 | 135 | 136 | // >>>> .nextLine() method 137 | // .nextLine() Returns the rest of the current line 138 | // System.out.println("Enter your favorite quote"); 139 | // String quote = userInput.nextLine(); 140 | // System.out.println(quote); 141 | 142 | 143 | 144 | 145 | 146 | /* ****************** NOTE ******************** 147 | *Quirk of using next() then nextLine()... 148 | *https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo 149 | * 150 | *That's because the Scanner.nextInt method does not read the newline character in your input created by hitting "Enter," 151 | *the call to Scanner.nextLine returns after reading that newline. 152 | *You will encounter the similar behaviour when you use Scanner.nextLine() after Scanner.next() 153 | *or any Scanner.nextFoo method (except nextLine itself). 154 | */ 155 | 156 | // Scanner sc = new Scanner(System.in); 157 | // System.out.print("Please enter your favorite number: "); 158 | // int num = sc.nextInt(); 159 | // System.out.println(num); 160 | // System.out.print("Please enter your favorite words: "); 161 | // String words = sc.nextLine(); 162 | // System.out.println(words); 163 | 164 | 165 | } 166 | } -------------------------------------------------------------------------------- /src/ControlFlowExercises.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ControlFlowExercises { 4 | public static void main(String[] args) { 5 | int i = 5; 6 | 7 | while(i <= 15) { 8 | System.out.print(i); 9 | System.out.print(" "); 10 | i += 1; 11 | } 12 | 13 | // int counter = 0; 14 | // 15 | // do{ 16 | // System.out.println(counter); 17 | // counter += 2; 18 | // }while(counter <= 100); 19 | 20 | // int counter = 100; 21 | // 22 | // do{ 23 | // System.out.println(counter); 24 | // counter -= 5; 25 | // }while(counter >= -10); 26 | 27 | long start = 2L; 28 | do{ 29 | System.out.println(start); 30 | start *= start; 31 | }while(start < 1000000L); 32 | 33 | // for (int i = 100; i >= 0; i -= 2) { 34 | // System.out.println(i); 35 | // } 36 | 37 | // long i; 38 | // 39 | // for (i = 2L; i < 1000000L; i *= i) { 40 | // System.out.println(i); 41 | // } 42 | 43 | 44 | // Fizz - 3 45 | // Buzz - 5 46 | // FizzBuzz = 15 47 | // for(i = 0; i <= 100; i += 1){ 48 | // if(i % 15 == 0){ 49 | // System.out.println("FizzBuzz"); 50 | // } else if(i % 5 == 0){ 51 | // System.out.println("Buzz"); 52 | // } else if(i % 3 == 0){ 53 | // System.out.println("Fizz"); 54 | // } else { 55 | // System.out.println(i); 56 | // } 57 | // } 58 | 59 | Scanner sc = new Scanner(System.in); 60 | 61 | boolean userContinues = true; 62 | 63 | do { 64 | System.out.print("What number would you like to go up to? "); 65 | int userInt = sc.nextInt(); 66 | System.out.println(); 67 | System.out.println("Here is your table!"); 68 | System.out.println(); 69 | System.out.println("number | squared | cubed"); 70 | System.out.println("------ | ------- | -----"); 71 | for (i = 1; i <= userInt; i += 1) { 72 | System.out.format("%-7d", i); 73 | System.out.print("|"); 74 | System.out.format(" %-8d", i * i); 75 | System.out.print("|"); 76 | System.out.format(" %-9d", i * i * i); 77 | System.out.println(); 78 | } 79 | System.out.print("Would you like to enter another number (y/n)? "); 80 | String userResponse = sc.next(); 81 | if (!userResponse.equalsIgnoreCase("y")) { 82 | userContinues = false; 83 | } 84 | } while (userContinues); 85 | 86 | boolean anotherGrade = true; 87 | do { 88 | System.out.print("Please enter a numerical grade from 0 to 100 "); 89 | 90 | int numericGrade = sc.nextInt(); 91 | 92 | if (numericGrade >= 88) { 93 | System.out.println("A"); 94 | } else if (numericGrade >= 80) { 95 | System.out.println("B"); 96 | } else if (numericGrade >= 67) { 97 | System.out.println("C"); 98 | } else if (numericGrade >= 60) { 99 | System.out.println("D"); 100 | } else { 101 | System.out.println("F"); 102 | } 103 | System.out.print("Do you wish to enter a new grade? (y/n) "); 104 | String userResponse = sc.next(); 105 | if (!userResponse.equalsIgnoreCase("y")) { 106 | anotherGrade = false; 107 | } 108 | } while (anotherGrade); 109 | 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/ControlStatementsLec.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class ControlStatementsLec { 3 | public static void main(String[] args) { 4 | // ==================== Boolean Expressions 5 | 6 | // no >== ,or <==, or === because only value comparisons are available 7 | // truthy and falsy values don't exist in Java 8 | 9 | int randomNumber = 6; 10 | System.out.println(randomNumber == 6); 11 | 12 | char randomChar = 'Y'; 13 | System.out.println(randomChar == 'y'); 14 | 15 | int newNumber = 3; 16 | int otherNumber = 3; 17 | System.out.println(newNumber == otherNumber); 18 | 19 | 20 | // ==================== Logical Operators 21 | 22 | // && will only check second value if first is true 23 | // & will check both 24 | // this can be used to check what would otherwise result in a syntax error 25 | // same comparison process for || and | 26 | 27 | // x will only increment in second condition if first condition is true using && 28 | // int x = 2; 29 | // int y = 3; 30 | // 31 | // if (false & ++x == y) { 32 | // System.out.println("Equal"); 33 | // } else { 34 | // System.out.println("Not equal");; 35 | // } 36 | // System.out.println(x); 37 | 38 | 39 | // ==================== Strings 40 | 41 | // DO NOT COMPARE STRINGS WITH == !!!! 42 | 43 | Scanner sc = new Scanner(System.in); 44 | String cat1 = sc.nextLine(); 45 | String cat2 = "CAT"; 46 | System.out.println(cat1); 47 | System.out.println(cat2); 48 | System.out.println(cat1.equalsIgnoreCase(cat2)); 49 | 50 | // do use equals(), 51 | 52 | boolean stringValuesAreEqual = "Test".equals("Test"); 53 | System.out.printf("The result is: %s", stringValuesAreEqual); 54 | 55 | 56 | // or use equalsIgnoreCase() 57 | 58 | //String hello = "hello"; 59 | //System.out.println(hello.equalsIgnoreCase("HeLlO")); 60 | 61 | // does not equal 62 | 63 | //String tech = "tech"; 64 | //System.out.println(!tech.equalsIgnoreCase("tool")); 65 | 66 | 67 | 68 | // ==================== Switch Case 69 | 70 | // basically the same as JS :) 71 | 72 | 73 | String caseSwitch = "Fred"; 74 | switch (caseSwitch) { 75 | case "bob": 76 | System.out.println("Case 1"); 77 | break; 78 | case "fred": 79 | System.out.println("Case 2"); 80 | break; 81 | default : 82 | System.out.println("Default case"); 83 | break; 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/DungeonGame.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; 2 | import java.util.Scanner; 3 | 4 | public class DungeonGame { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in).useDelimiter("\n"); 7 | 8 | System.out.println("Welcome to the Dungeon!"); 9 | System.out.println("==================================="); 10 | 11 | /* 12 | Let's create a boss to defeat. 13 | - a variable to store the enemyName 14 | - a variable to store its maxHealth 15 | - a variable to store its enemyAttackDamage 16 | */ 17 | Random rand = new Random(); 18 | 19 | String enemyName = "Grandma Terl"; 20 | int enemyMaxHealth = rand.nextInt(100); 21 | String enemyAttack = "Book 1:1"; 22 | int enemyAttackDamage = 15; 23 | 24 | 25 | 26 | /* 27 | Now let's create our player. 28 | - a variable to store heroName ask for user input. 29 | - a variable to store health 30 | - a variable to store attackDamage 31 | - how many healthPotions should we have? 32 | - how much health should the potion restore? 33 | */ 34 | System.out.println("Hello hero, what is your name?"); 35 | String heroName = sc.next(); 36 | int myHealth = 100; 37 | int attackDamage = 20; 38 | int healthPotions = 3; 39 | int healthPotionHeal = 30; 40 | 41 | System.out.println("Do you accept the challenge," + heroName + "?"); 42 | String answer = sc.next(); 43 | 44 | if(answer.equalsIgnoreCase("yes")){ 45 | System.out.format("Then, you must defeat %s\n", enemyName); 46 | System.out.println("ENEMY STATS\n============================"); 47 | System.out.format("Health: %d\n", enemyMaxHealth); 48 | System.out.format("Attack: %s\n", enemyAttack); 49 | System.out.format("Damage: %s\n\n\n", enemyAttackDamage); 50 | 51 | System.out.println("YOUR STATS\n============================="); 52 | System.out.format("Health: %d\n", myHealth); 53 | System.out.format("Damage: %d\n", attackDamage); 54 | System.out.format("# of Potions: %d\n", healthPotions); 55 | System.out.format("Potion effects: + %d health\n\n", healthPotionHeal); 56 | } 57 | System.out.println("Ready to start?"); 58 | String start = sc.next(); 59 | 60 | if(start.equalsIgnoreCase("yes")){ 61 | System.out.println("What would you like to do?"); 62 | do{ 63 | System.out.println("1. Push your code\n2. Drink potion\n3. Run?"); 64 | int action = sc.nextInt(); 65 | if(action == 1){ 66 | System.out.format("You attack %s! You deal %d damage.\n", enemyName, attackDamage); 67 | enemyMaxHealth -= attackDamage; 68 | if (enemyMaxHealth < 0) { 69 | enemyMaxHealth = 0; 70 | } 71 | System.out.format("Enemy Health: %d\n", enemyMaxHealth); 72 | }else if(action == 2){ 73 | System.out.println("You drink the potion! +30 health."); 74 | }else if(action == 3){ 75 | System.out.println("You can't run!"); 76 | }else{ 77 | System.out.println("That is not an option please try again"); 78 | } 79 | 80 | if (enemyMaxHealth == 0 || enemyMaxHealth < 0){ 81 | System.out.printf("You have defeated %s%n", enemyName); 82 | } 83 | }while(enemyMaxHealth > 0); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/HelloWorld.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | 3 | public static void main(String[] args) { 4 | // // ============================ SYNTAX, TYPES, VARIABLES EXERCISE 5 | // 6 | // // Create an int variable named myFavoriteNumber and assign your favorite number to it, then print it out to the console. 7 | // int myFavoriteNumber = 7; 8 | // System.out.println(myFavoriteNumber); 9 | // 10 | // // Create a String variable named myString and assign a string value to it, then print the variable out to the console. 11 | // String myString = "Hello"; 12 | // System.out.println(myString); 13 | // 14 | // // Change your code to assign a character value to myString. What do you notice? 15 | // myString = 'h'; // ERROR 16 | // System.out.println(myString); 17 | // 18 | // // Change your code to assign the value 3.14159 to myString. What happens? 19 | // myString = 3.14159; // ERROR 20 | // 21 | // // Declare an long variable named myNumber, but do not assign anything to it. Next try to print out myNumber to the console. What happens? 22 | // long myNumber; 23 | 24 | // // Change your code to assign the value 3.14 to myNumber. What do you notice? 25 | // myNumber = 3.14; // ERROR 26 | // 27 | // // Change your code to assign the value 123L (Note the 'L' at the end) to myNumber. 28 | // myNumber = 123L; 29 | // 30 | // // Change your code to assign the value 123 to myNumber. 31 | // myNumber = 123; 32 | // 33 | // // Why does assigning the value 3.14 to a variable declared as a long not compile, but assigning an integer value does? 34 | //// Longs can only hold integers 35 | // 36 | // // Change your code to declare myNumber as a float. Assign the value 3.14 to it. What happens? What are two ways we could fix this? 37 | // float myNumber = 3.14F; // ERROR 38 | // // use F after the number or explicit casting 39 | // 40 | // 41 | // // Copy and paste the following code blocks one at a time and execute them 42 | 43 | // int x = 5; 44 | // System.out.println(x++); 45 | // System.out.println(x); 46 | // 47 | // int x = 5; 48 | // System.out.println(++x); 49 | // System.out.println(x); 50 | // 51 | // 52 | // // What is the difference between the above code blocks? Explain why the code outputs what it does. 53 | // 54 | //// the difference between pre and post increment 55 | // 56 | // // Try to create a variable named class. What happens? 57 | // 58 | // // ERROR unexpected identifier 59 | 60 | // Object is the most generic type in Java. You can assign any value to a variable of type Object. What do you think will happen when the following code is run? 61 | 62 | // String theNumberThree = "three"; 63 | // Object o = theNumberThree; 64 | // int three = (int) o; 65 | // error caught at runtime 66 | 67 | // How is the above example different from the code block below? 68 | // int three = (int) "three"; // error caught during compilation 69 | // 70 | // // Rewrite the following expressions using the relevant shorthand assignment operators: 71 | // 72 | // int x = 4; 73 | // x += 5; 74 | // 75 | // int x = 3; 76 | // int y = 4; 77 | // y *= x; 78 | // 79 | // int x = 10; 80 | // int y = 2; 81 | // x /= y; 82 | // y -= x; 83 | 84 | 85 | 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/HighLow.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class HighLow { 4 | public static int numberOfGuesses; 5 | public static int gameNumber; 6 | 7 | public static void main(String[] args) { 8 | initGame(); 9 | } 10 | 11 | public static void initGame() { 12 | boolean programRunning; 13 | boolean gameRunning = true; 14 | Scanner sc = new Scanner(System.in); 15 | System.out.println("Welcome to the High / Low Guessing Game!"); 16 | do { 17 | gameNumber = randomWithRange(1, 100); 18 | System.out.println("The random number is: " + gameNumber); 19 | do { 20 | gameRunning = runRound(sc); 21 | } while (gameRunning); 22 | programRunning = getYesOrNo(sc).equals("y"); 23 | } while (programRunning); 24 | System.out.println("Good bye!"); 25 | } 26 | 27 | public static boolean runRound(Scanner sc) { 28 | boolean gameNotWon = false; 29 | System.out.print("Please enter a guess: "); 30 | int playerGuess = getInteger(1, 100, sc); 31 | if (playerGuess == gameNumber) { 32 | System.out.println("GOOD GUESS!"); 33 | gameNotWon = false; 34 | } else if (playerGuess > gameNumber) { 35 | System.out.println("LOWER"); 36 | numberOfGuesses++; 37 | gameNotWon = true; 38 | System.out.println("Number of guesses made: " + numberOfGuesses); 39 | } else { 40 | System.out.println("HIGHER"); 41 | gameNotWon = true; 42 | numberOfGuesses++; 43 | System.out.println("Number of guesses made: " + numberOfGuesses); 44 | } 45 | return gameNotWon; 46 | } 47 | 48 | public static int randomWithRange(int min, int max) 49 | { 50 | int range = (max - min) + 1; 51 | return (int)(Math.random() * range) + min; 52 | } 53 | 54 | 55 | public static int getInteger(int min, int max, Scanner sc) { 56 | if (!sc.hasNextInt()) { 57 | System.out.println("Not a number!"); 58 | return getInteger(min, max, sc); 59 | } 60 | int userInput = sc.nextInt(); 61 | if (userInput >= min && userInput <= max) { 62 | return userInput; 63 | } else { 64 | System.out.println("Number not in range!"); 65 | return getInteger(min, max, sc); 66 | } 67 | } 68 | 69 | public static String getYesOrNo(Scanner sc) { 70 | String userChoice; 71 | do { 72 | System.out.println("Do you wish to play again? [y/n]: "); 73 | userChoice = sc.next().trim(); 74 | } while (!userChoice.equalsIgnoreCase("y") && !userChoice.equalsIgnoreCase("n")); 75 | return userChoice; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/MethodLecture.java: -------------------------------------------------------------------------------- 1 | public class MethodLecture { 2 | 3 | /* 4 | 5 | Lecture Outline: 6 | 7 | - Defining Methods (parts of a method) 8 | - Method Parameters 9 | - Calling methods 10 | Method Overloading 11 | Recursion 12 | */ 13 | 14 | 15 | // public static void printCohortName(String name) { 16 | // System.out.println(name); 17 | // } 18 | 19 | // public static void main(String[] args) { 20 | 21 | // printCohortName("Luna"); 22 | // printCohortName("Jupiter"); 23 | // printCohortName("Apex"); 24 | // 25 | 26 | // // ------ DEFINING AND CALLING METHODS WITH VARIOUS INPUTS 27 | // sayGreeting(); 28 | // sayInput("Howdy"); 29 | // int x = returnSeven() + returnSeven(); 30 | // System.out.println(returnSeven() + returnSeven()); 31 | 32 | // System.out.println(returnInt(3)); 33 | 34 | // System.out.println(returnAge(3)); 35 | 36 | 37 | // returnProductOfThreeNums(2.4, 8.7, 9); 38 | // 39 | // 40 | // // ------ OVERLOADING 41 | // sayHello(); 42 | // sayHello(10); 43 | // sayHello("John"); 44 | // sayHello("Salutations", "Kevin"); 45 | // 46 | // 47 | // 48 | // // ------ RECURSION 49 | 50 | // countTo100Loop(1); 51 | // countTo100(1); 52 | // soutHello(); 53 | 54 | // } 55 | 56 | // ----------- DEFINING AND CALLING METHODS WITH VARIOUS INPUTS (examples) 57 | 58 | // no input or returned output 59 | // public static void sayGreeting() { 60 | // System.out.println("Hello"); 61 | // } 62 | 63 | // no returned output with input 64 | // public static void sayInput(String input) { 65 | // System.out.println(input); 66 | // } 67 | 68 | // returned output without input 69 | // public static int returnSeven() { 70 | // return 7; 71 | // } 72 | 73 | // return output given an input 74 | // public static int returnInt(int someInt) { 75 | // return someInt; 76 | // } 77 | 78 | // public static String returnAge(int age) { 79 | // return "The user age is: " + (age * 2); 80 | // } 81 | 82 | // return type based on multiple inputs 83 | // public static double returnProductOfThreeNums(double num1, double num2, double num3) { 84 | // int x = 5; 85 | // int y = 6; 86 | // String z = "bob"; 87 | // return num1 * num2 * num3; 88 | // } 89 | 90 | 91 | // ----------- OVERLOADING 92 | 93 | 94 | // public static String sayHello() { 95 | // return "hello"; 96 | // } 97 | // 98 | // public static void sayHello() { 99 | // System.out.println("hello"); 100 | // } 101 | 102 | // public static void sayHello(int times) { 103 | // for (int i = 0; i < times; i += 1) { 104 | // sayHello(); 105 | // } 106 | // } 107 | // public static void sayHello() { 108 | // sayHello("Hello", "World"); 109 | // } 110 | // public static void sayHello(String greeting) { 111 | // System.out.println(greeting); 112 | // } 113 | // public static void sayHello(String name) { 114 | // sayHello("Hello", name); 115 | // } 116 | // public static void sayHello(String greeting, String name) { 117 | // System.out.println(greeting + ", " + name + "!"); 118 | // } 119 | 120 | 121 | 122 | // public static double sayHello(double x) { 123 | // return x; 124 | // } 125 | 126 | // ----------- RECURSION - where a method invokes itself 127 | 128 | // public static void soutHello(int num) { 129 | // if (num > 10) { 130 | // return; 131 | // } 132 | // System.out.println("hello"); 133 | // soutHello(num + 1); 134 | // } 135 | // 136 | // public static void helloLoop() { 137 | // for (int i = 0; i < 10; i += 1) { 138 | // System.out.println("hello"); 139 | // } 140 | // } 141 | // 142 | // public static void main(String[] args) { 143 | // soutHello(1); 144 | //// helloLoop(); 145 | // } 146 | 147 | 148 | 149 | // public static void countTo100Loop(int num) { 150 | // for (int i = num; i <= 100; i += 1) { 151 | // System.out.println(i); 152 | // } 153 | // } 154 | // 155 | // public static int countTo100(int num) { 156 | // System.out.println(num); 157 | // return num == 100 ? num : countTo100(++num); 158 | // } 159 | // 160 | // public static int powerOf10(int n) { 161 | // if (n == 0) { 162 | // return 1; 163 | // } 164 | // return powerOf10(n-1) * 10; 165 | // } 166 | // 167 | 168 | 169 | } 170 | 171 | -------------------------------------------------------------------------------- /src/MethodsExercises.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class MethodsExercises { 4 | public static void main(String[] args) { 5 | // System.out.println(add(2.5, 2.5)); 6 | // System.out.println(subtract(2, 2)); 7 | // System.out.println(multiply(2, 2)); 8 | // System.out.println(divide(2, 10)); 9 | // System.out.println(modulus(100, 2)); 10 | // System.out.println(newMultiply(3, 3)); 11 | // System.out.println(recursiveMultiply(3, 3, 0)); 12 | 13 | // Scanner sc = new Scanner(System.in); 14 | //// userInteractionFactorial(sc); 15 | // int userInt = getInteger(1, 5); 16 | // System.out.println(userInt); 17 | // 18 | 19 | 20 | } 21 | // 22 | //// Exercises 23 | // 24 | //// 25 | //// Basic Arithmetic 26 | //// 27 | //// Create four separate methods. Each will perform an arithmetic operation: 28 | //// 29 | //// Addition 30 | //// Subtraction 31 | //// Multiplication 32 | //// Division 33 | //// Each function needs to take two parameters/arguments so that the operation can be performed. 34 | //// 35 | //// Test your functions and verify the output. 36 | //// 37 | //// Add a modulus function that finds the modulus of two numbers. 38 | //// 39 | //// Food for thought: What happens if we try to divide by zero? What should happen? 40 | //// 41 | // 42 | public static double add(double num1, double num2) { 43 | return num1 + num2; 44 | } 45 | public static double subtract(double num1, double num2) { 46 | return num1 - num2; 47 | } 48 | public static double multiply(double num1, double num2) { 49 | return num1 * num2; 50 | } 51 | public static double divide(double num1, double num2) { 52 | return num1 / num2; 53 | } 54 | public static double modulus(double num1, double num2) { 55 | return num1 % num2; 56 | } 57 | // 58 | // 59 | //// Bonus 60 | //// 61 | //// Create your multiplication method without the * operator (Hint: a loop might be helpful). 62 | // 63 | // public static double newMultiply(double num1, double num2) { 64 | // double total = 0; 65 | // for (int i = 0; i < num2; i += 1) { 66 | // total += num1; 67 | // } 68 | // return total; 69 | // } 70 | // 71 | // 72 | //// Do the above with recursion. 73 | // 74 | // public static double recursiveMultiply(double num1, double num2, double total) { 75 | // if (num2 > 0) { 76 | // return recursiveMultiply(num1, num2 - 1, total + num1); 77 | // } else { 78 | // return total; 79 | // } 80 | // } 81 | // 82 | // 83 | //// Create a method that validates that the user input is in a certain range 84 | //// 85 | //// The method signature should look like this: 86 | //// 87 | //// 88 | //// public static int getInteger(int min, int max); 89 | //// and is used like this: 90 | //// 91 | //// 92 | //// System.out.print("Enter a number between 1 and 10: "); 93 | //// int userInput = getInteger(1, 10); 94 | //// If the input is invalid, prompt the user again. 95 | //// 96 | //// Hint: recursion might be helpful here! 97 | // 98 | public static int getInteger(int min, int max) { 99 | Scanner sc = new Scanner(System.in); 100 | if (!sc.hasNextInt()) { 101 | System.out.println("Not a number!"); 102 | return getInteger(min, max); 103 | } 104 | int userInput = sc.nextInt(); 105 | if (userInput >= min && userInput <= max) { 106 | return userInput; 107 | } else { 108 | System.out.println("Number not in range!"); 109 | return getInteger(min, max); 110 | } 111 | } 112 | // 113 | // 114 | // 115 | //// Calculate the factorial of a number. 116 | //// 117 | //// Prompt the user to enter an integer from 1 to 10. 118 | //// Display the factorial of the number entered by the user. 119 | //// Ask if the user wants to continue. 120 | //// Use a for loop to calculate the factorial. 121 | //// Assume that the user will enter an integer, but verify it’s between 1 and 10. 122 | //// Use the long type to store the factorial. 123 | //// Continue only if the user agrees to. 124 | //// A factorial is a number multiplied by each of the numbers before it. 125 | //// Factorials are denoted by the exclamation point (n!). Ex: 126 | //// 127 | //// 128 | //// 1! = 1 = 1 129 | //// 2! = 1 x 2 = 2 130 | //// 3! = 1 x 2 x 3 = 6 131 | //// 4! = 1 x 2 x 3 x 4 = 24 132 | // 133 | public static long calculateFactorial(int num) { 134 | int output = 1; 135 | for (int i = 1; i <= num; i += 1) { 136 | output *= i; 137 | } 138 | return output; 139 | } 140 | // 141 | // 142 | public static void userInteractionFactorial(Scanner sc) { 143 | boolean willContinue; 144 | String userChoice; 145 | do { 146 | System.out.println("Please enter an integer from 1 to 12"); 147 | int userInt = getInteger(1, 12); 148 | System.out.println(calculateFactorial(userInt)); 149 | do { 150 | System.out.println("Do you wish to continue? [y/n]: "); 151 | userChoice = sc.next().trim(); 152 | } while (!userChoice.equalsIgnoreCase("y") & !userChoice.equalsIgnoreCase("n")); 153 | 154 | willContinue = userChoice.equalsIgnoreCase("y"); 155 | } while (willContinue); 156 | } 157 | // 158 | // 159 | // 160 | //// Bonus 161 | //// 162 | //// Test the application and find the integer for the highest factorial that can be accurately calculated by this application, then modify the prompt so that it prompts the user for a number "from 1 to {the highest integer that returns accurate factorial calculation}". Don’t forget to change your verification too! 163 | // 164 | // 165 | //// Use Recursion to implement the factorial. 166 | // 167 | // public static long calculateFactorial(int num) { 168 | // long result; 169 | // if (num == 1) { 170 | // return 1; 171 | // } 172 | // result = calculateFactorial(num - 1) * num; 173 | // return result; 174 | // } 175 | // 176 | //// Create an application that simulates dice rolling. 177 | //// Ask the user to enter the number of sides for a pair of dice. 178 | //// Prompt the user to roll the dice. 179 | ////"Roll" two n-sided dice, display the results of each, and then ask the user if he/she wants to roll the dice again. 180 | //// Use static methods to implement the method(s) that generate the random numbers. 181 | //// Use the .random method of the java.lang.Math class to generate random numbers. 182 | // 183 | // 184 | public static int randomWithRange(int min, int max) 185 | { 186 | int range = (max - min) + 1; 187 | return (int)(Math.random() * range) + min; 188 | } 189 | 190 | public static void rollDiceGame(Scanner sc) { 191 | String userChoice; 192 | System.out.print("Please enter the number of sides for the dice: "); 193 | int nSides = getInteger(1, 20); 194 | do { 195 | System.out.println("You have rolled a " + randomWithRange(1, nSides) + " and a " + randomWithRange(1, nSides)); 196 | do { 197 | System.out.println("Would you like to roll again? [y/n]"); 198 | userChoice = sc.next().trim(); 199 | } while (!userChoice.equalsIgnoreCase("y") & !userChoice.equalsIgnoreCase("n")); 200 | 201 | } while (!userChoice.equals("n")); 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /src/Person.java: -------------------------------------------------------------------------------- 1 | public class Person { 2 | private String name; 3 | 4 | public Person(String name){ 5 | // setName(name); 6 | this.name = name; 7 | } 8 | public String getName(){ 9 | return this.name; 10 | } 11 | 12 | public void setName(String name){ 13 | this.name = name; 14 | } 15 | public void sayHello(){ 16 | System.out.println("Hello " + name); 17 | } 18 | 19 | public static void main(String[] args) { 20 | Person person1 = new Person("Bob"); 21 | person1.sayHello(); 22 | System.out.println(person1.getName()); 23 | 24 | Person person2 = person1; 25 | 26 | System.out.println(person1.getName()); 27 | System.out.println(person2.getName()); 28 | person2.setName("Jane"); 29 | 30 | System.out.println(person1.getName()); 31 | System.out.println(person2.getName()); 32 | 33 | System.out.println(person1 == person2); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/ServerNameGenerator.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; 2 | 3 | public class ServerNameGenerator { 4 | public static String[] adjectives = {"funny", "lackadaisical", "prompt", "fastidious", "prickly", "amazing", "incredible", "outdated", "pristine", "comical"}; 5 | public static String[] nouns = {"desk", "guitar", "house", "volkswagen", "lawnmower", "duck", "chair", "poster", "event", "candle"}; 6 | 7 | 8 | public static void main(String[] args) { 9 | System.out.println("Here is your server name: "); 10 | System.out.println(getWord(adjectives) + " " + getWord(nouns)); 11 | } 12 | 13 | public static String getWord(String[] words){ 14 | Random rnd = new Random(); 15 | int randomIndex = rnd.nextInt(words.length); 16 | return words[randomIndex]; 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /src/StringExercise.java: -------------------------------------------------------------------------------- 1 | public class StringExercise { 2 | public static void main(String[] args) { 3 | 4 | // For each of the following output examples, create a string variable named message 5 | // that contains the desired output and print it out to the console. 6 | 7 | 8 | // We don't need no education 9 | // We don't need no thought control 10 | 11 | String output = "We don't need no education\nWe don't need no thought control"; 12 | System.out.println(output); 13 | 14 | // Check "this" out!, "s inside of "s! 15 | 16 | String output2 = "Check \"this\" out!, \"s inside of \"s!"; 17 | System.out.println(output2); 18 | 19 | // In windows, the main drive is usually C:\ 20 | 21 | String output3 = "In windows, the main drive is usually C:\\"; 22 | 23 | // I can do backslashes \, double backslashes \\, 24 | // and the amazing triple backslash \\\! 25 | 26 | String output4 = "I can do backslashes \\, double backslashes \\\\,\nand the amazing triple backslash \\\\\\"; 27 | System.out.println(output4); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/StringLecture.java: -------------------------------------------------------------------------------- 1 | public class StringLecture { 2 | 3 | public static void main(String[] args) { 4 | 5 | // ------ .equals(String anotherString) 6 | 7 | // String one = "bob"; 8 | // String two = "bob"; 9 | 10 | // System.out.println(one.equals(two)); 11 | 12 | // System.out.println("bob".equals("steve")); 13 | // System.out.println(one.equals(two)); 14 | 15 | 16 | 17 | // ------ .equalsIgnoreCase(String anotherString) 18 | 19 | // String greeting1 = "howdy"; 20 | // String greeting2 = "howdy"; 21 | // String greeting3 = "howdy"; 22 | // 23 | // // greeting1 has to match with greeting2 and greeting 3 24 | // 25 | // if (greeting1.equals(greeting2) && greeting1.equals(greeting3)) { 26 | // 27 | // } 28 | 29 | 30 | // greeting.equals(greeting); 31 | // System.out.println(greeting.equalsIgnoreCase("HoWDy")); 32 | // 33 | 34 | // ------ .startsWith(String prefix) 35 | 36 | // String title = "Dracula"; 37 | // boolean isADoctor = title.toUpperCase().startsWith("DR."); 38 | // System.out.println(isADoctor); 39 | // System.out.println(title); 40 | 41 | 42 | // ------ .endsWith(String suffix) 43 | 44 | // String travisParkAddress = "311 E Travis St, San Antonio, TX 78205"; 45 | // String codeUpZip = "78205"; 46 | // boolean sameZipAsCodeup = travisParkAddress.endsWith(codeUpZip); 47 | // 48 | // System.out.println(sameZipAsCodeup); 49 | 50 | 51 | // ------ .charAt(int index) 52 | // consider that this method returns a char type and not a String type 53 | 54 | // boolean firstLetterCapitalized = false; 55 | // String word = "test"; 56 | // 57 | // char firstLetter = word.charAt(0); 58 | // 59 | // if (firstLetter == Character.toUpperCase(firstLetter)) { 60 | // firstLetterCapitalized = true; 61 | // } 62 | // 63 | // System.out.println(firstLetterCapitalized); 64 | 65 | 66 | // ------ .indexOf(String subString) 67 | 68 | // String cat = "cat"; 69 | // System.out.println(cat.indexOf("at")); 70 | 71 | 72 | // ------ .lastIndexOf(String subString) 73 | 74 | // String good = "Good"; 75 | // System.out.println(good.indexOf("o")); 76 | 77 | 78 | // ------ .length() 79 | 80 | // String longestWord = "pneumonoultramicroscopicsilicovolcanoconiosis"; 81 | // System.out.println(longestWord.length()); 82 | 83 | 84 | // ------ .replace(char oldChar, char newChar) 85 | 86 | // String search = "tiny cats looking cute"; 87 | // String parsedSearch = search.replace("cats", "dogs"); 88 | // System.out.println(parsedSearch); 89 | // System.out.println(search); 90 | 91 | 92 | // ------ .substring(int beginIndex[, int endIndex]) 93 | 94 | // String name = "Justin Bob Reich"; 95 | // System.out.println(name.substring(3)); 96 | 97 | // System.out.println(name.lastIndexOf("i")); 98 | // System.out.println(name.indexOf(" ")); 99 | // name.substring(0, 3); 100 | // System.out.println(name.substring(0, 3)); 101 | // System.out.println(name.indexOf(" ")); 102 | // String firstName = name.substring(0, 6); 103 | 104 | // System.out.println(firstName); 105 | 106 | 107 | // String lastName = name.substring(name.lastIndexOf(" ") + 1); 108 | // System.out.println(firstName); 109 | // System.out.println(lastName); 110 | 111 | // String name = "Justin Reich"; 112 | // String firstName = name.substring(0, name.indexOf(" ")); 113 | // System.out.println(firstName); 114 | // String lastName = name.substring(firstName.length() + 1); 115 | // System.out.println(lastName); 116 | 117 | 118 | // ------ .toLowerCase() and .toUpperCase() 119 | 120 | // String hello = "hELlo"; 121 | // System.out.println(hello.toUpperCase()); 122 | // System.out.println(hello.toLowerCase()); 123 | // System.out.println(hello); 124 | 125 | 126 | // ------ .trim() 127 | 128 | // String input = " bob smith \n\n "; 129 | // String trimmedInput = input.trim(); 130 | // System.out.println(trimmedInput); 131 | // 132 | // System.out.print("|" + input + "|"); 133 | 134 | 135 | // ------ chaining string methods 136 | 137 | // convert word to pig latin word (assume word doesn't begin with a vowel or end in ay) 138 | 139 | // String word1 = "cat"; 140 | // String pigLatinWord = word1 141 | // .trim() // "cat" 142 | // .toLowerCase() // "cat" 143 | // .substring(1) // "at" 144 | // .concat(word1.substring(0, 1).toLowerCase()) // "atc" 145 | // .concat("ay"); // "atcay" 146 | // System.out.println(pigLatinWord); 147 | 148 | 149 | 150 | } 151 | 152 | } 153 | 154 | -------------------------------------------------------------------------------- /src/SyntaxLecture.java: -------------------------------------------------------------------------------- 1 | public class SyntaxLecture { 2 | 3 | public static void main(String[] args) { 4 | 5 | 6 | // ================== STATEMENTS (s-3) 7 | 8 | // Statements may be... 9 | // Declarations 10 | // int x; // primitive 11 | // String y; // reference type 12 | 13 | // Assignment expressions 14 | // x = 3; 15 | 16 | // String x; 17 | // x = "bob"; 18 | 19 | // System.out.println(x); 20 | // x = 4; 21 | // System.out.println(x); 22 | 23 | 24 | // Any use of ++ or -- 25 | 26 | // int x = 5; 27 | // System.out.println(++x); // 6 28 | // System.out.println(x++); // 6 29 | // System.out.println(x); // 7 30 | 31 | // Method invocations 32 | // Math.random(); 33 | 34 | // Object creation expressions 35 | // SomeObject = new SomeObject(); 36 | 37 | // ================== COMMENTS (s-4) 38 | 39 | // single line comment 40 | 41 | /* 42 | 43 | multi-line comment 44 | 45 | */ 46 | 47 | /** 48 | * Comment block 49 | */ 50 | 51 | // System.out.println("test"); 52 | 53 | 54 | // ================== DATA TYPES (s-5, 6, 7) 55 | 56 | 57 | 58 | // int primitiveExample = 3; 59 | // System.out.println(primitiveExample); 60 | 61 | 62 | // Student referenceExample = new Student(); 63 | 64 | 65 | // use the smallest type needed for the job 66 | 67 | 68 | // primitive types... 69 | 70 | // byte age = -32; 71 | // short minimumAnnualSalary = 15080; 72 | // int distanceToSaturnInKm = 1200000000; 73 | // long numberOfHumanCells = 3000000000L; // L needed for compiler 74 | 75 | 76 | // byte s = -128; 77 | // --s; 78 | // System.out.println(s); 79 | 80 | 81 | // System.out.println(numberOfHumanCells); 82 | // float lengthOfBacteriaInInches = 0.00004F; // F needed for compiler 83 | // System.out.println(lengthOfBacteriaInInches); 84 | // double widthOfAtomInMeters = .00000000001; 85 | // char seatingSection = 'M'; // must wrap in single quotes 86 | // boolean everythingIsAwesome = false; 87 | 88 | // String bool = "false"; 89 | // boolean bool2 = Boolean.parseBoolean(bool); 90 | // System.out.println(bool2); 91 | 92 | // strings (not a primitive type) 93 | 94 | String thisIsAString = "Hello"; 95 | 96 | 97 | 98 | // like in JS, strings must escape certain characters like quotes and use it to inject newline characters and other formatting 99 | 100 | // System.out.println("Hello\nWorld"); 101 | // System.out.print("Hello"); 102 | // System.out.print("World"); 103 | 104 | // System.out.println("He said \"Hi\""); 105 | // 106 | // String hello = "Hello"; 107 | // char someLetter = hello.charAt(0); 108 | // System.out.println(someLetter); 109 | 110 | 111 | // ================== VARIABLES (s-8) 112 | 113 | // declaration separate from initialization 114 | 115 | // int seven; 116 | // seven = 7; 117 | // System.out.println(seven); 118 | 119 | // declaration and initialization 120 | 121 | // int eight = 8; 122 | // System.out.println(eight); 123 | 124 | 125 | // ================== IDENTIFIERS AND KEYWORDS (s-9) 126 | 127 | // see curriculum 128 | 129 | 130 | 131 | // ================== CONSTANTS (s-10) 132 | 133 | // see curriculum 134 | 135 | // final int SIDES_OF_A_DICE = 6; 136 | 137 | 138 | // ================== EXPRESSIONS (s-11) 139 | 140 | // basically the same as JS 141 | 142 | 143 | // ================== OPERATORS (s-12) 144 | 145 | // basically the same as JS 146 | 147 | 148 | // ================== ASSIGNMENT STATEMENTS (s-13) 149 | 150 | // basically the same as JS 151 | 152 | 153 | // ================== CASTING (s-14) 154 | 155 | // Link on casting... http://www.javainterviewpoint.com/type-casting-java-implicit-explicit-casting/ 156 | 157 | 158 | // IMPLICIT 159 | // short x = 4; 160 | // int y = x; 161 | // System.out.println(x); 162 | // System.out.println(y); 163 | 164 | 165 | // EXPLICIT 166 | // int a = 2000001; 167 | // byte b = (byte) a; 168 | // System.out.println(a); 169 | // System.out.println(b); 170 | 171 | 172 | 173 | 174 | 175 | 176 | // implicit casting - less to more precise (widening) 177 | 178 | // float num1 = 2.22F; 179 | // double num2 = num1; 180 | 181 | 182 | 183 | // explicit casting - more to less explicit casting (narrowing) 184 | 185 | // double num3 = 3.1; 186 | // float num4 = (float) num3; 187 | // 188 | // System.out.println(num4); 189 | 190 | 191 | // int num = 3000; 192 | // byte num2 = (byte) num; 193 | // System.out.println(num2); 194 | 195 | 196 | } 197 | 198 | } 199 | -------------------------------------------------------------------------------- /src/abstractClassesInterfaces/McFranchise.java: -------------------------------------------------------------------------------- 1 | package abstractClassesInterfaces; 2 | 3 | // Declaring this as an 'interface' 4 | public interface McFranchise { 5 | // Properties 6 | String companyName = "McDonald's"; // this String is a constant 7 | 8 | // We won't have a constructor in an 'interface' ( only in abstract classes ) 9 | 10 | // Abstract Methods (that we have to completely write out in any class that IMPLEMENTS this interface 11 | void broilStuff(String menuItem); 12 | void businessHours(int openTime, int closeTime); 13 | String iceCreamMachineWorking(); 14 | // void greetCustomer(); // declare as abstract 15 | } 16 | -------------------------------------------------------------------------------- /src/arraysLecture/ArraysLec.java: -------------------------------------------------------------------------------- 1 | package arraysLecture; 2 | 3 | 4 | import java.util.Arrays; 5 | 6 | public class ArraysLec { 7 | 8 | public static void main(String[] args) { 9 | 10 | /* ******************************************************** */ 11 | /* ********** USING PRIMITIVE AND REFERENCE TYPES **********/ 12 | /* ******************************************************** */ 13 | 14 | // https://stackoverflow.com/questions/29140402/how-do-i-print-my-java-object-without-getting-sometype2f92e0f4 15 | 16 | 17 | 18 | // Int Example 19 | //Declare an int array variable and assign an int array with the length of 3 to the array variable nums 20 | 21 | // int[] nums = new int[3]; 22 | // 23 | // nums[0] = 1; //Assign each index to an int variable 24 | // nums[1] = 10; 25 | // nums [2] = 12; 26 | 27 | // System.out.println(nums); //Type@HashcodeOfObject 28 | 29 | 30 | 31 | // System.out.println(Arrays.toString(nums)); //this is an Array method 32 | // 33 | // for(int i = 0; i < nums.length; i++){ 34 | // System.out.println(nums[i]); 35 | // } 36 | 37 | 38 | 39 | 40 | // Dog Example 41 | // Dog d1 = new Dog("Bean", 1); 42 | // Dog d2 = new Dog("Patch", 3); 43 | // Dog d3 = new Dog("Rolo", 5); 44 | // Dog d4 = new Dog("Skip", 2); 45 | 46 | 47 | //Declaring a Dog array variable called dogs and creating a new Dog array with a length of 4 48 | // Dog[] dogs = new Dog[3]; 49 | // dogs[0] = d1; 50 | // dogs[1] = d2; 51 | // dogs[2] = d3; 52 | // dogs[2] = new Dog("Skip", 2); 53 | // 54 | // for(Dog dog : dogs){ 55 | // System.out.println(dog.getName()); 56 | // } 57 | 58 | 59 | // System.out.println(dogs); 60 | 61 | 62 | 63 | 64 | 65 | /* 66 | * !!!!! NOTE !!!!! 67 | * System.out.println(dogs); 68 | * 69 | * When we print "dogs" you will get some version of this! 70 | * [LarraysLecture.Dog;@___________ 71 | * 72 | * [ = single dimension 73 | * L = array contains a class or interface 74 | * arrays.Dog = type of object (arrays b/c in arrays package) 75 | */ 76 | 77 | 78 | // System.out.println(Arrays.toString(dogs)); 79 | 80 | 81 | 82 | // Dog[] dogs2 = {new Dog("Dog1", 4), new Dog("Dog2", 2), new Dog("Dog3", 7)}; 83 | // for(Dog dog : dogs2){ 84 | // System.out.println(dog.getAge()); 85 | // } 86 | 87 | //TODO: What do you think will happen in this loop? 88 | 89 | // for (int i = 0; i < dogs.length; i += 1) { 90 | // System.out.println(dogs[i].getName()); 91 | // } 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | // Program will break here. Exception in thread "main" java.lang.NullPointerException 103 | 104 | 105 | 106 | 107 | 108 | 109 | /* ******************************************************** */ 110 | /* ********** Array Initializer & Iterating ************** */ 111 | /* ******************************************************** */ 112 | // String[] languages = new String[4]; 113 | // languages[0] = "html"; 114 | // languages[0] = "react"; 115 | // languages[1] = "css"; 116 | // languages[2] = "javascript"; 117 | // languages[3] = "java"; 118 | // System.out.println(Arrays.toString(languages)); 119 | // 120 | // 121 | // 122 | // String[] languages2 = {"html2", "css2", "javascript2", "java2"}; 123 | // System.out.println(Arrays.toString(languages2)); 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | // //enhanced for loop 132 | // for (String language : languages2) { 133 | // System.out.println(language); 134 | // } 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | /* ******************************************************** */ 150 | /* ************ Array Methods Mini Activity ************** */ 151 | /* ******************************************************** */ 152 | //TODO: Experiment with the following Array methods. Add a few comments explaining what is happening. Bonus: Create your own example. 153 | 154 | 155 | // Example1: Array.fill() 156 | 157 | // String[] testArray = new String[4]; 158 | // 159 | // Arrays.fill(testArray, "dogs"); 160 | // for (String element : testArray) { 161 | // System.out.println(element); 162 | // } 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | // ***Example1: BONUS *** 172 | // int[] numArray = {1,1,1,1,1,1,1,1,1,1}; 173 | // 174 | // Arrays.fill(numArray, 0, 4, 5); 175 | // for (int element : numArray) { 176 | // System.out.println(element); 177 | // } 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | // Example 2: Arrays.equals(array1, array2) 188 | // Returns true if two array elements are equal and in the same order 189 | 190 | // String[] words = {"Mushroom", "Mushroom"}; 191 | // String[] words2 = {"Mushroom", "mushroom"}; 192 | // System.out.println(Arrays.equals(words, words2)); 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | // Example 3: Arrays.copyOf() 203 | // Returns a copy array of a given array of a given length 204 | 205 | // String[] badgerArray = new String[4]; 206 | // Arrays.fill(badgerArray, "Badgers"); 207 | // 208 | // String[] twoBadgers = Arrays.copyOf(badgerArray, 2); 209 | // System.out.println(Arrays.toString(twoBadgers)); 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | // Example 4: Arrays.sort(array, startIndex, toIndex) 221 | // Sorts array elements alphabetically/numerically 2nd and 3rd arguments are optional. 222 | 223 | // String[] animals = {"Dog", "Rabbit", "Cat", "Snake", "Fish"}; 224 | // System.out.println(Arrays.toString(animals)); 225 | // 226 | // Arrays.sort(animals); 227 | // System.out.println(Arrays.toString(animals)); 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | /* ******************************************************** */ 237 | /* ************** Two-Dimensional Arrays ***************** */ 238 | /* ******************************************************** */ 239 | 240 | 241 | // int[][] matrix = { 242 | // {1, 2, 3}, 243 | // {4, 5, 6}, 244 | // {7, 8, 9} 245 | // }; 246 | // 247 | // 248 | // 249 | // // access the first element in the second row 250 | // System.out.println(matrix[1][0]); // 4 251 | // 252 | // 253 | // // the last element in the first row 254 | // System.out.println(matrix[0][2]); // 3 255 | // 256 | // 257 | // // the first element in the last row 258 | // System.out.println(matrix[2][0]); // 7 259 | 260 | 261 | 262 | 263 | /* ******************************************************** */ 264 | /* ************** Arrays vs. Array Lists ***************** */ 265 | /* ******************************************************** */ 266 | 267 | //https://stackoverflow.com/questions/4842883/are-there-reasons-to-prefer-arrays-over-arraylists 268 | 269 | //Remember that Arrays in Java are a less flexible data type than Arrays in JavaScript. This is why our Array methods are limited. 270 | 271 | //ArrayLists in Java which we will experience later are more similar to Arrays we saw in JavaScript and allows for different functionality. 272 | 273 | 274 | 275 | } 276 | } 277 | -------------------------------------------------------------------------------- /src/arraysLecture/Dog.java: -------------------------------------------------------------------------------- 1 | package arraysLecture; 2 | 3 | public class Dog { 4 | 5 | private String name; 6 | private int age; 7 | 8 | 9 | public Dog(String name, int age) { 10 | this.name = name; 11 | this.age = age; 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | public int getAge() { 23 | return age; 24 | } 25 | 26 | public void setAge(int age) { 27 | this.age = age; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/collections/ArrayLists.java: -------------------------------------------------------------------------------- 1 | package collections; 2 | 3 | import java.lang.reflect.Array; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import java.util.Collection; 7 | import java.util.Collections; 8 | 9 | public class ArrayLists { 10 | public static void main(String[] args) { 11 | 12 | ArrayList numbers = new ArrayList<>(); 13 | ArrayList randomNumbers = new ArrayList<>(Arrays.asList(1,2,3)); 14 | 15 | System.out.println(randomNumbers); 16 | 17 | // Add elements to an ArrayList. The element type is the determined by the Object type within the angle brackets <> 18 | numbers.add(10); 19 | numbers.add(12); 20 | numbers.add(13); 21 | numbers.add(13); 22 | 23 | // numbers.remove(Integer.valueOf(13)); <- removes first instance of 13 24 | // numbers.remove((Integer)13); <- StackOverFlow version 25 | 26 | 27 | // prints out ArrayList 28 | System.out.println(numbers); 29 | 30 | // return length of the ArrayList with .size() 31 | System.out.println(numbers.size()); 32 | 33 | // return an element at the specified index 34 | System.out.println(numbers.get(1)); 35 | // System.out.println(numbers.get(5)); <- results in Out Of Bounds exception 36 | 37 | 38 | // returns index position of found element, -1 if not found. 39 | System.out.println(numbers.indexOf(13)); 40 | System.out.println(numbers.indexOf(20)); 41 | 42 | // TODO: Add a new Integer to the numbers ArrayList at index 1. 43 | 44 | numbers.add(1,11); 45 | // numbers.add("fortyfive"); 46 | 47 | System.out.println(numbers); 48 | 49 | ArrayList roasts = new ArrayList<>(); 50 | // ArrayList roasts = new ArrayList<>(Arrays.asList("test","test","test")); 51 | ArrayList emptyList = new ArrayList<>(); 52 | roasts.add("light"); 53 | roasts.add("medium"); 54 | roasts.add("medium"); 55 | roasts.add("medium"); 56 | roasts.add("dark"); 57 | roasts.add("dark"); 58 | roasts.add("medium"); 59 | 60 | System.out.println(roasts); 61 | 62 | // .contains returns a boolean value based on whether or not a searched value exists in the ArrayList 63 | System.out.println(roasts.contains("dark")); 64 | 65 | // TODO: Check if the roasts list contains "espresso" 66 | System.out.println(roasts.contains("espresso")); 67 | 68 | // returns the last occurrence of a given value 69 | // TODO: Find the last "medium" roast in the list. 70 | System.out.println(roasts.lastIndexOf("medium")); 71 | 72 | // TODO: How could we check if the roasts list is empty? 73 | System.out.println(roasts.isEmpty()); 74 | System.out.println(emptyList.isEmpty()); 75 | 76 | // TODO: Remove one medium roast from the list. If there are duplicate strings in the list, which one is removed first? 77 | boolean isRemoved = roasts.remove("medium"); 78 | System.out.println(isRemoved); 79 | System.out.println(roasts); 80 | 81 | System.out.println(roasts.remove("espresso")); 82 | 83 | // TODO: Remove the element at index 4. Note the return value here vs. the previous remove method. 84 | String removedCoffee = roasts.remove(4); 85 | Collections.sort(roasts); 86 | System.out.println(roasts); 87 | 88 | // BONUS TODO: How can we get the list of roasts in alphabetical order? 89 | Collections.sort(roasts); 90 | // roasts.sort(Collections.reverseOrder()); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/collections/CollectionsLecture.java: -------------------------------------------------------------------------------- 1 | package collections; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.HashMap; 6 | import java.util.Set; 7 | 8 | public class CollectionsLecture { 9 | public static void main(String[] args) { 10 | ArrayList nums = new ArrayList<>(Arrays.asList(23,46,32,10,6)); 11 | for(int num:nums){ 12 | System.out.println(num); 13 | } 14 | 15 | HashMap answers = new HashMap<>(); 16 | 17 | answers.put('A',"Sally"); 18 | answers.put('B',"Sally"); 19 | answers.put('C',"Jimbo"); 20 | answers.put('D',"Jimbo"); 21 | answers.put('E',"Jim"); 22 | 23 | System.out.println(answers.get('C')); 24 | 25 | System.out.println(answers.keySet()); 26 | Set keys = answers.keySet(); 27 | 28 | for(char key:keys){ 29 | if(answers.get(key).equals("Jimbo")){ 30 | System.out.println(key); 31 | } 32 | } 33 | 34 | // How can we find all of Jimbo's answers? 35 | // .value of? 36 | // Loop and condition 37 | // is there a value set method? 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/collections/HashMaps.java: -------------------------------------------------------------------------------- 1 | package collections; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | 6 | public class HashMaps { 7 | public static void main(String[] args) { 8 | // We'll start by defining a hash map 9 | HashMap usernames = new HashMap<>(); 10 | HashMap answers = new HashMap<>(); 11 | 12 | answers.put('A',"Sophie"); 13 | answers.put('B',"Vivian"); 14 | 15 | 16 | // and putting some data into it 17 | usernames.put("Ryan", "ryanorsinger"); 18 | // usernames.put("Ryan", "otherryan"); <- will overwrite other ryan 19 | usernames.put("Zach", "zgulde"); 20 | usernames.put("Fernando", "fmendozaro"); 21 | usernames.put("Justin", "jreich5"); 22 | 23 | System.out.println(usernames); 24 | // TODO: Add more key-value pairs to usernames 25 | usernames.put("Sophie", "sophiakurihara"); 26 | usernames.put("Vivian", "viviancan"); 27 | usernames.put("Casey", "caseyfriday"); 28 | 29 | System.out.println(usernames); 30 | 31 | // obtaining values from the hash map by key 32 | // TODO: Get the value stored in key "Ryan" 33 | System.out.println(usernames.get("Ryan")); 34 | // TODO: Get the value stored in key "Phillip". What is the result? 35 | System.out.println(usernames.get("Phillip")); 36 | System.out.println(usernames.getOrDefault("Jason", "gocodeup")); 37 | 38 | // checking if keys or values are present 39 | // TODO: Check if key "Justin" exists in the HashMap 40 | System.out.println(usernames.containsKey("Justin")); 41 | // TODO: Check if the value "fmendozaro" exists 42 | System.out.println(usernames.containsValue("fmendozaro")); 43 | 44 | 45 | usernames.putIfAbsent("Ryan", "hiiamryan"); 46 | 47 | System.out.println("New:" + usernames); // {Ryan=ryanorsinger} 48 | 49 | usernames.putIfAbsent("Zach", "zgulde"); 50 | usernames.putIfAbsent("Zach", "coderdude24"); 51 | System.out.println(usernames); // {Ryan=ryanorsinger, Zach=zgulde} 52 | 53 | // TODO: Remove key "Zach" and the value associated with it 54 | usernames.remove("Zach"); 55 | System.out.println(usernames); // {Ryan=ryanorsinger} 56 | 57 | // TODO: Replace Ryan's username with "torvalds" 58 | usernames.replace("Ryan","torvalds"); 59 | System.out.println(usernames); // {Ryan=torvalds} 60 | 61 | usernames.clear(); 62 | System.out.println(usernames); 63 | System.out.println(usernames.isEmpty()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/fileIo/FileReader.java: -------------------------------------------------------------------------------- 1 | package fileIo; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.Files; 5 | import java.nio.file.Path; 6 | import java.nio.file.Paths; 7 | import java.nio.file.StandardOpenOption; 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | import java.util.List; 11 | 12 | public class FileReader { 13 | 14 | // properties for this class 15 | // goal: read in a file and parse through it 16 | private String directoryName; // i.e. 'data', 'src/fileIo' 17 | private String fileName; // i.e. 'day18.txt', 'jolts.txt' 18 | private String logFileName; // will hold logging info 19 | private Path directoryPath; // Path representation of the parent directory for our files 20 | private Path filePath; // Path representation for the actual file itself 21 | private Path logFilePath; // Path representation of the log file 22 | private List fileLines; // Holding spot for the content inside of the data file itself 23 | private List logFileLines; // Holding spot for the content inside of the log file 24 | 25 | 26 | // Constructor 27 | // Want to send in a directory path name and a file name, logFile name, and generate EVERYTHING from just those two values 28 | public FileReader(String directoryName, String fileName, String logFileName) throws IOException { 29 | this.directoryName = directoryName; 30 | this.fileName = fileName; 31 | this.logFileName = logFileName; 32 | // Instantiating Path values 33 | this.directoryPath = Paths.get(directoryName); // Paths.get("data") 34 | this.filePath = Paths.get(directoryName, fileName); 35 | this.logFilePath = Paths.get(directoryName, logFileName); 36 | 37 | // Check if files exist, and create them if they don't currently exist 38 | // Log File 39 | if (Files.notExists(this.logFilePath)) { 40 | try { 41 | Files.createFile(this.logFilePath); 42 | } catch (IOException e) { 43 | // Store this exception message in the log file 44 | // if there is an issue creating the log file, let's just crash the whole party and throw an IOException 45 | throw new IOException("Unable to create the logfile (" + this.logFileName + ")!"); 46 | } 47 | } 48 | 49 | // Directory for data file ('data'), ('src/fileIo') 50 | if (Files.notExists(this.directoryPath)) { 51 | try { 52 | Files.createDirectories(this.directoryPath); // createDirectories will create any missing parent directories along with the enclosing directory 53 | } catch (IOException e) { 54 | // Add this error message to the log 55 | // Files.write(Path filePath, List message(s), appendOption) 56 | // could initialize a List like this, and send it in as the second argument in the Files.write() method 57 | // List errorMessage = new ArrayList<>(); 58 | // errorMessage.add(e.getMessage()); 59 | 60 | Files.write(this.logFilePath, Arrays.asList(e.getMessage()), StandardOpenOption.APPEND); // append to the end of the log file 61 | throw new IOException("Unable to create the data directory (" + this.directoryName + ")!"); 62 | // stop all execution 63 | } 64 | } 65 | 66 | // Data File ('day18.txt') 67 | if (Files.notExists(this.filePath)) { // i.e. 'src/day18.txt' 68 | // if we've made into this if statement, that means the file DOES NOT exist, so let's create it! 69 | try { 70 | Files.createFile(this.filePath); 71 | } catch (IOException e) { 72 | Files.write(this.logFilePath, Arrays.asList(e.getMessage()), StandardOpenOption.APPEND); // append to the end of the log file 73 | throw new IOException("Unable to create the data file (" + this.fileName + ")!"); 74 | } 75 | } 76 | 77 | 78 | // Test if the instantiation worked 79 | System.out.println(filePath); // display the file path for the passed in arguments 80 | this.fileLines = Files.readAllLines(this.filePath); // gives me every line in (i.e. 'day18.txt' as a String, inside of a List 81 | 82 | } 83 | 84 | // PSVM (you can think of this as being 20 files away from this file - it is STATIC 85 | public static void main(String[] args) throws IOException { 86 | // Instantiate a FileReader object, and see if it works 87 | FileReader day18Reader = new FileReader("data", "day18.txt", "day18.log"); 88 | day18Reader.writeToLog("Successfully read the " + day18Reader.getFileName() + " file!"); 89 | 90 | // Set up a new instance to access the jolts.txt file 91 | FileReader joltsReader = new FileReader("src/fileIo", "jolts.txt", "jolts.log"); 92 | joltsReader.writeToLog("Successfully read the " + joltsReader.getFileName() + " file!"); 93 | 94 | System.out.println("Day18 file, here's the first line:"); 95 | System.out.println(day18Reader.getFileLines().get(0)); 96 | 97 | System.out.println("Jolts file, here's the first line:"); 98 | System.out.println(joltsReader.getFileLines().get(0)); 99 | } 100 | 101 | 102 | // Custom Method - want to be able to easily write a message to the log, without some enormous nested function calling nonsense 103 | public void writeToLog(String message) throws IOException { 104 | try { 105 | // write the string 'message' to the log file of THIS INSTANCE of a FileReader object 106 | Files.write(this.logFilePath, Arrays.asList(message), StandardOpenOption.APPEND); 107 | } catch(IOException e) { 108 | Files.write(this.logFilePath, Arrays.asList(e.getMessage()), StandardOpenOption.APPEND); 109 | throw new IOException("Unable to write custom message to log file"); 110 | } 111 | } 112 | 113 | 114 | 115 | // Getters and Setters 116 | public String getDirectoryName() { 117 | return directoryName; 118 | } 119 | 120 | public void setDirectoryName(String directoryName) { 121 | this.directoryName = directoryName; 122 | } 123 | 124 | public String getFileName() { 125 | return fileName; 126 | } 127 | 128 | public void setFileName(String fileName) { 129 | this.fileName = fileName; 130 | } 131 | 132 | public String getLogFileName() { 133 | return logFileName; 134 | } 135 | 136 | public void setLogFileName(String logFileName) { 137 | this.logFileName = logFileName; 138 | } 139 | 140 | public Path getDirectoryPath() { 141 | return directoryPath; 142 | } 143 | 144 | public void setDirectoryPath(Path directoryPath) { 145 | this.directoryPath = directoryPath; 146 | } 147 | 148 | public Path getFilePath() { 149 | return filePath; 150 | } 151 | 152 | public void setFilePath(Path filePath) { 153 | this.filePath = filePath; 154 | } 155 | 156 | public Path getLogFilePath() { 157 | return logFilePath; 158 | } 159 | 160 | public void setLogFilePath(Path logFilePath) { 161 | this.logFilePath = logFilePath; 162 | } 163 | 164 | public List getFileLines() { 165 | return fileLines; 166 | } 167 | 168 | public void setFileLines(List fileLines) { 169 | this.fileLines = fileLines; 170 | } 171 | 172 | public List getLogFileLines() { 173 | return logFileLines; 174 | } 175 | 176 | public void setLogFileLines(List logFileLines) { 177 | this.logFileLines = logFileLines; 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/fileIo/README.md: -------------------------------------------------------------------------------- 1 | # Order of FileReader Class Creation 2 | 3 | ### Paths 4 | 1. Create a **directory** string property 5 | 1. Create a **filename** string property 6 | 1. Create a **logfileName** string property 7 | 1. Initialize the path for our file 8 | 9 | ### Getters and Setters 10 | 1. We can use the IntelliJ shortcut to create these 11 | 12 | ### Constructor 13 | We'll be using the following methods in our constructor 14 | 1. **Paths**.get 15 | 1. **Files**.notExists 16 | 1. **Files**.createFile 17 | 1. **Files**.createDirectories 18 | 1. **Files**.write 19 | 1. **Files**.readAllLines 20 | 21 | ### Special Logging Method 22 | I also want a method that will log any string I send in to the log file. 23 | 24 | ### Test it all out (PSVM) 25 | Finally, just need to test it all out with a `public static void main() { ...` -------------------------------------------------------------------------------- /src/fileIo/jolts.log: -------------------------------------------------------------------------------- 1 | Successfully read the jolts.txt file! 2 | -------------------------------------------------------------------------------- /src/fileIo/jolts.txt: -------------------------------------------------------------------------------- 1 | 105 2 | 124 3 | 42 4 | 52 5 | 71 6 | 41 7 | 1 8 | 85 9 | 148 10 | 90 11 | 155 12 | 112 13 | 35 14 | 134 15 | 145 16 | 39 17 | 161 18 | 160 19 | 34 20 | 54 21 | 15 22 | 165 23 | 8 24 | 20 25 | 46 26 | 49 27 | 108 28 | 151 29 | 60 30 | 7 31 | 48 32 | 154 33 | 63 34 | 147 35 | 132 36 | 98 37 | 158 38 | 33 39 | 137 40 | 45 41 | 140 42 | 121 43 | 22 44 | 62 45 | 111 46 | 141 47 | 167 48 | 131 49 | 74 50 | 93 51 | 2 52 | 142 53 | 113 54 | 21 55 | 162 56 | 61 57 | 3 58 | 19 59 | 101 60 | 9 61 | 102 62 | 115 63 | 70 64 | 12 65 | 84 66 | 6 67 | 114 68 | 107 69 | 97 70 | 133 71 | 64 72 | 80 73 | 78 74 | 91 75 | 79 76 | 14 77 | 168 78 | 87 79 | 159 80 | 30 81 | 94 82 | 77 83 | 40 84 | 125 85 | 47 86 | 27 87 | 38 88 | 166 89 | 86 90 | 26 91 | 23 92 | 67 93 | 127 94 | 28 95 | 16 96 | 169 97 | 13 98 | 92 99 | 106 100 | 57 101 | 118 102 | 126 103 | 83 104 | 146 105 | 29 106 | 130 107 | 53 -------------------------------------------------------------------------------- /src/inheritanceLecture/AutoShop/Car.java: -------------------------------------------------------------------------------- 1 | package inheritanceLecture.AutoShop; 2 | 3 | public class Car { 4 | private String make; 5 | private String model; 6 | private int year; 7 | 8 | public void drive(){ 9 | System.out.println("Vroom Vroom"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/inheritanceLecture/AutoShop/Chevy.java: -------------------------------------------------------------------------------- 1 | package inheritanceLecture.AutoShop; 2 | 3 | import inheritanceLecture.AutoShop.Car; 4 | 5 | public class Chevy extends Car { 6 | } 7 | -------------------------------------------------------------------------------- /src/inheritanceLecture/AutoShop/Ford.java: -------------------------------------------------------------------------------- 1 | package inheritanceLecture.AutoShop; 2 | 3 | import inheritanceLecture.AutoShop.Car; 4 | 5 | public class Ford extends Car { 6 | } 7 | -------------------------------------------------------------------------------- /src/inheritanceLecture/AutoShop/Technician.java: -------------------------------------------------------------------------------- 1 | package inheritanceLecture.AutoShop; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Technician { 6 | private String name; 7 | 8 | public Technician(String name){ 9 | this.name = name; 10 | } 11 | 12 | public Car repair(Car theCar){ 13 | System.out.println("Repairing the car..."); 14 | return theCar; 15 | } 16 | 17 | public static void main(String[] args) { 18 | Technician Bob = new Technician("Bob"); 19 | 20 | // Assume that Bob can repair any type of Car. Demonstrate this with Polymorphism. 21 | 22 | Car toyota = new Toyota(); 23 | Car ford = new Ford(); 24 | Car chevy = new Chevy(); 25 | 26 | 27 | Bob.repair(toyota); 28 | toyota.drive(); 29 | 30 | Bob.repair(ford); 31 | Bob.repair(chevy); 32 | 33 | ArrayList cars = new ArrayList<>(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/inheritanceLecture/AutoShop/Toyota.java: -------------------------------------------------------------------------------- 1 | package inheritanceLecture.AutoShop; 2 | 3 | import inheritanceLecture.AutoShop.Car; 4 | 5 | public class Toyota extends Car { 6 | public void drive(){ 7 | System.out.println("Toyota is driving."); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/inheritanceLecture/Developer.java: -------------------------------------------------------------------------------- 1 | package inheritanceLecture; 2 | 3 | public class Developer extends Employee{ 4 | public Developer(){ 5 | } 6 | public Developer(String name){ 7 | super(name); 8 | } 9 | 10 | public void doWork(){ 11 | System.out.println("Writing code..."); 12 | } 13 | 14 | public void working(){ 15 | super.doWork(); 16 | } 17 | 18 | public void debug(){ 19 | System.out.println("DEBUGGING"); 20 | } 21 | 22 | public static void main(String[] args) { 23 | Employee Bob = new Employee("Bob"); 24 | Bob.doWork(); 25 | System.out.println(Bob.getName()); 26 | // Bob.debug(); <- this will not work 27 | 28 | Developer John = new Developer("John"); 29 | John.doWork(); 30 | John.working(); 31 | 32 | System.out.println(John.getName()); 33 | John.debug(); 34 | System.out.println(John.name);; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/inheritanceLecture/Employee.java: -------------------------------------------------------------------------------- 1 | package inheritanceLecture; 2 | import util.Input; 3 | 4 | public class Employee { 5 | protected String name; 6 | public int id; 7 | public final static String company = "Codeup"; 8 | 9 | public Employee(){ 10 | 11 | } 12 | public Employee(String name){ 13 | this.name = name; 14 | } 15 | 16 | public void doWork(){ 17 | System.out.println("Working... working..."); 18 | } 19 | 20 | public String getName(){ 21 | return name; 22 | } 23 | 24 | public int getId(){ 25 | return id; 26 | } 27 | 28 | // public String getString(){ 29 | // Input sc = new Input(); 30 | // return sc.getString(); 31 | // } 32 | 33 | public static void main(String[] args) { 34 | Employee sarah = new Employee("Sarah"); 35 | Employee ryan = new Developer("Ryan"); 36 | 37 | ryan.doWork(); 38 | // ryan.working(); 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/inheritanceLecture/JavaDeveloper.java: -------------------------------------------------------------------------------- 1 | package inheritanceLecture; 2 | 3 | public class JavaDeveloper extends Developer{ 4 | public JavaDeveloper(){ 5 | 6 | } 7 | 8 | // This creates JavaDeveloper's own implementation of the working method and calls on the doWork method from its superclass, Developer. 9 | // public void working(){ 10 | // super.doWork(); 11 | // } 12 | 13 | public JavaDeveloper(String name){ 14 | super(name); 15 | } 16 | public static void main(String[] args) { 17 | JavaDeveloper Sophie = new JavaDeveloper("Sophie"); 18 | System.out.println(Sophie.name); 19 | Sophie.doWork(); 20 | Sophie.working(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/inheritanceLecture/Manager.java: -------------------------------------------------------------------------------- 1 | package inheritanceLecture; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Manager extends Employee{ 6 | 7 | public Manager(String name){ 8 | super(name); 9 | } 10 | public ArrayList manageEmployee(ArrayList employees){ 11 | System.out.println("Managing employees"); 12 | return employees; 13 | } 14 | 15 | public static void main(String[] args) { 16 | Employee bob = new Developer("Bob"); 17 | Employee john = new Developer("John"); 18 | Developer johnDev = new Developer("John Developer"); 19 | Employee jane = new Teacher("Jane"); 20 | 21 | Manager bernice = new Manager("Bernice"); 22 | ArrayList employees = new ArrayList<>(); 23 | employees.add(bob); 24 | employees.add(john); 25 | employees.add(jane); 26 | // employees.add(johnDev); <- this will not work. wrong type 27 | 28 | bernice.manageEmployee(employees); 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/inheritanceLecture/Teacher.java: -------------------------------------------------------------------------------- 1 | package inheritanceLecture; 2 | 3 | public class Teacher extends Employee{ 4 | public Teacher(){ 5 | 6 | } 7 | 8 | public Teacher(String name){ 9 | super(name); 10 | } 11 | 12 | public void doWork() { 13 | System.out.println("Teaching students..."); 14 | } 15 | 16 | public void working(){ 17 | super.doWork(); 18 | } 19 | 20 | public static void main(String[] args) { 21 | Teacher Jane = new Teacher("Jane"); 22 | System.out.println(Jane.getName()); 23 | Jane.doWork(); 24 | Jane.working(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/madlib/IoUtils.java: -------------------------------------------------------------------------------- 1 | package madlib; 2 | 3 | import java.util.Scanner; 4 | 5 | class IoUtils { 6 | 7 | private static Scanner sc; 8 | private static String outputMode = "sout"; 9 | 10 | static Scanner getScanner() { 11 | if (sc == null) { 12 | sc = new Scanner(System.in); 13 | } 14 | return sc; 15 | } 16 | 17 | static String nullCoalesceStr(String str, String defaultStr) { 18 | return (str == null) ? defaultStr : str; 19 | } 20 | 21 | static void output(String str) { 22 | switch (outputMode) { 23 | case "sout": { 24 | System.out.println(str); 25 | break; 26 | } 27 | case "html": { 28 | // write html 29 | break; 30 | } 31 | case "file": { 32 | // write to file 33 | break; 34 | } 35 | // additional implementations of output 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/madlib/MadLib.java: -------------------------------------------------------------------------------- 1 | package madlib; 2 | 3 | class MadLib { 4 | 5 | private String sentence; 6 | private String wordType1; 7 | private String wordType2; 8 | private String wordType3; 9 | 10 | MadLib(String sentence, String wordType1, String wordType2, String wordType3) { 11 | this.setSentence(sentence); 12 | this.wordType1 = wordType1; 13 | this.wordType2 = wordType2; 14 | this.wordType3 = wordType3; 15 | } 16 | 17 | String getMadLibSummary() { 18 | String convertedSentence = sentence.replace("%s", "{%s}"); 19 | return String.format(convertedSentence, wordType1, wordType2, wordType3); 20 | } 21 | 22 | String getSentence() { 23 | return sentence; 24 | } 25 | 26 | void setSentence(String sentence) { 27 | this.sentence = sentence.replace("_", "%s"); 28 | } 29 | 30 | String getWordType1() { 31 | return wordType1; 32 | } 33 | 34 | void setWordType1(String wordType1) { 35 | this.wordType1 = wordType1; 36 | } 37 | 38 | String getWordType2() { 39 | return wordType2; 40 | } 41 | 42 | void setWordType2(String wordType2) { 43 | this.wordType2 = wordType2; 44 | } 45 | 46 | String getWordType3() { 47 | return wordType3; 48 | } 49 | 50 | void setWordType3(String wordType3) { 51 | this.wordType3 = wordType3; 52 | } 53 | 54 | static void main(String[] args) { 55 | MadLib ml = new MadLib("Hello _ _ _.", "adjective", "adjective", "noun"); 56 | System.out.println(ml.getMadLibSummary()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/madlib/MadLibAnswer.java: -------------------------------------------------------------------------------- 1 | package madlib; 2 | 3 | public class MadLibAnswer { 4 | 5 | private String word1; 6 | private String word2; 7 | private String word3; 8 | 9 | private MadLib madlib; 10 | 11 | MadLibAnswer(String word1, String word2, String word3, MadLib madlib) { 12 | this.word1 = word1; 13 | this.word2 = word2; 14 | this.word3 = word3; 15 | this.madlib = madlib; 16 | } 17 | 18 | String returnUserVersion() { 19 | return String.format(madlib.getSentence(), word1, word2, word3); 20 | } 21 | 22 | public String getWord1() { 23 | return word1; 24 | } 25 | 26 | public void setWord1(String word1) { 27 | this.word1 = word1; 28 | } 29 | 30 | public String getWord2() { 31 | return word2; 32 | } 33 | 34 | public void setWord2(String word2) { 35 | this.word2 = word2; 36 | } 37 | 38 | public String getWord3() { 39 | return word3; 40 | } 41 | 42 | public void setWord3(String word3) { 43 | this.word3 = word3; 44 | } 45 | 46 | public MadLib getMadlib() { 47 | return madlib; 48 | } 49 | 50 | public void setMadlib(MadLib madlib) { 51 | this.madlib = madlib; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/madlib/MadLibGame.java: -------------------------------------------------------------------------------- 1 | package madlib; 2 | 3 | public class MadLibGame { 4 | 5 | private static void outputWelcome() { 6 | IoUtils.output("Welcome to the Mad Lib game!"); 7 | IoUtils.output("The first step is to create a Mad Lib. You will be prompted to enter a few things to do this."); 8 | } 9 | 10 | private static MadLib generateMadLib() { 11 | return MadLibUtils.createMadLib( 12 | "Please enter a sentence with three words missing. You should use a single underscore for each missing word...", 13 | "Please enter a word or phrase type for the first missing word...", 14 | "Please enter another word or phrase type for the second missing word...", 15 | "Please enter a final word or phrase type for the third missing word..."); 16 | } 17 | 18 | private static void outputMadLibDetails(MadLib ml) { 19 | IoUtils.output("The Mad Lib you created has the following structure..."); 20 | IoUtils.output(ml.getMadLibSummary()); 21 | } 22 | 23 | private static MadLibAnswer generateUserMadLib(MadLib ml) { 24 | IoUtils.output("Now that a Mad Lib has been created, try out silly answers!"); 25 | return MadLibUtils.fillInMadLib(ml); 26 | } 27 | 28 | private static void outputUserMadLib(MadLibAnswer mla) { 29 | IoUtils.output(mla.returnUserVersion()); 30 | } 31 | 32 | private static void outputClosingMsg() { 33 | IoUtils.output("\nThat was crazy!"); 34 | } 35 | 36 | private static void run() { 37 | outputWelcome(); 38 | MadLib ml = generateMadLib(); 39 | outputMadLibDetails(ml); 40 | MadLibAnswer mla = generateUserMadLib(ml); 41 | outputUserMadLib(mla); 42 | outputClosingMsg(); 43 | } 44 | 45 | public static void main(String[] args) { 46 | run(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/madlib/MadLibUtils.java: -------------------------------------------------------------------------------- 1 | package madlib; 2 | 3 | class MadLibUtils { 4 | 5 | private static String getSentence(String prompt) { 6 | IoUtils.output(IoUtils.nullCoalesceStr(prompt, "Please enter a sentence for the Mad Lib...")); 7 | return IoUtils.getScanner().nextLine(); 8 | } 9 | 10 | private static String getWordType(String prompt) { 11 | IoUtils.output(IoUtils.nullCoalesceStr(prompt, "Please enter a word...")); 12 | return IoUtils.getScanner().nextLine(); 13 | } 14 | 15 | private static String getWord( String prompt, String type) { 16 | IoUtils.output(IoUtils.nullCoalesceStr(prompt, "Please enter a word matching the following description: ") + type + "..."); 17 | return IoUtils.getScanner().nextLine(); 18 | } 19 | 20 | static MadLib createMadLib(String senPrompt, String wordType1Prompt, String wordType2Prompt, String wordType3Prompt) { 21 | String sentence = getSentence(senPrompt); 22 | String wordType1 = getWordType(wordType1Prompt); 23 | String wordType2 = getWordType(wordType2Prompt); 24 | String wordType3 = getWordType(wordType3Prompt); 25 | return new MadLib(sentence, wordType1, wordType2, wordType3); 26 | } 27 | 28 | static MadLibAnswer fillInMadLib(MadLib ml) { 29 | String word1 = getWord(null, ml.getWordType1()); 30 | String word2 = getWord(null, ml.getWordType2()); 31 | String word3 = getWord(null, ml.getWordType3()); 32 | return new MadLibAnswer(word1, word2, word3, ml); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/oopLecture/Arithmetic.java: -------------------------------------------------------------------------------- 1 | package oopLecture; 2 | 3 | // ======================== slide 5 (class fields) 4 | public class Arithmetic { 5 | 6 | // static property 7 | public static final double PI = 3.14159; 8 | 9 | // static methods 10 | public static int add(int x, int y) { 11 | return x + y; 12 | } 13 | 14 | public static int multiply(int x, int y) { 15 | return x * y; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/oopLecture/Dog.java: -------------------------------------------------------------------------------- 1 | package oopLecture; 2 | 3 | public class Dog { 4 | 5 | // relating to slide 3 6 | 7 | public String name; 8 | public String breed; 9 | public final String ANIMAL_TYPE = "Canine"; 10 | public boolean canBreed; 11 | public int age; 12 | 13 | // relating to slide 4 14 | public void callForDog(String name) { 15 | if (name.equalsIgnoreCase(this.name)) { 16 | System.out.println(this.name + " is now walking toward you!"); 17 | } else { 18 | System.out.println(this.name + " ignores you."); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/oopLecture/DogHelper.java: -------------------------------------------------------------------------------- 1 | package oopLecture; 2 | 3 | public class DogHelper { 4 | 5 | public static final int NUMBER_OF_DOG_BREEDS = 340; 6 | 7 | public static final int APPROX_POPULATION_OF_DOGS = 52000000; 8 | 9 | public static double humanToDogYears(double years) { 10 | return years * 7; 11 | } 12 | 13 | public static double ouncesOfFoodCalculator(double dogWeightInPounds) { 14 | return dogWeightInPounds * 0.5; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/oopLecture/OopLecture.java: -------------------------------------------------------------------------------- 1 | package oopLecture; 2 | 3 | public class OopLecture { 4 | 5 | public int testNum = 3; 6 | 7 | public static void main(String[] args) { 8 | 9 | // ======================== slide 3 (classes and objects) 10 | // 11 | // Person p1 = new Person(); 12 | // p1.firstName = "Justin"; 13 | // p1.lastName = "Reich"; 14 | // System.out.println(p1.lastName); 15 | 16 | // Person p2 = new Person(); 17 | // p2.firstName = "Justin"; 18 | // p2.lastName = "Reich"; 19 | 20 | // System.out.println(p1); 21 | // System.out.println(p2); 22 | 23 | // Person justinImposter = p2; 24 | // 25 | // System.out.println(justinImposter); 26 | // System.out.println(p2); 27 | 28 | // System.out.println(p1 == p2); 29 | 30 | // p1.firstName = "Rick"; 31 | // p1.lastName = "Sanchez"; 32 | // System.out.println(p1.firstName); 33 | // System.out.println(p1.lastName); 34 | 35 | 36 | // System.out.println(p1.firstName); 37 | // System.out.println(p1.lastName); 38 | 39 | // 40 | // Person fred = new Person(); 41 | // fred.firstName = "Fred"; 42 | // fred.lastName = "Smith"; 43 | // System.out.println(fred.firstName); 44 | // System.out.println(fred.lastName); 45 | 46 | 47 | 48 | // -- Dog Example -- 49 | 50 | 51 | // Dog d1 = new Dog(); 52 | // 53 | // d1.age = 3; 54 | // d1.breed = "corgi"; 55 | // d1.canBreed = false; 56 | // d1.name = "Tater"; 57 | 58 | 59 | 60 | // ======================== slide 4 (object fields) 61 | 62 | // Person rick = new Person(); 63 | // rick.firstName = "Rick"; 64 | // rick.lastName = "Sanchez"; 65 | // System.out.println(rick.sayHello()); 66 | 67 | // -- Dog Method Example -- 68 | 69 | // Dog d1 = new Dog(); 70 | // d1.age = 3; 71 | // d1.breed = "corgi"; 72 | // d1.canBreed = false; 73 | // d1.name = "Tater"; 74 | // 75 | // d1.callForDog("Tater"); 76 | 77 | 78 | // ======================== slide 5 (class fields) 79 | 80 | 81 | // System.out.println(Arithmetic.PI); 82 | // System.out.println(Arithmetic.add(5, 5)); 83 | // System.out.println(Arithmetic.multiply(5, 5)); 84 | 85 | // -- DogHelper Example -- 86 | 87 | // Dog dog = new Dog(); 88 | // dog.name = "Sparky"; 89 | // dog.age = 3; 90 | // dog.callForDog("Sparky"); 91 | // 92 | // 93 | // System.out.println(DogHelper.NUMBER_OF_DOG_BREEDS); 94 | // 95 | // // Sparky's Age in Dog Years 96 | // 97 | // System.out.println(DogHelper.humanToDogYears(dog.age)); 98 | 99 | 100 | 101 | 102 | 103 | // ======================== slide 7 (class vs. object fields) 104 | 105 | // Person theBestDrummerAlive = new Person(); 106 | // theBestDrummerAlive.name = "Neil Peart"; 107 | // Person.worldPopulation += 1; // accessing a static property 108 | // 109 | // System.out.println(Person.worldPopulation); 110 | // 111 | // // this also works, but is usually not a good idea 112 | // System.out.println(theBestDrummerAlive.worldPopulation); // 7500000001 113 | // System.out.println(theBestDrummerAlive.name); 114 | 115 | 116 | 117 | // ======================== slide 8 (constructors) 118 | 119 | // Student s1 = new Student("bob"); 120 | 121 | 122 | // Student jane = new Student("Jane Doe", "Zion"); 123 | // Student connor = new Student("Connor Wulf", "Jupiter"); 124 | // System.out.print(jane.name + " - "); 125 | // System.out.println(jane.cohort); // prints "Jane Doe - Zion" 126 | // Student john = new Student("John Doe"); 127 | // System.out.println(john.name + " - "); 128 | // System.out.println(john.cohort); // prints "John Doe - Unassigned" 129 | 130 | 131 | // ======================== slide 9 (this keyword) 132 | 133 | // Student jane = new Student("Jane Doe", "Zion"); 134 | // System.out.print(jane.name + " - "); 135 | // System.out.println(jane.cohort); // prints "Jane Doe - Zion" 136 | // Student john = new Student("John Doe"); 137 | // System.out.print(john.name + " - "); 138 | // System.out.println(john.cohort); // prints "John Doe - Unassigned" 139 | 140 | 141 | // ======================== slide 10 (visibility) 142 | 143 | // Student student = new Student("John Doe", 82.4); 144 | // System.out.println(student.name); // "John Doe" 145 | // student.name = "Robert Smith"; 146 | // System.out.println(student.name); 147 | //// // DON'T DO THIS - can't access private properties outside the class 148 | //// System.out.println(student.grade); 149 | // System.out.println(student.shareGrade()); // Do this instead 150 | // 151 | // student.changeGrade(70); 152 | // 153 | // System.out.println(student.shareGrade()); 154 | 155 | } 156 | 157 | 158 | } 159 | 160 | -------------------------------------------------------------------------------- /src/oopLecture/Person.java: -------------------------------------------------------------------------------- 1 | package oopLecture; 2 | 3 | public class Person { 4 | 5 | // // SLIDE 3 6 | // public String firstName; 7 | // public String lastName = "Smith"; 8 | // public char age; 9 | 10 | 11 | 12 | // SLIDE 4 13 | 14 | // // instance variables 15 | // public String firstName; 16 | // public String lastName; 17 | // 18 | // // instance method 19 | // public String sayHello(char punctuation) { 20 | // return lastName + ", " + firstName + " says hi" + punctuation; 21 | // } 22 | // 23 | // public String sayHello() { 24 | // return lastName + ", " + firstName + " says hi!"; 25 | // } 26 | 27 | 28 | 29 | // SLIDE 7 30 | public static long worldPopulation = 7_500_000_000L; // class property 31 | public String name; // instance property 32 | 33 | public void sayName(int length) { 34 | if (name.length() > length) { 35 | System.out.println("My long name is: " + name); 36 | } else { 37 | System.out.println("My name is: " + name); 38 | } 39 | } 40 | 41 | public void sayName() { 42 | System.out.println("My name is: " + name); 43 | } 44 | 45 | public static String findLongestName(Person p1, Person p2) { 46 | if (p1.name.length() > p2.name.length()) { 47 | return p1.name; 48 | } else { 49 | return p2.name; 50 | } 51 | } 52 | 53 | public static void main(String[] args) { 54 | 55 | // System.out.println(Person.worldPopulation); 56 | // Person.worldPopulation -= 1; 57 | // System.out.println(worldPopulation); 58 | // 59 | // 60 | Person theBestDrummerAlive = new Person(); 61 | theBestDrummerAlive.name = "Neil Peart"; 62 | theBestDrummerAlive.sayName(); 63 | 64 | Person notADrummer = new Person(); 65 | notADrummer.name = "Justin"; 66 | 67 | notADrummer.sayName(); 68 | 69 | String longestName = Person.findLongestName(theBestDrummerAlive, notADrummer); 70 | System.out.println(longestName); 71 | 72 | Person.worldPopulation += 1; // accessing a static property 73 | // // this also works, but is usually not a good idea 74 | // System.out.println(theBestDrummerAlive.worldPopulation); // 7500000001 75 | // // DONT DO THIS, it will not compile 76 | // System.out.println(Person.name); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/oopLecture/Post.java: -------------------------------------------------------------------------------- 1 | package oopLecture; 2 | 3 | import java.util.Date; 4 | 5 | public class Post { 6 | 7 | private long id; 8 | private String authorName; 9 | private int numberOfViews; 10 | private String content; 11 | private String title; 12 | private Date datePublished; 13 | 14 | public Post(long id, String authorName, int numberOfViews, String content, String title, Date datePublished) { 15 | this.id = id; 16 | this.authorName = authorName; 17 | this.numberOfViews = numberOfViews; 18 | this.content = content; 19 | this.title = title; 20 | this.datePublished = datePublished; 21 | } 22 | 23 | public Post(String authorName, int numberOfViews, String content, String title, Date datePublished) { 24 | this.authorName = authorName; 25 | this.numberOfViews = numberOfViews; 26 | this.content = content; 27 | this.title = title; 28 | this.datePublished = datePublished; 29 | } 30 | 31 | public long getId() { 32 | return id; 33 | } 34 | 35 | public void setId(long id) { 36 | this.id = id; 37 | } 38 | 39 | public String getAuthorName() { 40 | return authorName; 41 | } 42 | 43 | public void setAuthorName(String authorName) { 44 | this.authorName = authorName; 45 | } 46 | 47 | public int getNumberOfViews() { 48 | return numberOfViews; 49 | } 50 | 51 | public void setNumberOfViews(int numberOfViews) { 52 | this.numberOfViews = numberOfViews; 53 | } 54 | 55 | public String getContent() { 56 | return content; 57 | } 58 | 59 | public void setContent(String content) { 60 | this.content = content; 61 | } 62 | 63 | public String getTitle() { 64 | return title; 65 | } 66 | 67 | public void setTitle(String title) { 68 | this.title = title; 69 | } 70 | 71 | public Date getDatePublished() { 72 | return datePublished; 73 | } 74 | 75 | public void setDatePublished(Date datePublished) { 76 | this.datePublished = datePublished; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/oopLecture/Student.java: -------------------------------------------------------------------------------- 1 | package oopLecture; 2 | 3 | class Student { 4 | 5 | // ======================== slide 8 (constructors) 6 | 7 | // public String name; 8 | // public String cohort; 9 | // 10 | // public void testMethod() { 11 | // System.out.println("Will this run?"); 12 | // } 13 | // 14 | // public Student() { 15 | // System.out.println("New student created!"); 16 | // testMethod(); 17 | // } 18 | // 19 | // public Student(String studentName) { 20 | // this(); 21 | // name = studentName; 22 | // cohort = "Unassigned"; 23 | // } 24 | // 25 | // public Student(String studentName, String assignedCohort) { 26 | // name = studentName; 27 | // cohort = assignedCohort; 28 | // } 29 | // 30 | 31 | // ======================== slide 9 (this keyword) 32 | 33 | // public String name; 34 | // public String cohort; 35 | // 36 | // public Student(String name) { 37 | // this(name, "Unassigned"); 38 | // } 39 | // 40 | // public Student(String name, String cohort) { 41 | // this.name = name; 42 | // this.cohort = cohort; 43 | // } 44 | // 45 | // public String sayHello() { 46 | // return "Hello from " + this.name + "!"; 47 | // } 48 | 49 | 50 | // ======================== slide 10 (visibility) 51 | 52 | private String name; 53 | private double grade; 54 | 55 | public Student(String name, double grade) { 56 | this.name = name; 57 | this.grade = grade; 58 | } 59 | 60 | // getter 61 | public double shareGrade() { 62 | return grade; 63 | } 64 | 65 | // setter 66 | public void changeGrade(double grade) { 67 | this.grade = grade; 68 | } 69 | 70 | public String getName() { 71 | return name; 72 | } 73 | 74 | public void setName(String name) { 75 | this.name = name; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/shapes/Circle.java: -------------------------------------------------------------------------------- 1 | package shapes; 2 | 3 | public class Circle { 4 | private double radius; 5 | private static int circleCount = 0; 6 | 7 | public Circle(double rad){ 8 | this.radius = rad; 9 | circleCount++; 10 | } 11 | 12 | public double getArea(){ 13 | return Math.PI * (Math.pow(radius,2)); 14 | } 15 | public double getCircumference(){ 16 | return 2 * Math.PI * radius; 17 | } 18 | 19 | public static int getCircleCount(){ 20 | return circleCount; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/shapes/CircleApp.java: -------------------------------------------------------------------------------- 1 | package shapes; 2 | 3 | import util.Input; 4 | 5 | public class CircleApp { 6 | public static void main(String[] args) { 7 | Input input = new Input(); 8 | boolean answer = true; 9 | do{ 10 | double radius = input.getDouble(1,100); 11 | Circle circle1 = new Circle(radius); 12 | 13 | System.out.println("Circumference: " + circle1.getCircumference()); 14 | System.out.println("Area: " + circle1.getArea()); 15 | 16 | answer = input.yesNo("Do you want to create another circle?"); 17 | }while(answer); 18 | System.out.println("You've created " + Circle.getCircleCount() + " circles"); 19 | 20 | 21 | 22 | // System.out.println("Please enter the circle radius"); 23 | // double radius1 = input.getDouble(); 24 | // 25 | // Circle circle1 = new Circle(radius1); 26 | // System.out.println("Circumference: " + circle1.getCircumference()); 27 | // System.out.println("Area: " + circle1.getArea()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/shapes/Measurable.java: -------------------------------------------------------------------------------- 1 | package shapes; 2 | 3 | public interface Measurable { 4 | double getPerimeter(); 5 | double getArea(); 6 | } 7 | -------------------------------------------------------------------------------- /src/shapes/Quadrilateral.java: -------------------------------------------------------------------------------- 1 | package shapes; 2 | 3 | public abstract class Quadrilateral extends Shape implements Measurable { 4 | 5 | // Properties 6 | protected double length; 7 | protected double width; 8 | 9 | 10 | // Constructor 11 | public Quadrilateral(double length, double width) { 12 | this.length = length; 13 | this.width = width; 14 | } 15 | 16 | // Implement Override Methods 17 | @Override 18 | public double getPerimeter() { 19 | return 0; 20 | } 21 | 22 | @Override 23 | public double getArea() { 24 | return 0; 25 | } 26 | 27 | // Getters and Setters 28 | public double getLength() { 29 | return length; 30 | } 31 | 32 | // Implement these setters in a class that extends this abstract class 33 | public abstract void setLength(double length); 34 | 35 | public double getWidth() { 36 | return width; 37 | } 38 | 39 | // Implement these setters in a class that extends this abstract class 40 | public abstract void setWidth(double width); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/shapes/Rectangle.java: -------------------------------------------------------------------------------- 1 | package shapes; 2 | 3 | public class Rectangle extends Quadrilateral implements Measurable { 4 | protected double length; 5 | protected double width; 6 | 7 | public Rectangle(double l, double w){ 8 | // this.length = l; 9 | // this.width = w; 10 | // Use the super class' constructor 11 | super(l, w); 12 | } 13 | 14 | public double getArea(){ 15 | return length * width; 16 | } 17 | public double getPerimeter(){ 18 | return (2 * length) + (2 * width); 19 | } 20 | 21 | // Setters that were defined abstract in the abstract class "Quadrilateral" 22 | public void setWidth(double width) { 23 | this.width = width; 24 | } 25 | public void setLength(double length) { 26 | this.length = length; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/shapes/Shape.java: -------------------------------------------------------------------------------- 1 | package shapes; 2 | 3 | public abstract class Shape { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/shapes/ShapesTest.java: -------------------------------------------------------------------------------- 1 | package shapes; 2 | 3 | public class ShapesTest { 4 | public static void main(String[] args) { 5 | Rectangle box1 = new Rectangle(5,4); 6 | Square box2 = new Square(5); 7 | 8 | Measurable myShape; 9 | myShape = box1; 10 | System.out.println("Rectangle permiter is: " + myShape.getPerimeter()); 11 | System.out.println("Rectangle area is: " + myShape.getArea()); 12 | myShape = box2; 13 | System.out.println("Square permiter is: " + myShape.getPerimeter()); 14 | System.out.println("Square area is: " + myShape.getArea()); 15 | 16 | System.out.println(box1.getArea()); 17 | System.out.println(box1.getPerimeter()); 18 | 19 | System.out.println(box2.getArea()); 20 | System.out.println(box2.getPerimeter()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/shapes/Square.java: -------------------------------------------------------------------------------- 1 | package shapes; 2 | 3 | import org.w3c.dom.css.Rect; 4 | 5 | public class Square extends Quadrilateral { 6 | public Square(double side){ 7 | super(side,side); 8 | } 9 | 10 | // Constructor 11 | 12 | public double getArea(){ 13 | System.out.println("Square implementation of area"); 14 | return length * length; 15 | } 16 | 17 | public double getPerimeter(){ 18 | System.out.println("Square implementation of perimeter"); 19 | return 4 * length; 20 | } 21 | 22 | // Setters for the width and length (Quadrilateral abstract class says we have to define these here) 23 | public void setWidth(double width) { 24 | this.width = width; 25 | this.length = width; 26 | } 27 | public void setLength(double length) { 28 | this.length = length; 29 | this.width = length; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/util/Input.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Input { 6 | private Scanner sc; 7 | 8 | public Input(){ 9 | this.sc = new Scanner(System.in); 10 | } 11 | 12 | public String getString(){ 13 | return this.sc.nextLine(); 14 | } 15 | 16 | public String getString(String prompt){ 17 | System.out.println(prompt); 18 | return getString(); 19 | } 20 | 21 | public boolean yesNo(){ 22 | return yesNo("Please enter yes or no."); 23 | // String input = this.sc.next(); 24 | // return (input.trim().toLowerCase().equals("y") || 25 | // input.trim().toLowerCase().equals("yes")); 26 | } 27 | 28 | public boolean yesNo(String prompt){ 29 | System.out.println(prompt); 30 | String input = this.sc.next(); 31 | return (input.trim().toLowerCase().equals("y") || 32 | input.trim().toLowerCase().equals("yes")); 33 | } 34 | 35 | 36 | public int getInt(){ 37 | System.out.println("Please enter an int."); 38 | return this.sc.nextInt(); 39 | } 40 | 41 | public int getInt(int min, int max){ 42 | return getInt(min,max,"Please enter an int between "+min+" and "+max); 43 | // int input; 44 | // do{ 45 | // System.out.printf("Please enter an int between %d and %d%n", min, max); 46 | // input = this.sc.nextInt(); 47 | // }while(input < min || input > max); 48 | // 49 | // return input; 50 | } 51 | 52 | public int getInt(int min, int max,String prompt){ 53 | int input; 54 | do{ 55 | System.out.println(prompt); 56 | input = this.sc.nextInt(); 57 | }while(input < min || input > max); 58 | 59 | return input; 60 | } 61 | 62 | public double getDouble(){ 63 | System.out.println("Please enter a double."); 64 | return this.sc.nextDouble(); 65 | } 66 | 67 | public double getDouble(double min, double max){ 68 | return getDouble(min,max,"Please enter a double between "+min+" and "+max); 69 | // double input; 70 | // do{ 71 | // System.out.printf("Please enter a double between %.2f and %.2f%n", min, max); 72 | // input = this.sc.nextDouble(); 73 | // }while(input < min || input > max); 74 | // 75 | // return input; 76 | } 77 | 78 | public double getDouble(double min, double max,String prompt){ 79 | double input; 80 | do{ 81 | System.out.println(prompt); 82 | input = this.sc.nextDouble(); 83 | }while(input < min || input > max); 84 | 85 | return input; 86 | } 87 | 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/util/InputTest.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | public class InputTest { 4 | public static void main(String[] args) { 5 | System.out.println("Please follow the instructions"); 6 | 7 | Input input = new Input(); 8 | 9 | System.out.println(input.yesNo()); 10 | System.out.println(input.getInt(1,10)); 11 | System.out.println(input.getDouble(10,20)); 12 | } 13 | } 14 | --------------------------------------------------------------------------------