5 Commits
Author SHA1 Message Date
MehrdadShirvani e73ac6115f Revert "fix: remove redundant comment"
This reverts commit 959c579550.
2026-04-18 19:38:33 +03:30
MehrdadShirvani 959c579550 fix: remove redundant comment 2026-04-18 19:30:23 +03:30
MehrdadShirvani 5780e034f1 fix: improve comments 2026-04-17 11:53:06 +03:30
MehrdadShirvani 3ac2a41574 Update README.md 2026-04-17 07:33:45 +00:00
MehrdadShirvani b89647da5e Update README.md 2026-04-17 07:16:58 +00:00
4 changed files with 66 additions and 47 deletions
+2 -2
View File
@@ -8,7 +8,7 @@ Follow these steps to set up your project:
### 0. Watch the introductory video ### 0. Watch the introductory video
We have recorded a special video, explaining the exact steps that needs to be taken to complete this assignment. We have recorded a special video, explaining the exact steps that needs to be taken to complete this assignment.
Here is the [link]() Here is the [link](https://drive.meshcomp.ir/d/c9138977a329485585ae/)
**Make sure to watch the video before starting the assignment.** **Make sure to watch the video before starting the assignment.**
@@ -226,7 +226,7 @@ Before starting, ensure you have:
## Getting Help ## Getting Help
- **Mentor contact:** Available during office hours and via [specify platform] - **Mentor contact**
- **Git documentation:** https://docs.meshcomp.ir/git - **Git documentation:** https://docs.meshcomp.ir/git
--- ---
+20 -3
View File
@@ -7,6 +7,17 @@ public class BonusExercises {
/* /*
complete the method below, so it will validate an email address complete the method below, so it will validate an email address
1. Must have exactly one @ (no more, no less)
2. Split into local-part and domain (before @ and after @)
3. Local-part rules:
- Can't be empty
- Can't start or end with dot
- Can't have two dots in a row
4. Domain rules:
- Can't be empty
- Can't start or end with hyphen
- Can't have underscores
- Each segment (between dots) must follow same hyphen rules
*/ */
public boolean validateEmail(String email) { public boolean validateEmail(String email) {
String regex = ""; // todo String regex = ""; // todo
@@ -17,9 +28,15 @@ public class BonusExercises {
} }
/* /*
this method should find a date in string This method should find and return the first date in a string.
note that it should be in british or american format
if there's no match for a date, return null Supported formats:
- American: MM/DD/YYYY (e.g., 12/09/2023)
- British: DD/MM/YYYY (e.g., 12/09/2023 — same pattern, context matters)
- ISO: YYYY-MM-DD (e.g., 2024-07-15)
- Slash variant: YYYY/MM/DD (e.g., 2025/01/01)
If no match for a date is found in the string, return null.
*/ */
public String findDate(String string) { public String findDate(String string) {
// todo // todo
+35 -25
View File
@@ -19,41 +19,47 @@ public class MainExercises
the output has to be a two-dimensional array of characters, so don't just print the triangle! the output has to be a two-dimensional array of characters, so don't just print the triangle!
*/ */
public char[][] generateTriangle(int n) { public char[][] generateTriangle(int n) {
char[][] triangle = new char[n][];
for(int i = 0; i < n; i++)
{
triangle[i] = new char[i+1];
for(int j = 0; j <= i; j++)
{
if(i == 0 || j == 0 || i == j || i == n-1)
triangle[i][j] = '*';
else
triangle[i][j] = ' ';
}
} // todo
return triangle; return null;
} }
/* /*
given a matrix of random integers, you should do spiral traversal in it SPIRAL TRAVERSAL OF A RECTANGULAR MATRIX
e.g. if the matrix is as shown below:
Given a rectangular matrix (2D array) of integers, this method traverses
it in a spiral order (clockwise from outside to inside) and returns
the elements as a 1D array.
EXAMPLE:
Input matrix:
1 2 3 1 2 3
4 5 6 4 5 6
7 8 9 7 8 9
then the spiral traversal of that is:
{1, 2, 3, 6, 9, 8, 7, 4, 5} Spiral order: start at top-left (1), go right →, then down ↓,
then left ←, then up ↑, then repeat inward.
Result: {1, 2, 3, 6, 9, 8, 7, 4, 5}
so you should walk in that matrix in a curl and then add the numbers in order you've seen them in a 1D array so you should walk in that matrix in a curl and then add the numbers in order you've seen them in a 1D array
*/
public int[] spiralTraversal(int[][] values, int rows, int cols) {
RECTANGULAR MATRIX ASSUMPTION:
This method assumes the input matrix is RECTANGULAR (all rows have
the same number of columns). In Java, we can verify this because
2D arrays might be jagged (rows of different lengths).
IMPORTANT: In Java, we do NOT need to pass rows and cols!
The 2D array 'matrix' knows its own dimensions:
- Number of rows: matrix.length
- Number of columns: matrix[0].length (if rectangular)
*/
public int[] spiralTraversal(int[][] matrix) {
// todo // todo
return null; return null;
} }
/* /*
@@ -72,14 +78,18 @@ public class MainExercises
2, 1, 1 2, 1, 1
1, 1, 1, 1 1, 1, 1, 1
note: as you can see in examples, we want to generate distinct summations, which means 1, 2 and 2, 1 are no different Note: As you can see in the examples, we want to generate distinct partitions,
you should generate all partitions of the input number and which means 1,2 and 2,1 are not different — they count as the same combination.
hint: you can measure the size and order of arrays by finding the pattern of partitions and their number You should generate all partitions of the input number.
trust me, that one's fun and easy :)
if you're familiar with lists and arraylists, you can also edit method's body to use them instead of array Hint: You can determine the size and order of the arrays by finding the pattern
of partitions and their count. Trust me, this one's fun and easy :)
If you're familiar with Lists and ArrayLists, you can also edit the method's
body to use them instead of arrays.
*/ */
public int[][] intPartitions(int n) { public int[][] intPartitions(int n) {
// todo // todo
return null; return null;
+4 -12
View File
@@ -16,10 +16,8 @@ public class MainTestTraversal {
int[][] nums = { int[][] nums = {
{1, 2, 3, 4, 5} {1, 2, 3, 4, 5}
}; };
int rows = 1;
int cols = 5;
int[] expected = {1, 2, 3, 4, 5}; int[] expected = {1, 2, 3, 4, 5};
assertArrayEquals(expected, ex.spiralTraversal(nums, rows, cols)); assertArrayEquals(expected, ex.spiralTraversal(nums));
} }
@Test @Test
@@ -30,10 +28,8 @@ public class MainTestTraversal {
{7, 8, 9}, {7, 8, 9},
{10, 11, 12} {10, 11, 12}
}; };
int rows = 4;
int cols = 3;
int[] expected = {1, 2, 3, 6, 9, 12, 11, 10, 7, 4, 5, 8}; int[] expected = {1, 2, 3, 6, 9, 12, 11, 10, 7, 4, 5, 8};
assertArrayEquals(expected, ex.spiralTraversal(nums, rows, cols)); assertArrayEquals(expected, ex.spiralTraversal(nums));
} }
@Test @Test
@@ -42,10 +38,8 @@ public class MainTestTraversal {
{1, 2, 3, 4}, {1, 2, 3, 4},
{5, 6, 7, 8} {5, 6, 7, 8}
}; };
int rows = 2;
int cols = 4;
int[] expected = {1, 2, 3, 4, 8, 7, 6, 5}; int[] expected = {1, 2, 3, 4, 8, 7, 6, 5};
assertArrayEquals(expected, ex.spiralTraversal(nums, rows, cols)); assertArrayEquals(expected, ex.spiralTraversal(nums));
} }
@Test @Test
@@ -57,10 +51,8 @@ public class MainTestTraversal {
{19, 20, 21, 22, 23, 24}, {19, 20, 21, 22, 23, 24},
{25, 26, 27, 28, 29, 30} {25, 26, 27, 28, 29, 30}
}; };
int rows = 5;
int cols = 6;
int[] expected = {1, 2, 3, 4, 5, 6, 12, 18, 24, 30, 29, 28, 27, 26, 25, 19, 13, 7, 8, 9, 10, 11, 17, 23, 22, 21, int[] expected = {1, 2, 3, 4, 5, 6, 12, 18, 24, 30, 29, 28, 27, 26, 25, 19, 13, 7, 8, 9, 10, 11, 17, 23, 22, 21,
20, 14, 15, 16}; 20, 14, 15, 16};
assertArrayEquals(expected, ex.spiralTraversal(nums, rows, cols)); assertArrayEquals(expected, ex.spiralTraversal(nums));
} }
} }