Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Is the **blank** object mutable or immutable? How can you tell?

```text
PUT ANSWER TO #2 HERE
The "blank" object in this code is mutable. It has defined coordinates in main and then riddle uses point p to modify blank.
```

```java
Expand Down Expand Up @@ -47,7 +47,7 @@ public class Puzzler {
* Explain how the return values from #3 and #4 differ.

```text
PUT ANSWER TO #5 HERE
findCenter provides the center coordinates of a rectangle while distance calculates the distance between two points.
```

```java
Expand Down Expand Up @@ -87,14 +87,14 @@ Recall that aliases are two variables that refer to the same object.
* Put the output in the text block below

```text
PUT ANSWER TO #2 HERE
(5,8)
```

3. At the end of main, are p1 and p2 aliased? Why or why not?
* Put your answer in the text block below

```text
PUT ANSWER TO #3 HERE
At the end of main method, p1 and p2 are not pointing to the same object. They're both from box1 but if you change box1 it won't directly affect p1 or p2.
```

```java
Expand Down Expand Up @@ -142,6 +142,9 @@ for (int i = 0; i < s.length(); i++) {
* Screenshot your output and add it to your project as Part3_2.jpg
3. Generalize the code so that it works on any string.
* What could you do to generalize it more?
```text
You can add more specific parameters
```

## Part 4: Large Numbers

Expand Down
24 changes: 22 additions & 2 deletions src/BigIntRewrite.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
public class BigIntRewrite {
public static void main(String[] args) {
/**
* @authot Trevor Hartman
* @author Alexei Iachkov
* @date 3-31-24
* @version 1.0
*/
import java.math.BigInteger;

public class BigIntRewrite {
public static BigInteger pow(int x, int n) {
if (n == 0) {
return BigInteger.valueOf(1);
} else if (n == 1) {
return BigInteger.valueOf(x);
} else {
BigInteger result = BigInteger.valueOf(x);
int count = 1;
while (count < n) {
result = result.multiply(BigInteger.valueOf(x));
count++;
}
return result;
}
}
}
Binary file added src/Part1_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Part1_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Part1_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Part2_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Part3_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 33 additions & 1 deletion src/StringPlayground.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
/**
* @author Trevor Hartman
* @author Alexei Iachkov
* @date 3-31-24
* @version 1.0
*/
public class StringPlayground {

public static int countParentheses(String input) {
int count = 0;

for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (c == '(') {
count++;
} else if (c == ')') {
count--;
}
}
return count;
}

public static void main(String[] args) {
String testyString1 = "((3 + 7) * 2)";
String testyString2 = "()())))";
String testyString3 = "(()(()()(())))";
String testyString4 = "((()))))";

System.out.println("Parentheses count for String1: " + countParentheses(testyString1));
System.out.println("Parentheses count for String2: " + countParentheses(testyString2));
System.out.println("Parentheses count for String3: " + countParentheses(testyString3));
System.out.println("Parentheses count for String4: " + countParentheses(testyString4));
}
}
}

//this code can be generalized more by adding more specific parameters such as other brackets and using true/false instead of integers