commit d45a2994e86ca6328575d952dc566a85a6d9d795 Author: sulzlep Date: Sat Jul 13 12:44:25 2024 +0200 Starting git repo for working on files diff --git a/module1/CMYKtoRGB.class b/module1/CMYKtoRGB.class new file mode 100644 index 0000000..8fb306e Binary files /dev/null and b/module1/CMYKtoRGB.class differ diff --git a/module1/CMYKtoRGB.java b/module1/CMYKtoRGB.java new file mode 100644 index 0000000..9d6b5a2 --- /dev/null +++ b/module1/CMYKtoRGB.java @@ -0,0 +1,23 @@ +public class CMYKtoRGB +{ + public static void main(String [] args){ + double cyan = Double.parseDouble(args[0]); + double magenta = Double.parseDouble(args[1]); + double yellow = Double.parseDouble(args[2]); + double black = Double.parseDouble(args[3]); + + double white = 1 - black; + double red = 255 * white * (1 - cyan); + double green = 255 * white * (1 - magenta); + double blue = 255 * white * (1 - yellow); + + int decimal_red = (int) Math.round(red); + int decimal_green = (int) Math.round(green); + int decimal_blue = (int) Math.round(blue); + + System.out.println("red = " + decimal_red); + System.out.println("green = " + decimal_green); + System.out.println("blue = " + decimal_blue); + } +} + diff --git a/module1/GreatCircle.class b/module1/GreatCircle.class new file mode 100644 index 0000000..5af8f43 Binary files /dev/null and b/module1/GreatCircle.class differ diff --git a/module1/GreatCircle.java b/module1/GreatCircle.java new file mode 100644 index 0000000..4f23e17 --- /dev/null +++ b/module1/GreatCircle.java @@ -0,0 +1,23 @@ +public class GreatCircle +{ + public static void main(String [] args){ + + + double x1 = Math.toRadians(Double.parseDouble(args[0])); + double y1 = Math.toRadians(Double.parseDouble(args[1])); + double x2 = Math.toRadians(Double.parseDouble(args[2])); + double y2 = Math.toRadians(Double.parseDouble(args[3])); + + double t1 = (x2 - x1) / 2.0; + double t2 = (y2 - y1) / 2.0; + double q1 = Math.pow(Math.sin(t1), 2); + double q2 = Math.pow(Math.sin(t2), 2); + + double as = q1 + (Math.cos(x1) * Math.cos(x2) * q2); + double sq = Math.sqrt(as); + + double distance = 2 * 6371.0 * Math.asin(sq); + + System.out.println(distance + " kilometers"); + } +} diff --git a/module1/HelloGoodbye.class b/module1/HelloGoodbye.class new file mode 100644 index 0000000..2a28932 Binary files /dev/null and b/module1/HelloGoodbye.class differ diff --git a/module1/HelloGoodbye.java b/module1/HelloGoodbye.java new file mode 100644 index 0000000..dba8634 --- /dev/null +++ b/module1/HelloGoodbye.java @@ -0,0 +1,10 @@ +public class HelloGoodbye +{ + public static void main(String [] args){ + String name1 = args[0]; + String name2 = args[1]; + + System.out.println("Hello " + name2 + " and " + name1 + "."); + System.out.println("Goodbye " + name2 + " and " + name1 + "."); + } +} diff --git a/module1/HelloWorld.class b/module1/HelloWorld.class new file mode 100644 index 0000000..8e5c63c Binary files /dev/null and b/module1/HelloWorld.class differ diff --git a/module1/HelloWorld.java b/module1/HelloWorld.java new file mode 100644 index 0000000..4f31510 --- /dev/null +++ b/module1/HelloWorld.java @@ -0,0 +1,6 @@ +public class HelloWorld { + public static void main(String [] args) + { + System.out.println("Hello, World"); + } +} diff --git a/module1/RightTriangle.class b/module1/RightTriangle.class new file mode 100644 index 0000000..fc56d27 Binary files /dev/null and b/module1/RightTriangle.class differ diff --git a/module1/RightTriangle.java b/module1/RightTriangle.java new file mode 100644 index 0000000..72aed04 --- /dev/null +++ b/module1/RightTriangle.java @@ -0,0 +1,20 @@ +public class RightTriangle +{ + public static void main(String [] args){ + int a = Integer.parseInt(args[0]); + int b = Integer.parseInt(args[1]); + int c = Integer.parseInt(args[2]); + boolean isPositive; + boolean isSquare; + boolean result; + + isPositive = (a >= 0) && (b >= 0) && (c >= 0); + int square_a = a * a; + int square_b = b * b; + int square_c = c * c; + isSquare = ( square_a + square_b) == square_c || (square_b + square_c) == square_a || (square_a + square_c) == square_b; + result = isPositive && isSquare; + + System.out.println(result); + } +} diff --git a/module1/hello.zip b/module1/hello.zip new file mode 100644 index 0000000..f6c7675 Binary files /dev/null and b/module1/hello.zip differ diff --git a/module2/BandMatrix.class b/module2/BandMatrix.class new file mode 100644 index 0000000..459feb3 Binary files /dev/null and b/module2/BandMatrix.class differ diff --git a/module2/BandMatrix.java b/module2/BandMatrix.java new file mode 100644 index 0000000..7f17181 --- /dev/null +++ b/module2/BandMatrix.java @@ -0,0 +1,24 @@ +public class BandMatrix +{ + public static void main(String[] args) + { + int n = Integer.parseInt(args[0]); + int width = Integer.parseInt(args[1]); + + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + if ((j - i <= width) && (i -j <= width)) + { + System.out.print(" * "); + } + else + { + System.out.print(" 0 "); + } + } + System.out.println("\n"); + } + } +} diff --git a/module2/GeneralizedHarmonic.class b/module2/GeneralizedHarmonic.class new file mode 100644 index 0000000..a535487 Binary files /dev/null and b/module2/GeneralizedHarmonic.class differ diff --git a/module2/GeneralizedHarmonic.java b/module2/GeneralizedHarmonic.java new file mode 100644 index 0000000..beefb0b --- /dev/null +++ b/module2/GeneralizedHarmonic.java @@ -0,0 +1,23 @@ +public class GeneralizedHarmonic +{ + public static void main(String[] args) + { + int n = Integer.parseInt(args[0]); + int r = Integer.parseInt(args[1]); + if (r >= 0 && n >= 0) + { + double h = 0; + double breuk = 0; + for (int i = 1; i <= n; i++ ) + { + breuk = 1/(Math.pow(i,r)); + h += breuk; + } + System.out.println(h); + } + else + { + System.out.println("Negative number in one of the arguments"); + } + } +} diff --git a/module2/RandomWalker.class b/module2/RandomWalker.class new file mode 100644 index 0000000..c627333 Binary files /dev/null and b/module2/RandomWalker.class differ diff --git a/module2/RandomWalker.java b/module2/RandomWalker.java new file mode 100644 index 0000000..d9e5b31 --- /dev/null +++ b/module2/RandomWalker.java @@ -0,0 +1,25 @@ +public class RandomWalker +{ + public static void main(String[] args) + { + int r = Integer.parseInt(args[0]); + + int xCoordinate = 0; + int yCoordinate = 0; + int steps = 0; + + System.out.println("(" + xCoordinate + ", " + yCoordinate + ")" ); + + while(Math.abs(xCoordinate) + Math.abs(yCoordinate) < r) + { + if(Math.random() <= 0.25) xCoordinate += 1; + else if (Math.random() <= 0.50) xCoordinate -= 1; + else if (Math.random() <= 0.75) yCoordinate += 1; + else yCoordinate -= 1; + + System.out.println("(" + xCoordinate + ", " + yCoordinate + ")" ); + steps++; + } + System.out.println("steps = " + steps); + } +} diff --git a/module2/RandomWalkers.class b/module2/RandomWalkers.class new file mode 100644 index 0000000..656a188 Binary files /dev/null and b/module2/RandomWalkers.class differ diff --git a/module2/RandomWalkers.java b/module2/RandomWalkers.java new file mode 100644 index 0000000..73e9b39 --- /dev/null +++ b/module2/RandomWalkers.java @@ -0,0 +1,31 @@ +public class RandomWalkers +{ + public static void main(String[] args) + { + int r = Integer.parseInt(args[0]); + int trials = Integer.parseInt(args[1]); + + int xCoordinate = 0; + int yCoordinate = 0; + int steps = 0; + double average = 0; + + //System.out.println("(" + xCoordinate + ", " + yCoordinate + ")" ); + + for(int i = 1; i <= trials; i++) + { + while(Math.abs(xCoordinate) + Math.abs(yCoordinate) < r) + { + if(Math.random() <= 0.25) xCoordinate += 1; + else if (Math.random() <= 0.50) xCoordinate -= 1; + else if (Math.random() <= 0.75) yCoordinate += 1; + else yCoordinate -= 1; + + //System.out.println("(" + xCoordinate + ", " + yCoordinate + ")" ); + steps++; + } + } + average = (float) steps / trials; + System.out.println("average number of steps = " + average); + } +} diff --git a/module2/loops.zip b/module2/loops.zip new file mode 100644 index 0000000..6b9df69 Binary files /dev/null and b/module2/loops.zip differ