Testeksamne, og andre ting

This commit is contained in:
2025-12-03 11:33:58 +01:00
parent 7d790d8126
commit 2c91d6de4a
17 changed files with 3337 additions and 0 deletions

8
Testeksamen/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

9
Testeksamen/.idea/Testeksamen.iml generated Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

5
Testeksamen/.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KubernetesApiProvider"><![CDATA[{}]]></component>
<component name="ProjectRootManager" version="2" project-jdk-name="21" project-jdk-type="JavaSDK" />
</project>

8
Testeksamen/.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Testeksamen.iml" filepath="$PROJECT_DIR$/.idea/Testeksamen.iml" />
</modules>
</component>
</project>

6
Testeksamen/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

21
Testeksamen/Draw.java Normal file
View File

@@ -0,0 +1,21 @@
public class Draw{
public static void main(String[] args) {
figure(8);
figure(4);
figure(2);
}
public static void figure(int n){
for(int i = 0; i < n; i++) {
for(int j = 0; j < i; j++) {
System.out.print(" ");
}
for(int j = 0; j < (2 * n) - 1 - (i*2); j++){
System.out.print("*");
}
System.out.println();
}
}
}

70
Testeksamen/Example.java Normal file
View File

@@ -0,0 +1,70 @@
public class Example {
public static void main(String[] args) {
boolean m[][] = { { true, false, true, true },
{ true, false, true, false },
{ true, false, true, true } };
System.out.println("++++++++++++");
Grid g = new Grid(m);
System.out.println(g);
System.out.println("++++++++++++");
g.update();
System.out.println(g);
System.out.println("++++++++++++");
}
}
public class Data {
private int major;
private int minor;
private boolean active;
public Data(int major, int minor, boolean active) {
this.major = Math.max(0, major);
this.minor = Math.max(0, minor);
this.active = active;
}
public int getMajor() {
return this.major;
}
public int getMinor() {
return this.minor;
}
public boolean getActive() {
return this.active;
}
public void parity() {
this.major = this.major % 2;
this.minor = this.minor % 2;
}
public String toString() {
return "" + this.major + (this.active ? "**" : "//") + this.minor;
}
}
public class Grid {
private Data[] a;
public Grid(boolean[][] m) {
this.a = new Data[m[0].length * m.length];
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m[i].length; j++) {
this.a[(m[0].length * i)+j] = new Data(i, j, m[i][j]);
}
}
}
public void update() {
for (int i = 0; i < this.a.length; i++) {
if (this.a[i].getActive()) {
this.a[i].parity();
}
}
}
public String toString() {
String return_string = "";
for (int i = 0; i < this.a.length; i++) {
return_string += this.a[i] + (i == this.a.length - 1 ? "" : "-");
}
return return_string;
}
}

25
Testeksamen/Loop.java Normal file
View File

@@ -0,0 +1,25 @@
import java.util.Scanner;
import java.util.ArrayList;
public class Loop {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
ArrayList<String> words = new ArrayList<>();
System.out.println("Please enter \"STOP\" to stop.");
while (true) {
System.out.print("Enter a word: ");
String next_word = console.next();
words.add(next_word);
if (next_word.equals("STOP")) {
break;
}
}
System.out.println("Here are the word lengths:");
for (int i = 0; i < words.size(); i++) {
String word = words.get(i);
System.out.println(word + " " + word.length());
}
System.out.println("The last word was \"STOP\" of course.");
}
}

58
Testeksamen/Main.java Normal file
View File

@@ -0,0 +1,58 @@
public class Main {
public static void main(String[] args) {
Vektor x = new Vektor("Kasper", 123456789);
Rektor y = new Rektor("Jesper", 3.14);
Lektor z = new Lektor("Jonathan");
Person[] a = { x, y, z };
printArray(a);
}
public static void printArray(Object[] a) {
for (int i = 0; i < a.length; i++) {
System.out.println(i + " " + a[i]);
}
}
}
public class Person {
private String navn;
public Person(String navn) {
this.navn = navn;
}
public String toString() {
return this.navn;
}
}
public class Vektor extends Person {
private int id;
public Vektor(String navn, int id) {
super(navn);
this.id = id;
}
public String toString() {
return "Vektor:" + super.toString() + ";" + this.id;
}
}
public class Rektor extends Person {
private double id;
public Rektor(String navn, double id) {
super(navn);
this.id = id;
}
public String toString() {
return "Rektor:" + super.toString() + ";" + this.id;
}
}
public class Lektor extends Person {
public Lektor(String navn) {
super(navn);
}
public String toString() {
return "Lektor:" + super.toString();
}
}

