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
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions src/Aliasing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.awt.Point;
import java.awt.Rectangle;

public class Aliasing {
public static void printPoint(Point p) {
System.out.println("(" + p.x + ", " + p.y + ")");
}

public static Point findCenter(Rectangle box) {
int x = box.x + box.width / 2;
int y = box.y + box.height / 2;
return new Point(x, y);
}

public static void main(String[] args) {
Rectangle box1 = new Rectangle(2, 4, 7, 9);
Point p1 = findCenter(box1); // Creates a new Point object based on box1's coordinates
printPoint(p1); // Prints the center of box1

box1.grow(1, 1); // Increases the size of box1 by 1 unit in all directions

Point p2 = findCenter(box1); // Creates a new Point object based on the modified box1's coordinates
printPoint(p2); // Prints the center of the modified box1
}
}
24 changes: 24 additions & 0 deletions src/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Person {
private String name;

public Person(String theName) {
this.name = theName;
}
}

public class Student extends Person {
private int id;
public static int nextId = 1;

public Student(String theName) {
super(theName);
id = nextId++;
}

public static void main(String[] args) {
Person e1 = new Student("Alice");
Person e2 = new Student("Bob");
Person e3 = new Student("Carol");
Person arrayOfPeople[] = {e1, e2, e3};
}
}
29 changes: 28 additions & 1 deletion src/StringPlayground.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
public class StringPlayground {
public static int countParentheses(String s) {
int count = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '(') {
count++;
} else if (c == ')') {
count--;
}
}
return count;
}

public static void main(String[] args) {
String[] testStrings = {
"((3 + 7) * 2)", // Balanced
"((3 + 7) * 2))", // Unbalanced
"((3 + 7) * 2))(", // Unbalanced
"", // Empty
"((((((", // Unbalanced
"))))))", // Unbalanced
"()" // Balanced
};

for (String s : testStrings) {
int result = countParentheses(s);
System.out.println("String: \"" + s + "\", Parentheses Count: " + result);
}
}
}
}