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
10 changes: 10 additions & 0 deletions .idea/material_theme_project_new.xml

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

2 changes: 1 addition & 1 deletion .idea/misc.xml

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

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# java-2025-syntax
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/P7QlOs71)
# java-2025-syntax
# Rodenko 307 Group
225 changes: 209 additions & 16 deletions src/main/java/ua/university/BasicOperators.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ua.university;


import java.util.Arrays;

/**
* BasicOperators class contains a set of static methods
* for practicing Java operators, loops, arrays, and branching.
Expand All @@ -16,14 +18,24 @@ public class BasicOperators {
* @return double array where [0] = sum, [1] = average
*/
public static double[] sumAndAverage(int a, int b, int c) {
return null;
double[] result = new double[2];

result[0] = a + b + c;
result[1] = result[0] / 3;

return result;
}

/**
* Returns the maximum of three integers.
*/
public static int maxOfThree(int a, int b, int c) {
return 0;
if( a > b && a > c)
return a;
else if (b > a && b > c)
return b;
else
return c;
}

/**
Expand All @@ -45,105 +57,286 @@ public static int maxOfThree(int a, int b, int c) {
* @throws IllegalArgumentException if {@code score} is less than 0 or greater than 100
*/
public static char gradeFromScore(int score) {
return '0';
if(score < 0 || score > 100)
throw new IllegalArgumentException();

if(score < 50)
return 'F';
else if (score < 60)
return 'E';
else if (score < 70)
return 'D';
else if(score < 80)
return 'C';
else if(score < 90)
return 'B';
else
return 'A';
}

/**
* Returns the day of the week name for a number 1-7.
*/
public static String dayOfWeek(int day) {
return null;
if(day > 0 && day <= 7) {
switch (day) {
case 1:
return "Monday";
case 2:
return "Tuesday";
case 3:
return "Wednesday";
case 4:
return "Thursday";
case 5:
return "Friday";
case 6:
return "Saturday";
case 7:
return "Sunday";
}
}
throw new IllegalArgumentException();
}

/**
* Returns an array counting down from n to 1.
*/
public static int[] countdown(int n) {
return null;
if(n < 0)
throw new IllegalArgumentException();

int[] counting = new int[n];

for(int i = n, j = 0; i > 0; i--, j ++)
counting[j] = i;

return counting;
}

/**
* Returns factorial of n.
*/
public static long factorial(int n) {
return 0;
if(n < 0)
throw new IllegalArgumentException();

if(n == 0)
return 1;
return n * factorial(n-1);
}

/**
* Returns a reversed copy of the array.
*/
public static int[] reverseArray(int[] arr) {
return null;
if(arr == null || arr.length == 0)
throw new IllegalArgumentException();

int[] reverse = new int[arr.length];

for(int i = arr.length-1, j = 0; i >=0; i--, j++)
reverse[j] = arr[i];

return reverse;
}

/**
* Returns sum of all elements in a 2D array (matrix).
*/
public static int sumMatrix(int[][] matrix) {
return 0;
if(matrix == null || matrix.length == 0)
throw new IllegalArgumentException();

int sum = 0;

for(int i = 0; i < matrix[0].length; i++)
for(int j = 0; j < matrix[0].length; j++)
sum += matrix[i][j];

return sum;
}

/**
* Checks if a string is a palindrome.
*/
public static boolean isPalindrome(String s) {
return false;
if (s == null || s.isEmpty())
throw new IllegalArgumentException();

StringBuilder reverse_s = new StringBuilder();
int n = s.length() - 1;
for(int i = n; i >= 0; i--)
reverse_s.append(s.charAt(i));

if(s.equals(reverse_s.toString()))
return true;
else
return false;
}

/**
* Returns minimum and maximum of an array.
*/
public static int[] findMinMax(int[] arr) {
return null;
if(arr.length == 0)
throw new IllegalArgumentException();

int[] min_and_max = new int[2];
int min, max;
min = max = 0;

for(int num: arr){
if(num > max)
max = num;
else if(num < min)
min = num;
}
min_and_max[0] = min;
min_and_max[1] = max;

return min_and_max;
}

/**
* Returns multiplication table n x n.
*/
public static int[][] multiplicationTable(int n) {
return null;
if (n == 0)
throw new IllegalArgumentException();

int[][] matrix = new int[n][n];

for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
matrix[i][j] = (i + 1) * (j + 1);

return matrix;
}

/**
* Returns all even numbers up to n.
*/
public static int[] evenNumbersUpToN(int n) {
return null;
if (n < 0)
throw new IllegalArgumentException();


int[] even_numbers = new int[n / 2];
int j = 0;

for(int i = 2; i <= n; i+=2)
even_numbers[j++] = i;

return even_numbers;
}

/**
* Checks if a number is prime.
*/
public static boolean isPrime(int n) {
if(n == 2 || (n % 2 != 0 && n % 3 != 0))
return true;
return false;
}

/**
* Counts vowels in a string.
*/
public static int countVowels(String s) {
return 0;
int count = 0;

for (char c : s.toCharArray()) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
count++;
}
}

return count;
}

/**
* Returns first n Fibonacci numbers.
*/
public static int[] fibonacci(int n) {
return null;
if(n < 0)
throw new IllegalArgumentException();
if (n == 0)
return new int[0]; // пустой массив
if (n == 1)
return new int[] {1};

int[] numbers = new int[n];
numbers[0] = 0; numbers[1] = 1;

for(int i = 2; i < n; i++)
numbers[i] = numbers[i-1] + numbers[i-2];

return numbers;
}

/**
* Returns the transpose of a 2D array (matrix).
*/
public static int[][] transpose(int[][] matrix) {
return null;
if (matrix == null)
throw new IllegalArgumentException();

int rows = matrix.length;
int cols = matrix[0].length;

int[][] transposed = new int[cols][rows];

for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
transposed[j][i] = matrix[i][j];

return transposed;
}

/**
* Returns a sorted copy of the array in ascending order.
*/
public static int[] sortArray(int[] arr) {
return null;
boolean swapped;
int start, end;
int tmp;
int[] sort_array = new int[arr.length];
System.arraycopy(arr, 0, sort_array, 0, arr.length);

swapped = true; start = 0;end = arr.length - 1;

while (swapped) {
swapped = false;
for (int i = start; i < end; i++) {
if (sort_array[i] > sort_array[i + 1]) {
tmp = sort_array[i];
sort_array[i] = sort_array[i + 1];
sort_array[i + 1] = tmp;

swapped = true;
}
}

if (!swapped)
break;

end--;
swapped = false;
for (int i = end; i > start; i--) {
if (sort_array[i] < sort_array[i - 1]) {
tmp = sort_array[i];
sort_array[i] = sort_array[i - 1];
sort_array[i - 1] = tmp;

swapped = true;
}
}

start++;
}

return sort_array;
}

}