Power of Squares done :D

This commit is contained in:
LinlyBoi
2022-01-28 22:06:55 +02:00
parent f1bbde4908
commit 3173c9caa1
8 changed files with 233 additions and 2 deletions

View File

@@ -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));
}
}

View File

@@ -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;
}
}

View File

@@ -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]);
}
}
}

View File

@@ -33,6 +33,7 @@ public class Product
@Override
public String toString()
{

View File

@@ -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());
}
}