changed the file structure

This commit is contained in:
Sage The DM 2024-10-22 09:33:26 +02:00
parent b1c3582880
commit 6b23a757b6
70 changed files with 764 additions and 23 deletions

View file

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View file

@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,16 @@
// Luca Burger
// Aufgabe 12
public class App {
public static void main(String[] args) throws Exception {
Time myTime1 = new Time(5, 42);
Time myTime2 = new Time(3, 27);
Time myTime3 = new Time(5, 20);
Time myTime4 = new Time(3, 10);
Time myTime5 = new Time(3, 20);
System.out.println(Time.subtract(myTime3, myTime4));
System.out.println(Time.convertToMinute(myTime1));
}
}

Binary file not shown.

View file

@ -0,0 +1,37 @@
// Luca Burger
// Aufgabe 12
public class Time {
int hour;
int minute;
Time(int hour, int minute) {
this.hour = hour;
this.minute = minute;
}
void add(Time time, Time time2) {
time.hour += time2.hour;
time.minute += time2.minute;
}
static int subtract(Time time, Time time2) {
int minute1 = convertToMinute(time);
int minute2 = convertToMinute(time2);
return minute1 - minute2;
}
static int convertToMinute(Time time) {
int add = time.hour * 60;
return time.minute += add;
}
static String print(Time myTime) {
String text = "";
text += myTime.hour;
text += ":";
text += myTime.minute;
return text;
}
}

View file

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View file

@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,63 @@
import java.util.*;
public class App {
public static void main(String[] args) throws Exception {
Position player = new Position();
player.x = 0;
player.y = 0;
while (true) {
player.printPosition(player);
int direction = whereToMove(player);
int distance = howFar(player);
switch (direction) {
case 1:
player.goUp(distance);
break;
case 2:
player.goRight(distance);
break;
case 3:
player.goDown(distance);
break;
case 4:
player.goLeft(distance);
break;
default:
System.out.println("Was not a valid direction || distance");
break;
}
}
}
public static int whereToMove(Position player) {
Scanner scan = new Scanner(System.in);
int input;
while (true) {
System.out.println("Where do you want to move (1 up, 2 right, 3 down, 4 left)");
try {
input = scan.nextInt();
break;
} catch (Exception e) {
System.out.println("Input was not an int");
}
}
return input;
}
public static int howFar(Position player) {
Scanner scan = new Scanner(System.in);
int input;
while (true) {
System.out.println("How far?");
try {
input = scan.nextInt();
break;
} catch (Exception e) {
System.out.println("Input was not an int");
}
}
return input;
}
}

Binary file not shown.

View file

@ -0,0 +1,24 @@
public class Position {
int x;
int y;
void goLeft(int howFar) {
x = x - howFar;
}
void goRight(int howFar) {
x = x + howFar;
}
void goUp(int howFar) {
y = y - howFar;
}
void goDown(int howFar) {
y = y + howFar;
}
void printPosition(Position player) {
System.out.println("Player Position: (" + player.x + "/" + player.y + ")");
}
}

View file

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View file

@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,80 @@
public class Rectangle {
// Private attributes for length and width
private double length;
private double width;
// Constructor with two parameters to initialize the length and width
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
// Setter methods
public void setLength(double length) {
this.length = length;
}
public void setWidth(double width) {
this.width = width;
}
public void setSides(double length, double width) {
this.length = length;
this.width = width;
}
// Getter methods
public double getLength() {
return length;
}
public double getWidth() {
return width;
}
// Method to get the longer side
public double getLongerSide() {
return Math.max(length, width);
}
// Method to get the shorter side
public double getShorterSide() {
return Math.min(length, width);
}
// Method to calculate the diagonal of the rectangle
public double getDiagonal() {
return Math.sqrt(length * length + width * width);
}
// Method to calculate the area of the rectangle
public double getArea() {
return length * width;
}
// Method to calculate the perimeter of the rectangle
public double getPerimeter() {
return 2 * (length + width);
}
// Methods to adjust length and width
public void increaseLength(double l) {
length += l;
}
public void increaseWidth(double w) {
width += w;
}
public void decreaseLength(double l) {
length -= l;
if (length < 0)
length = 0; // Ensure length doesn't become negative
}
public void decreaseWidth(double w) {
width -= w;
if (width < 0)
width = 0; // Ensure width doesn't become negative
}
}