BIN
Testeksamen/Test.pdf Normal file

Binary file not shown.

View File

@@ -0,0 +1,14 @@
public class Example {
public static void main(String[] args) {
boolean m[][] = { { true, false, true, true },
{ true, false, true, false },
{ true, false, true, true } };
System.out.println("++++++++++++");
Grid g = new Grid(m);
System.out.println(g);
System.out.println("++++++++++++");
g.update();
System.out.println(g);
System.out.println("++++++++++++");
}
}

View File

@@ -0,0 +1,15 @@
public class Main {
public static void main(String[] args) {
Vektor x = new Vektor("Kasper", 123456789);
Rektor y = new Rektor("Jesper", 3.14);
Lektor z = new Lektor("Jonathan");
Person[] a = { x, y, z };
printArray(a);
}
public static void printArray(Object[] a) {
for (int i = 0; i < a.length; i++) {
System.out.println(i + " " + a[i]);
}
}
}

2885
Testeksamen/testeksamen.pdf Normal file

File diff suppressed because one or more lines are too long

161
Testeksamen/testeksamen.typ Normal file
View File

@@ -0,0 +1,161 @@
#import("@local/dtu-template:0.5.1"):*
#show: dtu-programming-assignment.with(
course: "02100",
course-name: "Indledende Programmering og Softwareteknologi, Efterår 2025",
title: "Tetseksamen",
author: "s255955",
programming-language: "Java",
semester: "2025 Fall",
)
= Opgave 1
```
public static void figure(int n){
for(int i = 0; i < n; i++) {
for(int j = 0; j < i; j++) {
System.out.print(" ");
}
for(int j = 0; j < (2 * n) - 1 - (i*2); j++){
System.out.print("*");
}
System.out.println();
}
}
```
= Opgave 2
```
import java.util.Scanner;
import java.util.ArrayList;
public class Loop {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
ArrayList<String> words = new ArrayList<>();
System.out.println("Please enter \"STOP\" to stop.");
while (true) {
System.out.print("Enter a word: ");
String next_word = console.next();
words.add(next_word);
if (next_word.equals("STOP")) {
break;
}
}
System.out.println("Here are the word lengths:");
for (int i = 0; i < words.size(); i++) {
String word = words.get(i);
System.out.println(word + " " + word.length());
}
System.out.println("The last word was \"STOP\" of course.");
}
}
```
= Opgave 3
```
public class Data {
private int major;
private int minor;
private boolean active;
public Data(int major, int minor, boolean active) {
this.major = Math.max(0, major);
this.minor = Math.max(0, minor);
this.active = active;
}
public int getMajor() {
return this.major;
}
public int getMinor() {
return this.minor;
}
public boolean getActive() {
return this.active;
}
public void parity() {
this.major = this.major % 2;
this.minor = this.minor % 2;
}
public String toString() {
return "" + this.major + (this.active ? "**" : "//") + this.minor;
}
}
public class Grid {
private Data[] a;
public Grid(boolean[][] m) {
this.a = new Data[m[0].length * m.length];
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m[i].length; j++) {
this.a[(m[0].length * i)+j] = new Data(i, j, m[i][j]);
}
}
}
public void update() {
for (int i = 0; i < this.a.length; i++) {
if (this.a[i].getActive()) {
this.a[i].parity();
}
}
}
public String toString() {
String return_string = "";
for (int i = 0; i < this.a.length; i++) {
return_string += this.a[i] + (i == this.a.length - 1 ? "" : "-");
}
return return_string;
}
}
```
= Opgave 4
```
public class Person {
private String navn;
public Person(String navn) {
this.navn = navn;
}
public String toString() {
return this.navn;
}
}
public class Vektor extends Person {
private int id;
public Vektor(String navn, int id) {
super(navn);
this.id = id;
}
public String toString() {
return "Vektor:" + super.toString() + ";" + this.id;
}
}
public class Rektor extends Person {
private double id;
public Rektor(String navn, double id) {
super(navn);
this.id = id;
}
public String toString() {
return "Rektor:" + super.toString() + ";" + this.id;
}
}
public class Lektor extends Person {
public Lektor(String navn) {
super(navn);
}
public String toString() {
return "Lektor:" + super.toString();
}
}
```