├── .gitignore └── hw0 ├── .gitignore ├── README ├── Solutions.java ├── TestNoJUnit.java └── Tester.java /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | sentinel 3 | __pycache__ 4 | 5 | # Created by https://www.gitignore.io/api/java,eclipse,intellij,emacs,vim 6 | 7 | ### Java ### 8 | *.class 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | 18 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 19 | hs_err_pid* 20 | 21 | 22 | ### Eclipse ### 23 | *.pydevproject 24 | .metadata 25 | .gradle 26 | bin/ 27 | tmp/ 28 | *.tmp 29 | *.bak 30 | *.swp 31 | *~.nib 32 | local.properties 33 | .settings/ 34 | .loadpath 35 | 36 | # Eclipse Core 37 | .project 38 | 39 | # External tool builders 40 | .externalToolBuilders/ 41 | 42 | # Locally stored "Eclipse launch configurations" 43 | *.launch 44 | 45 | # CDT-specific 46 | .cproject 47 | 48 | # JDT-specific (Eclipse Java Development Tools) 49 | .classpath 50 | 51 | # Java annotation processor (APT) 52 | .factorypath 53 | 54 | # PDT-specific 55 | .buildpath 56 | 57 | # sbteclipse plugin 58 | .target 59 | 60 | # TeXlipse plugin 61 | .texlipse 62 | 63 | 64 | ### Intellij ### 65 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio 66 | 67 | *.iml 68 | 69 | ## Directory-based project format: 70 | .idea/ 71 | # if you remove the above rule, at least ignore the following: 72 | 73 | # User-specific stuff: 74 | # .idea/workspace.xml 75 | # .idea/tasks.xml 76 | # .idea/dictionaries 77 | 78 | # Sensitive or high-churn files: 79 | # .idea/dataSources.ids 80 | # .idea/dataSources.xml 81 | # .idea/sqlDataSources.xml 82 | # .idea/dynamic.xml 83 | # .idea/uiDesigner.xml 84 | 85 | # Gradle: 86 | # .idea/gradle.xml 87 | # .idea/libraries 88 | 89 | # Mongo Explorer plugin: 90 | # .idea/mongoSettings.xml 91 | 92 | ## File-based project format: 93 | *.ipr 94 | *.iws 95 | 96 | ## Plugin-specific files: 97 | 98 | # IntelliJ 99 | /out/ 100 | 101 | # mpeltonen/sbt-idea plugin 102 | .idea_modules/ 103 | 104 | # JIRA plugin 105 | atlassian-ide-plugin.xml 106 | 107 | # Crashlytics plugin (for Android Studio and IntelliJ) 108 | com_crashlytics_export_strings.xml 109 | crashlytics.properties 110 | crashlytics-build.properties 111 | 112 | 113 | ### Emacs ### 114 | # -*- mode: gitignore; -*- 115 | *~ 116 | \#*\# 117 | /.emacs.desktop 118 | /.emacs.desktop.lock 119 | *.elc 120 | auto-save-list 121 | tramp 122 | .\#* 123 | 124 | # Org-mode 125 | .org-id-locations 126 | *_archive 127 | 128 | # flymake-mode 129 | *_flymake.* 130 | 131 | # eshell files 132 | /eshell/history 133 | /eshell/lastdir 134 | 135 | # elpa packages 136 | /elpa/ 137 | 138 | # reftex files 139 | *.rel 140 | 141 | # AUCTeX auto folder 142 | /auto/ 143 | 144 | # cask packages 145 | .cask/ 146 | 147 | 148 | ### Vim ### 149 | [._]*.s[a-w][a-z] 150 | [._]s[a-w][a-z] 151 | *.un~ 152 | Session.vim 153 | .netrwhist 154 | *~ 155 | 156 | 157 | -------------------------------------------------------------------------------- /hw0/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.py 3 | *.jar 4 | *~ 5 | -------------------------------------------------------------------------------- /hw0/README: -------------------------------------------------------------------------------- 1 | The only skeleton file in this assignment is Tester.java, which you 2 | can use to test your solution. Create whatever files you need to hold your 3 | solution and use 'git add` to tell git about them before committing and 4 | submitting. 5 | -------------------------------------------------------------------------------- /hw0/Solutions.java: -------------------------------------------------------------------------------- 1 | /** Solutions to the HW0 Java101 exercises. 2 | * @author Allyson Park and [INSERT YOUR NAME HERE] 3 | */ 4 | public class Solutions { 5 | 6 | /** Returns whether or not the input x is even. 7 | */ 8 | public static boolean isEven(int x) { 9 | // TODO: Your code here. Replace the following return statement. 10 | return false; 11 | } 12 | 13 | // TODO: Fill in the method signatures for the other exercises 14 | // Your methods should be static for this HW. DO NOT worry about what this means. 15 | // Note that "static" is not necessarily a default, it just happens to be what 16 | // we want for THIS homework. In the future, do not assume all methods should be 17 | // static. 18 | 19 | } 20 | -------------------------------------------------------------------------------- /hw0/TestNoJUnit.java: -------------------------------------------------------------------------------- 1 | /** Tests for hw0. 2 | * @author YOUR NAME HERE 3 | */ 4 | public class Tester { 5 | 6 | /* Feel free to add your own tests. For now, you can just follow 7 | * the pattern you see here. We'll look into the details of JUnit 8 | * testing later. 9 | * 10 | * To actually run the tests, just use 11 | * java Tester 12 | * (after first compiling your files). 13 | * 14 | * DON'T put your HW0 solutions here! Put them in a separate 15 | * class and figure out how to call them from here. You'll have 16 | * to modify the calls to max, threeSum, and threeSumDistinct to 17 | * get them to work, but it's all good practice! */ 18 | 19 | public static void isEvenTest() { 20 | System.out.println("isEven(2) should be true, result: " + Solutions.isEven(2)); 21 | System.out.println("isEven(10) should be true, result: " + Solutions.isEven(10)); 22 | System.out.println("isEven(1) should be false, result: " + Solutions.isEven(1)); 23 | System.out.println("isEven(99) should be false, result: " + Solutions.isEven(1)); 24 | } 25 | 26 | public static void maxTest() { 27 | // Change call to max to make this call yours. 28 | System.out.println("max {1, 2, 3, 4, 5} should return 5, result: " 29 | + Solutions.max(new int[] { 1, 2, 3, 4, 5 })); 30 | System.out.println("max {0, -5, 2, 14, 10} should return 14, result: " 31 | + Solutions.max(new int[] { 0, -5, 2, 14, 10 })); 32 | System.out.println("max {1} should return 1, result: " 33 | + Solutions.max(new int[] { 1 })); 34 | // REPLACE THIS WITH MORE TESTS. 35 | } 36 | // 37 | // @Test 38 | // public void wordBankTest() { 39 | // String[] adjectives = new String[]{"big", "cool", "fast"}; 40 | // assertTrue(wordBank("big", adjectives)); 41 | // assertFalse(wordBank("dog", adjectives)); 42 | // } 43 | // 44 | // @Test 45 | // public void threeSumTest() { 46 | // // Change call to threeSum to make this call yours. 47 | // assertTrue(Solutions.threeSum(new int[] { 1, 2, -3 })); // 1 + 2 - 3 = 0 48 | // assertTrue(Solutions.threeSum(new int[] { -6, 3, 10, 200 })); // 3 + 3 - 6 = 0 49 | // assertFalse(Solutions.threeSum(new int[] {1, -900, 7})); 50 | // // REPLACE THIS WITH MORE TESTS. 51 | // } 52 | 53 | public static void main(String[] unused) { 54 | isEvenTest(); 55 | System.out.println(""); 56 | maxTest(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /hw0/Tester.java: -------------------------------------------------------------------------------- 1 | /** Tests for hw0. 2 | * @author YOUR NAME HERE 3 | */ 4 | public class Tester { 5 | 6 | /* Feel free to add your own tests. For now, you can just follow 7 | * the pattern you see here. We'll look into the details of JUnit 8 | * testing later. 9 | * 10 | * To actually run the tests, just use 11 | * java Tester 12 | * (after first compiling your files). 13 | * 14 | * DON'T put your HW0 solutions here! Put them in a separate 15 | * class and figure out how to call them from here. You'll have 16 | * to modify the calls to max, threeSum, and threeSumDistinct to 17 | * get them to work, but it's all good practice! */ 18 | 19 | 20 | /* Helpful formatting method for running tests. 21 | Prints out a statement if the test fails. */ 22 | private static void assertTrue(boolean answer, String test) { 23 | if (!answer) { 24 | System.out.printf("Executing %s, expected true and received %b.%n", test, answer); 25 | } 26 | } 27 | 28 | /* Helpful formatting method for running tests. 29 | Prints out a statement if the test fails. */ 30 | private static void assertFalse(boolean answer, String test) { 31 | if (answer) { 32 | System.out.printf("Executing %s, expected false and received %b.%n", test, answer); 33 | } 34 | } 35 | 36 | /* Helpful formatting method for running tests. 37 | Prints out a statement if the test fails. */ 38 | private static void assertIntEquals(int a, int b, String test) { 39 | if (!(a == b)) { 40 | System.out.printf("Executing %s, expected %d and received %d.%n", test, a, b); 41 | } 42 | } 43 | 44 | public static void isEvenTest() { 45 | // Change call to max to make this call yours. 46 | assertTrue(Solutions.isEven(2), "IsEvenTest"); 47 | assertTrue(Solutions.isEven(10), "IsEvenTest"); 48 | assertFalse(Solutions.isEven(1), "IsEvenTest"); 49 | assertFalse(Solutions.isEven(99), "IsEvenTest"); 50 | // REPLACE THIS WITH MORE TESTS. 51 | } 52 | 53 | // // UNCOMMENT EVERYTHING BELOW TO RUN MORE TESTS. 54 | 55 | // public static void maxTest() { 56 | // // Change call to max to make this call yours. 57 | // assertIntEquals(5, Solutions.max(new int[] { 1, 2, 3, 4, 5 }), "maxTest"); 58 | // assertIntEquals(14, Solutions.max(new int[] { 0, -5, 2, 14, 10 }), "maxTest"); 59 | // assertIntEquals(1, Solutions.max(new int[] {1}), "maxTest"); 60 | // // REPLACE THIS WITH MORE TESTS. 61 | // } 62 | // 63 | // public static void wordBankTest() { 64 | // // Change call to threeSum to make this call yours. 65 | // String[] adjectives = new String[]{"big", "cool", "fast"}; 66 | // assertTrue(Solutions.wordBank("big", adjectives), "wordBankTest"); 67 | // assertFalse(Solutions.wordBank("dog", adjectives), "wordBankTest"); 68 | // // REPLACE THIS WITH MORE TESTS. 69 | // } 70 | // 71 | // public static void threeSumTest() { 72 | // // Change call to threeSum to make this call yours. 73 | // assertTrue(Solutions.threeSum(new int[] { 1, 2, -3 }), "3SUM Test"); // 1 + 2 - 3 = 0 74 | // assertTrue(Solutions.threeSum(new int[] { -6, 3, 10, 200 }), "3SUM Test"); // 3 + 3 - 6 = 0 75 | // assertFalse(Solutions.threeSum(new int[] {1, -900, 7}), "3SUM Test"); 76 | // // REPLACE THIS WITH MORE TESTS. 77 | // } 78 | 79 | public static void main(String[] unused) { 80 | System.out.println("Make sure you've uncommented all the test you wish to run."); 81 | System.out.println("ALL FAILURES SHOWN BELOW (if none, congrats! you're good.)"); 82 | isEvenTest(); 83 | 84 | // // UNCOMMENT THE LINES BELOW 85 | // maxTest(); 86 | // wordBankTest(); 87 | // threeSumTest(); 88 | } 89 | 90 | } 91 | --------------------------------------------------------------------------------