Binary file not shown.

View file

@ -0,0 +1,67 @@
import java.util.Scanner;
public class RectangleTest {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Get user input for length and width
System.out.print("Enter the length of the rectangle: ");
double length = scanner.nextDouble();
System.out.print("Enter the width of the rectangle: ");
double width = scanner.nextDouble();
// Create a Rectangle object
Rectangle rectangle = new Rectangle(length, width);
System.out.println("What do you want to do? (1: increase, 2: decrease)");
int input = scanner.nextInt();
if (input == 1) {
// Increase the dimension
System.out.println("Which dimension do you want to increase? (1: width, 2: length)");
input = scanner.nextInt();
if (input == 1) {
// Increase width
System.out.print("Increase width by: ");
double increaseBy = scanner.nextDouble();
rectangle.increaseWidth(increaseBy);
} else if (input == 2) {
// Increase length
System.out.print("Increase length by: ");
double increaseBy = scanner.nextDouble();
rectangle.increaseLength(increaseBy);
} else {
System.out.println("Invalid input for dimension choice.");
}
} else if (input == 2) {
// Decrease the dimension
System.out.println("Which dimension do you want to decrease? (1: width, 2: length)");
input = scanner.nextInt();
if (input == 1) {
// Decrease width
System.out.print("Decrease width by: ");
double decreaseBy = scanner.nextDouble();
rectangle.decreaseWidth(decreaseBy);
} else if (input == 2) {
// Decrease length
System.out.print("Decrease length by: ");
double decreaseBy = scanner.nextDouble();
rectangle.decreaseLength(decreaseBy);
} else {
System.out.println("Invalid input for dimension choice.");
}
} else {
System.out.println("Invalid input for action choice.");
}
// Display the results
System.out.println("Longer side: " + rectangle.getLongerSide());
System.out.println("Shorter side: " + rectangle.getShorterSide());
System.out.println("Diagonal: " + rectangle.getDiagonal());
System.out.println("Area: " + rectangle.getArea());
System.out.println("Perimeter: " + rectangle.getPerimeter());
scanner.close();
}
}

View file

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View file

@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,9 @@
public class App {
public static void main(String[] args) throws Exception {
Person myPerson1 = new Person("Hans", 200);
myPerson1.validTransaction(500);
System.out.println(myPerson1.getBalance());
myPerson1.setName("Luca");
System.out.println(myPerson1.getName());
}
}

Binary file not shown.

View file

@ -0,0 +1,29 @@
public class Person {
private String name;
private double balance;
Person(String person, double money) {
name = person;
balance = money;
}
boolean validTransaction(double money) {
if (balance + money >= 0) {
balance += money;
return true;
} else
return false;
}
void setName(String name) {
this.name = name;
}
String getName() {
return name;
}
double getBalance() {
return balance;
}
}

View file

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View file

@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,29 @@
public class App {
public static void main(String[] args) {
// Einige Tiere erstellen
Tier loewe = new Tier("Löwe", "Leo");
Tier elefant = new Tier("Elefant", "Dumbo");
Tier pinguin = new Tier("Pinguin", "Pingu");
// Gehege mit Kapazität von 5 Tieren erstellen
Gehege gehege1 = new Gehege(1, 5);
// Tiere zum Gehege hinzufügen
gehege1.hinzufuegenTier(loewe);
gehege1.hinzufuegenTier(elefant);
gehege1.hinzufuegenTier(pinguin);
// Informationen ausgeben
System.out.println("Gehege Nummer: " + gehege1.getNummer());
Tier[] tiereImGehege = gehege1.getTiere();
for (Tier tier : tiereImGehege) {
System.out.println("Tier: " + tier.getArt() + " - Name: " + tier.getName());
}
// Name eines Tieres ändern
loewe.setName("Simba");
// Überprüfen, ob der Name des Tieres aktualisiert wurde
System.out.println("Aktualisierter Name des Löwen: " + loewe.getName());
}
}

Binary file not shown.

View file

