From 3173c9caa129c3fe7358520cc2a54a2bb5d5fcae Mon Sep 17 00:00:00 2001 From: LinlyBoi Date: Fri, 28 Jan 2022 22:06:55 +0200 Subject: [PATCH] Power of Squares done :D --- .idea/codeStyles/codeStyleConfig.xml | 5 ++ .idea/vcs.xml | 6 ++ DeansBequest.iml | 41 ++++++++++++ src/Emploice/Programs.java | 13 +++- src/MathRelated/PowerOfSquares.java | 87 +++++++++++++++++++++++++ src/MathRelated/PowerOfSquaresTest.java | 63 ++++++++++++++++++ src/Products/Product.java | 1 + src/Products/ProductTest.java | 19 ++++++ 8 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/vcs.xml create mode 100644 src/MathRelated/PowerOfSquares.java create mode 100644 src/MathRelated/PowerOfSquaresTest.java create mode 100644 src/Products/ProductTest.java diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DeansBequest.iml b/DeansBequest.iml index c90834f..1efa802 100644 --- a/DeansBequest.iml +++ b/DeansBequest.iml @@ -7,5 +7,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Emploice/Programs.java b/src/Emploice/Programs.java index e6eb7f1..7d57c57 100644 --- a/src/Emploice/Programs.java +++ b/src/Emploice/Programs.java @@ -1,11 +1,16 @@ package Emploice; import java.util.Random; +import java.util.Arrays; public class Programs { public static void main(String[] args) { + Employees Medhat = new Employees(20); + Employees Hamada = Medhat; + if(Medhat.getYears() == Hamada.getYears()) + System.out.println("El dof3a be yeso7o 3ala el fady"); Employees[] employs = new Employees[100]; for(int j = 0; j < employs.length; j++) @@ -13,12 +18,16 @@ public class Programs Random r = new Random(); employs[j] = new Employees(r.nextInt(1,50)); } - for(int i = 0; i < employs.length; i++) + + for(int i = 0; i < employs.length; i++) { - if(employs[i].getYears() >= 20) + if(employs[i].getYears() >= 20) System.out.println(employs[i].toString()); } + //System.out.println(Arrays.toString(employs)); + + } } \ No newline at end of file diff --git a/src/MathRelated/PowerOfSquares.java b/src/MathRelated/PowerOfSquares.java new file mode 100644 index 0000000..2ead395 --- /dev/null +++ b/src/MathRelated/PowerOfSquares.java @@ -0,0 +1,87 @@ +package MathRelated; + +public class PowerOfSquares +{ + public int IntegerPower(int base, int power) + { + + if(power == 0) + return 1; + + else + { + int count = 0; + while (count <= power) + { + base = base * base; + } + return base; + } + /* else //unlucky this is not required scammed + { + int count = -power; + while(count <= power) + { + base = base / base; + } + } + + */ + } + + public static void Square(int side , char c) + { + for (int i = 0; i < side; i++) + { + for (int j = 0; j < side; j++) + { + + System.out.print(c); + } + System.out.print("\n"); + + } + } + public static void Rectangle(int length , int width , char c) + { + for (int i = 0; i < length; i++) + { + for (int j = 0; j < width; j++) + { + + System.out.print(c); + } + System.out.print("\n"); + + } + } + public static void sortarray(int[] array) + { + int count = 0; + while(count < array.length) + { + for (int i = 0; i < array.length; i++) + { + if(i < array.length -2) + { + + if (array[i] > array[i+1]) + swap(i,i+1,array); + count++; + } + } + } + + } + public static void swap(int a , int b, int[] array) + { + int temp = 0; + array[a] = temp; + array[a] = array[b]; + array[b] = temp; + + } + + + +} diff --git a/src/MathRelated/PowerOfSquaresTest.java b/src/MathRelated/PowerOfSquaresTest.java new file mode 100644 index 0000000..4488b54 --- /dev/null +++ b/src/MathRelated/PowerOfSquaresTest.java @@ -0,0 +1,63 @@ +package MathRelated; + +import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class PowerOfSquaresTest extends PowerOfSquares +{ + + @Test + public void integerPower() + { + assertEquals(27,IntegerPower(3,3)); + assertEquals(4,IntegerPower(2,2)); + assertEquals(1,IntegerPower(2,0)); + } + + @Test + public void squareTest() + { + Square(4,'#'); + Square(10,'a'); + Square(5,'v'); + Square(1,'c'); + Square(6,'s'); + Square(2,'o'); + Square(2,'p'); + Square(8,'l'); + Square(9,'i'); + + } + + @Test + void RectangleTest() + { + Rectangle(10,20,'c'); + Rectangle(10,20,'#'); + Rectangle(10,20,'@'); + Rectangle(10,20,'*'); + Rectangle(10,20,'A'); + } + + @Test + public void sortarrayTest() + + { + int[] array = new int[10]; + int[] hypothesis = {1,2,3,4,5,6,7,8,9,10}; + int filler = array.length; + for(int i =array.length-1; i >=0; i--) + { + array[i] = filler; + filler--; + + } + sortarray(array); + for(int i = 0; i < hypothesis.length; i++) + { + assertEquals(hypothesis[i] , array[i]); + } + + } +} diff --git a/src/Products/Product.java b/src/Products/Product.java index 55835b8..e825ede 100644 --- a/src/Products/Product.java +++ b/src/Products/Product.java @@ -33,6 +33,7 @@ public class Product + @Override public String toString() { diff --git a/src/Products/ProductTest.java b/src/Products/ProductTest.java new file mode 100644 index 0000000..8e942bd --- /dev/null +++ b/src/Products/ProductTest.java @@ -0,0 +1,19 @@ +package Products; + +import org.junit.jupiter.api.Test; + +import java.util.Date; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class ProductTest { + + @Test + public void checkExpiredTest() + { + Date d1 = new Date(2025,10,10); + Product p1 = new Product("A1",100,d1); + assertFalse(p1.checkExpired()); + + } +}