Created the first Exercises for Variables and Primitives

main
1925458 2024-04-16 15:24:31 +02:00
commit ba8948806f
30 changed files with 374 additions and 0 deletions

10
.classpath 100644
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
.project 100644
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>javalings</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View File

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

17
README.md 100644
View File

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,8 @@
/**
*
*/
/**
*
*/
module javalings {
}

View File

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

View File

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

View File

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