@ -0,0 +1,54 @@
public class Gehege {
private int nummer;
private Tier[] tierListe;
private int aktuelleAnzahlTiere;
private int kapazitaet;
// Konstruktor, der die Nummer und die Kapazität des Geheges annimmt
Gehege(int nummer, int kapazitaet) {
this.nummer = nummer;
this.kapazitaet = kapazitaet;
this.tierListe = new Tier[kapazitaet];
this.aktuelleAnzahlTiere = 0;
}
// Methode zum Hinzufügen eines Tieres
public void hinzufuegenTier(Tier tier) {
if (aktuelleAnzahlTiere < kapazitaet) {
tierListe[aktuelleAnzahlTiere] = tier;
aktuelleAnzahlTiere++;
System.out.println("Tier hinzugefügt: " + tier.getName());
} else {
System.out.println("Das Gehege ist voll. Tier konnte nicht hinzugefügt werden.");
}
}
// Methode zum Entfernen eines Tieres
public void entfernenTier(Tier tier) {
for (int i = 0; i < aktuelleAnzahlTiere; i++) {
if (tierListe[i].equals(tier)) {
// Tier entfernen und Array neu ordnen
for (int j = i; j < aktuelleAnzahlTiere - 1; j++) {
tierListe[j] = tierListe[j + 1];
}
tierListe[aktuelleAnzahlTiere - 1] = null;
aktuelleAnzahlTiere--;
System.out.println("Tier entfernt: " + tier.getName());
return;
}
}
System.out.println("Tier nicht gefunden: " + tier.getName());
}
// Methode zum Zurückgeben der aktuellen Liste der Tiere
public Tier[] getTiere() {
Tier[] tiereImGehege = new Tier[aktuelleAnzahlTiere];
System.arraycopy(tierListe, 0, tiereImGehege, 0, aktuelleAnzahlTiere);
return tiereImGehege;
}
// Methode zum Zurückgeben der Nummer des Geheges
public int getNummer() {
return nummer;
}
}

Binary file not shown.

View file

@ -0,0 +1,25 @@
public class Tier {
private String art;
private String name;
// Konstruktor zur Setzung von Art und Name
public Tier(String art, String name) {
this.art = art;
this.name = name;
}
// Getter für Art
public String getArt() {
return art;
}
// Getter für Name
public String getName() {
return name;
}
// Setter für Name
public void setName(String name) {
this.name = name;
}
}

View file

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View file

@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,25 @@
public class App {
public static void main(String[] args) throws Exception {
// Create an array of Person objects
Person[] persons = new Person[5];
// Initialize the Person objects
persons[0] = new Person("Hans", 2012);
persons[1] = new Person("Peter", 2011);
persons[2] = new Person("Jochen", 2013);
persons[3] = new Person("Christian", 2050);
persons[4] = new Person("Tobias", 1932);
// Print each person
for (Person person : persons) {
person.printPerson();
}
int sumAge = 0;
for (Person person : persons) {
sumAge += person.getAge();
}
System.out.println("The sum of the age of all people is: " + sumAge);
}
}

Binary file not shown.

View file

