commit ba8948806f2596330bcd5e6fff86988cff94d645 Author: 1925458 <1925458tud.hs-mannheim.de> Date: Tue Apr 16 15:24:31 2024 +0200 Created the first Exercises for Variables and Primitives diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..57bca72 --- /dev/null +++ b/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..9c23653 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + javalings + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..8c9943d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/README.md b/README.md new file mode 100644 index 0000000..8e652dd --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# javalings + +## About + +The javalings repository is attempting to recreate the rustlings programm, +which is an introduction into the rust language. Respectivly, javalings +attempts to recreate that form of introduction for the java language. This +ressource is primarilly meant to be an additional ressource for students of the +university of applied science mannheim, however anyone interested in +understanding the java language can and should be able to follow this, as the +course should be as newbie friendly as possible. + +## Work in Progress + +javalings is a Work in Progress, as time alloted to this project is minimal and +does not enjoy priority in my project list at this moment. PRs may therefore +also take a while to review diff --git a/bin/datatypes/Primitives1.class b/bin/datatypes/Primitives1.class new file mode 100644 index 0000000..fd8e689 Binary files /dev/null and b/bin/datatypes/Primitives1.class differ diff --git a/bin/datatypes/Primitives2.class b/bin/datatypes/Primitives2.class new file mode 100644 index 0000000..41b868d Binary files /dev/null and b/bin/datatypes/Primitives2.class differ diff --git a/bin/datatypes/Primitives3.class b/bin/datatypes/Primitives3.class new file mode 100644 index 0000000..c176d63 Binary files /dev/null and b/bin/datatypes/Primitives3.class differ diff --git a/bin/datatypes/Primitives4.class b/bin/datatypes/Primitives4.class new file mode 100644 index 0000000..7fd4a67 Binary files /dev/null and b/bin/datatypes/Primitives4.class differ diff --git a/bin/datatypes/Primitives5.class b/bin/datatypes/Primitives5.class new file mode 100644 index 0000000..293799b Binary files /dev/null and b/bin/datatypes/Primitives5.class differ diff --git a/bin/datatypes/Primitives6.class b/bin/datatypes/Primitives6.class new file mode 100644 index 0000000..6338a3d Binary files /dev/null and b/bin/datatypes/Primitives6.class differ diff --git a/bin/datatypes/Primitives8.class b/bin/datatypes/Primitives8.class new file mode 100644 index 0000000..f19055b Binary files /dev/null and b/bin/datatypes/Primitives8.class differ diff --git a/bin/datatypes/Strings1.class b/bin/datatypes/Strings1.class new file mode 100644 index 0000000..8aee772 Binary files /dev/null and b/bin/datatypes/Strings1.class differ diff --git a/bin/module-info.class b/bin/module-info.class new file mode 100644 index 0000000..94db48a Binary files /dev/null and b/bin/module-info.class differ diff --git a/bin/variables/Variables1.class b/bin/variables/Variables1.class new file mode 100644 index 0000000..46e8dd4 Binary files /dev/null and b/bin/variables/Variables1.class differ diff --git a/bin/variables/Variables2.class b/bin/variables/Variables2.class new file mode 100644 index 0000000..643b8be Binary files /dev/null and b/bin/variables/Variables2.class differ diff --git a/bin/variables/Variables3.class b/bin/variables/Variables3.class new file mode 100644 index 0000000..52aa73e Binary files /dev/null and b/bin/variables/Variables3.class differ diff --git a/src/datatypes/Primitives1.java b/src/datatypes/Primitives1.java new file mode 100644 index 0000000..b13df03 --- /dev/null +++ b/src/datatypes/Primitives1.java @@ -0,0 +1,25 @@ +package datatypes; + +public class Primitives1 { + + public static void main(String[] args) { + /* Modify below */ + + // Create a 'byte' variable named 'x' with the value '24' + + // Create a 'byte' variable named 'y' with the value '18' + + // Fix this + byte sum = x + y; + byte rest = x - y; + byte div = x / y; + byte prod = x * y; + + /* Modify above */ + System.out.println("x + y = " + sum); + System.out.println("x - y = " + rest); + System.out.println("x / y = " + div + ", did you expect this?"); + System.out.println("x * y = " + prod + ", did you expect this?"); + } + + } diff --git a/src/datatypes/Primitives2.java b/src/datatypes/Primitives2.java new file mode 100644 index 0000000..fe19098 --- /dev/null +++ b/src/datatypes/Primitives2.java @@ -0,0 +1,24 @@ +package datatypes; + +public class Primitives2 { + + public static void main(String[] args) { + /* Modify below */ + + // Create a 'short' variable named 'x' with the value '12_500' + + // Create a 'short' variable named 'y' with the value '4_000' + + // Fix this + short sum = x + y; + short rest = x - y; + short div = x / y; + short prod = x * y; + + /* Modify above */ + System.out.println("x + y = " + sum); + System.out.println("x - y = " + rest); + System.out.println("x / y = " + div + ", did you expect this?"); + System.out.println("x * y = " + prod + ", did you expect this?"); + } + } diff --git a/src/datatypes/Primitives3.java b/src/datatypes/Primitives3.java new file mode 100644 index 0000000..2f668b5 --- /dev/null +++ b/src/datatypes/Primitives3.java @@ -0,0 +1,28 @@ +package datatypes; +import java.text.NumberFormat; + +public class Primitives3 { + + public static void main(String[] args) { + /* Modify below */ + + // Create an 'int' variable named 'x' with the value '900_000_000' + + // Create an 'int' variable named 'y' with the value '700_000_000' + + // Fix this + int sum = x + y; + int rest = x - y; + int div = x / y; + int prod = x * y; + + /* Modify above */ + var nf = NumberFormat.getInstance(); + nf.setGroupingUsed(true); + + System.out.println("x + y = " + nf.format(sum)); + System.out.println("x - y = " + nf.format(rest)); + System.out.println("x / y = " + nf.format(div) + ", did you expect this?"); + System.out.println("x * y = " + nf.format(prod) + ", did you expect this?"); + } + } diff --git a/src/datatypes/Primitives4.java b/src/datatypes/Primitives4.java new file mode 100644 index 0000000..33e194f --- /dev/null +++ b/src/datatypes/Primitives4.java @@ -0,0 +1,30 @@ +package datatypes; + +import java.text.NumberFormat; + +public class Primitives4 { + + public static void main(String[] args) { + /* Modify below */ + + // Create a 'long' variable named 'x' with the value '4_000_000_000_000_000_000L' + + // Create a 'long' variable named 'y' with the value '3_000_000_000_000_000_000L' + + // Fix this + long sum = x + y; + long rest = x - y; + long div = x / y; + long prod = x * y; + + /* Modify above */ + + var nf = NumberFormat.getInstance(); + nf.setGroupingUsed(true); + + System.out.println("x + y = " + nf.format(sum)); + System.out.println("x - y = " + nf.format(rest)); + System.out.println("x / y = " + nf.format(div) + ", did you expect this?"); + System.out.println("x * y = " + nf.format(prod) + ", did you expect this?"); + } + } diff --git a/src/datatypes/Primitives5.java b/src/datatypes/Primitives5.java new file mode 100644 index 0000000..a3c6976 --- /dev/null +++ b/src/datatypes/Primitives5.java @@ -0,0 +1,31 @@ +package datatypes; + +public class Primitives5 { + + public static void main(String[] args) { + /* Modify below */ + + // Create a 'float' variable named 'x' with the value '21.8F' + + // Create a 'float' variable named 'y' with the value '7.4F' + + // Fix this + float sum = x + y; + float rest = x - y; + float div = x / y; + float prod = x * y; + + /* Modify above */ + System.out.println("x + y = " + sum); + System.out.println("x - y = " + rest); + System.out.println("x / y = " + div); + System.out.println("x * y = " + prod); + System.out.println(""" + + Some floating point operations can result in numbers + with strange decimal places. + + You have to keep that in mind when doing calculations. + """); + } + } diff --git a/src/datatypes/Primitives6.java b/src/datatypes/Primitives6.java new file mode 100644 index 0000000..9b7646d --- /dev/null +++ b/src/datatypes/Primitives6.java @@ -0,0 +1,31 @@ +package datatypes; + +public class Primitives6 { + + public static void main(String[] args) { + /* Modify below */ + + // Create a 'double' variable named 'x' with the value '21.8' + + // Create a 'double' variable named 'y' with the value '7.4' + + // Fix this + double sum = x + y; + double rest = x - y; + double div = x / y; + double prod = x * y; + + /* Modify above */ + System.out.println("x + y = " + sum); + System.out.println("x - y = " + rest); + System.out.println("x / y = " + div); + System.out.println("x * y = " + prod); + System.out.println(""" + + Some floating point operations can result in numbers + with strange decimal places. + + You have to keep that in mind when doing calculations. + """); + } + } \ No newline at end of file diff --git a/src/datatypes/Primitives7.java b/src/datatypes/Primitives7.java new file mode 100644 index 0000000..edd92c8 --- /dev/null +++ b/src/datatypes/Primitives7.java @@ -0,0 +1,28 @@ +package datatypes; + +public class Primitives8 { + + public static void main(String[] args) { + /* Modify below */ + + // Create a 'char' variable named 'x' with the value 'X' + + // Create a 'char' variable named 'y' with the value 'Y' + + // Fix this + char concat = x + y; + var multipleChars = "" + x + y; // Do not change this line + + /* Modify above */ + System.out.println("x has the value: " + x + "\n x is of type: " + getType(x)); + System.out.println("\ny has the value: " + y + "\n y is of type: " + getType(y)); + System.out.println("\nx + y = " + concat + "\n concat is of type: " + getType(concat)); + System.out.println( + "\n\"\" + x + y = " + multipleChars + "\n multipleChars is of type: " + getType(multipleChars)); + System.out.println("\nDid you expect these results?"); + } + + private static String getType(Object value) { + return value.getClass().getName(); + } + } diff --git a/src/datatypes/Primitives8.java b/src/datatypes/Primitives8.java new file mode 100644 index 0000000..edd92c8 --- /dev/null +++ b/src/datatypes/Primitives8.java @@ -0,0 +1,28 @@ +package datatypes; + +public class Primitives8 { + + public static void main(String[] args) { + /* Modify below */ + + // Create a 'char' variable named 'x' with the value 'X' + + // Create a 'char' variable named 'y' with the value 'Y' + + // Fix this + char concat = x + y; + var multipleChars = "" + x + y; // Do not change this line + + /* Modify above */ + System.out.println("x has the value: " + x + "\n x is of type: " + getType(x)); + System.out.println("\ny has the value: " + y + "\n y is of type: " + getType(y)); + System.out.println("\nx + y = " + concat + "\n concat is of type: " + getType(concat)); + System.out.println( + "\n\"\" + x + y = " + multipleChars + "\n multipleChars is of type: " + getType(multipleChars)); + System.out.println("\nDid you expect these results?"); + } + + private static String getType(Object value) { + return value.getClass().getName(); + } + } diff --git a/src/datatypes/Strings1.java b/src/datatypes/Strings1.java new file mode 100644 index 0000000..5f6630b --- /dev/null +++ b/src/datatypes/Strings1.java @@ -0,0 +1,24 @@ +package datatypes; + +public class Strings1 { + + public static void main(String[] args) { + /* Modify below */ + + // Create a 'String' variable named 'javalings' with the value 'javalings' + + // Create a 'String' variable named 'exercise' with the value 'exercise' + + String concat = javalings + exercise; + String concatWithSpaces = javalings + " " + exercise; + String concatFormatted = "%s %s".formatted(javalings, exercise); + String concatFormattedOld = String.format("%s %s", javalings, exercise); + + /* Modify above */ + System.out.println("concat = " + concat); + System.out.println("concatWithSpaces = " + concatWithSpaces); + System.out.println("concatFormatted = " + concatFormatted); + System.out.println("concatFormattedOld = " + concatFormattedOld); + + } + } diff --git a/src/module-info.java b/src/module-info.java new file mode 100644 index 0000000..6d0bdb7 --- /dev/null +++ b/src/module-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * + */ +module javalings { +} \ No newline at end of file diff --git a/src/variables/Variables1.java b/src/variables/Variables1.java new file mode 100644 index 0000000..c612d96 --- /dev/null +++ b/src/variables/Variables1.java @@ -0,0 +1,18 @@ +package variables; + +public class Variables1 { + public static void main(String[] args) { + /* Modify below */ + + // Create a 'byte' variable named 'smallest' with the value '100' + + // Create a 'short' variable named 'small' with the value '30000' + + // Create an 'int' variable named 'medium' with the value '1000000000' + + // modify the above + System.out.println("smallest has the value : " + smallest); + System.out.println("small has the value : " + small); + System.out.println("medium has the value : " + medium); + } +} diff --git a/src/variables/Variables2.java b/src/variables/Variables2.java new file mode 100644 index 0000000..5f76524 --- /dev/null +++ b/src/variables/Variables2.java @@ -0,0 +1,19 @@ +package variables; + +public class Variables2 { + + public static void main(String[] args) { + /* Modify below */ + + // Create a 'float' variable named 'precision' with the value '42.42F' + + // Create a 'double' variable named 'doublePrecision' with the value '123.321D' + + // Create a 'long' variable named 'hugeNumber' with the value '123456789987654321L' + + /* Modify above */ + System.out.println("floatingPointNumber has the value : " + precision); + System.out.println("doubleFloatingPointNumber has the value : " + doublePrecision); + System.out.println("hugeNumber has the value : " + hugeNumber); + } +} diff --git a/src/variables/Variables3.java b/src/variables/Variables3.java new file mode 100644 index 0000000..d27a3cb --- /dev/null +++ b/src/variables/Variables3.java @@ -0,0 +1,20 @@ +package variables; + +public class Variables3 { + + public static void main(String[] args) { + /* Modify below */ + + // Create a 'boolean' variable named 'trueFalse' with the value 'true' + + // Create a 'char' variable named 'character' with the value 'D' + + // Create a 'String' variable named 'text' with the value 'Hello there!' + + + /* Modify above */ + System.out.println("trueFalse has the value : " + trueFalse); + System.out.println("character has the value : " + character); + System.out.println("text has the value : " + text); + } +} \ No newline at end of file