@ -0,0 +1,36 @@
import java.time.LocalDate;
class Person {
private String name;
private int age;
Person(String name, int yearOfBirth) {
this.name = name;
LocalDate currentDate = LocalDate.now();
int year = currentDate.getYear();
this.age = year - yearOfBirth;
if (this.age < 0) {
this.age = 0;
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void printPerson() {
System.out.println(name + " " + age);
}
}

Binary file not shown.

View file

@ -1,5 +1,7 @@
import java.util.*;
public class App { public class App {
public static void main(String[] args) throws Exception { public static void main(String[] args) {
Object[][] article = { Object[][] article = {
{ 1, "Banana", 5, "Stk" }, { 1, "Banana", 5, "Stk" },
{ 23, "Flour", 2, "KG" }, { 23, "Flour", 2, "KG" },
@ -13,39 +15,81 @@ public class App {
{ 56, "Bread", 2, "Loaves" }, { 56, "Bread", 2, "Loaves" },
{ 90, "Cheese", 1, "KG" }, { 90, "Cheese", 1, "KG" },
{ 32, "Tomato", 8, "Stk" }, { 32, "Tomato", 8, "Stk" },
{ 11, "Salt", 1, "KG" } { 11, "Salt", 1, "KG" },
{ 13, "Cocaine", 12, "mg" }
}; };
// Create an array to hold Storage objects // Create an array to hold Storage objects
Storage[] myStorage = new Storage[article.length]; Storage[] myStorage = new Storage[1000];
Storage[] myArticles = new Storage[article.length];
// Create and store Storage objects in the array // Initialize 1000 possible storage places
for (int i = 0; i < myStorage.length; i++) {
myStorage[i] = initializStorage(); // Initialize storage with default values
}
// Create and store Storage objects in the myArticles array
for (int i = 0; i < article.length; i++) { for (int i = 0; i < article.length; i++) {
myStorage[i] = createStorage(article[i]); myArticles[i] = createStorage(article[i]);
}
// Fill some of the myStorage array with the contents of myArticles
// For example, place the first few articles into the first few storage slots
for (int i = 0; i < myArticles.length; i++) {
if (i < myStorage.length) {
myStorage[i] = myArticles[i];
}
} }
// Print out the details of each Item // Print out the details of each Item
for (Storage storage : myStorage) { for (Storage storage : myStorage) {
printItems(storage); printItems(storage);
} }
String search = "Banana";
Storage foundItems = lookUp(myStorage, search);
if (foundItems != null) {
System.out.println("-------------------");
System.out.println("You searched for " + search);
printItems(foundItems);
} else {
System.out.println("No " + search + " found");
}
}
private static Storage initializStorage() {
Storage storage = new Storage();
storage.storageId = 0;
storage.article.name = "";
storage.quantaty = 0;
storage.article.unit = "";
return storage;
} }
private static Storage createStorage(Object[] article) { private static Storage createStorage(Object[] article) {
Storage storage = new Storage(); Storage storage = new Storage();
storage.storageId = (int) article[0]; storage.storageId = (int) article[0];
storage.name = (String) article[1]; storage.article.name = (String) article[1];
storage.unit.quantaty = (int) article[2]; storage.quantaty = (int) article[2];
storage.unit.unit = (String) article[3]; storage.article.unit = (String) article[3];
return storage; return storage;
} }
private static void printItems(Storage storage) { private static void printItems(Storage storage) {
if (storage.storageId != 0) { // Only print if there's an actual item
System.out.println("Item on shelf: " + storage.storageId); System.out.println("Item on shelf: " + storage.storageId);
System.out.println("Item name: " + storage.name); System.out.println("Item name: " + storage.article.name);
System.out.println("Item(s) on stock: " + storage.unit.quantaty); System.out.println("Item(s) on stock: " + storage.quantaty);
System.out.println("Measured unit: " + storage.unit.unit); System.out.println("Measured unit: " + storage.article.unit);
System.out.println("-----------------------------------------"); System.out.println("-----------------------------------------");
} }
}
private static Storage lookUp(Storage[] myStorage, String name) {
for (Storage storage : myStorage) {
if (storage.article.name == name) {
return storage;
}
}
return null;
}
} }

View file

@ -0,0 +1,4 @@
class Article {
String unit;
String name;
}

View file

@ -1,5 +1,6 @@
public class Storage {
class Storage {
int storageId; int storageId;
String name; Article article = new Article();
Unit unit = new Unit(); int quantaty;
} }

View file

@ -1,4 +0,0 @@
public class Unit {
int quantaty;
String unit;
}

View file

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View file

@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,23 @@
import java.util.Arrays;
public class App {
public static void main(String[] args) throws Exception {
int[] strength = new int[5];
strength[0] = 5;
strength[1] = 12;
strength[2] = 18;
strength[3] = 2;
strength[4] = 1;
for (int i = 0; i < strength.length; i++) {
System.out.println(strength[i]);
}
System.out.println("-------------------------------------");
Arrays.sort(strength);
for (int i = 0; i < strength.length; i++) {
System.out.println(strength[i]);
}
}
}

View file

@ -12,12 +12,13 @@ import javafx.stage.Stage;
public class App extends Application { public class App extends Application {
@Override @Override
public void start(Stage stage) { public void start(Stage stage) {
var javaVersion = SystemInfo.javaVersion(); var javaVersion = SystemInfo.javaVersion();
var javafxVersion = SystemInfo.javafxVersion(); var javafxVersion = SystemInfo.javafxVersion();
var label = new Label("Hello World"); var label = new Label("Hello, World");
var scene = new Scene(new StackPane(label), 100, 100); var scene = new Scene(new StackPane(label), 640, 480);
stage.setScene(scene); stage.setScene(scene);
stage.show(); stage.show();
} }

View file

@ -0,0 +1,3 @@
module-info.class
com\example\App.class
com\example\SystemInfo.class