added tasks from blatt 3

This commit is contained in:
Sven Vogel 2023-04-19 15:06:25 +02:00
parent 1b21d4e8da
commit 09266228ab
23 changed files with 563 additions and 0 deletions

8
.idea/.gitignore 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

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>

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

14
.idea/modules.xml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/GgtUndKgv/GgtUndKgv.iml" filepath="$PROJECT_DIR$/GgtUndKgv/GgtUndKgv.iml" />
<module fileurl="file://$PROJECT_DIR$/GreogorianischerKalender/GreogorianischerKalender.iml" filepath="$PROJECT_DIR$/GreogorianischerKalender/GreogorianischerKalender.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/Java-Programming.iml" filepath="$PROJECT_DIR$/.idea/Java-Programming.iml" />
<module fileurl="file://$PROJECT_DIR$/Konto/Konto.iml" filepath="$PROJECT_DIR$/Konto/Konto.iml" />
<module fileurl="file://$PROJECT_DIR$/Maximum/Maximum.iml" filepath="$PROJECT_DIR$/Maximum/Maximum.iml" />
<module fileurl="file://$PROJECT_DIR$/Verzinsung/Verzinsung.iml" filepath="$PROJECT_DIR$/Verzinsung/Verzinsung.iml" />
<module fileurl="file://$PROJECT_DIR$/Zaubern/Zaubern.iml" filepath="$PROJECT_DIR$/Zaubern/Zaubern.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

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

29
GgtUndKgv/.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

11
GgtUndKgv/GgtUndKgv.iml Normal file
View File

@ -0,0 +1,11 @@
<?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$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="19" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

78
GgtUndKgv/src/Main.java Normal file
View File

@ -0,0 +1,78 @@
import javax.swing.*;
class Rechnen {
static int ggt(int x, int y) {
if (x == 0)
return y;
return ggt(x, y % x);
}
static int kgv(int x, int y) {
return (x * y) / ggt(x, y);
}
}
public class Main {
public static void main(String[] args) {
while (true) {
String z1_S = null;
String z2_S = null;
int z1 = 0;
int z2 = 0;
z1_S = JOptionPane.showInputDialog("Bitte erste Zahl (positiv und ganz)");
if (z1_S == null) break;
z2_S = JOptionPane.showInputDialog("Bitte zweite ganze Zahl (positiv und ganz)");
if (z2_S == null) break;
try {
z1 = Integer.parseInt(z1_S);
z2 = Integer.parseInt(z2_S);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Bitte korrekte Zahlen eingeben");
continue;
}
String action = getAction_Dialog("KGV berechnen", "GGT berechnen");
if (action == null)
break;
try {
switch (action) {
case "KGV berechnen":
JOptionPane.showMessageDialog(null, "KGV von " + z1 + ", " + z2 + "=" + Rechnen.kgv(z1, z2));
break;
case "GGT berechnen":
JOptionPane.showMessageDialog(null, "GGT von " + z1 + ", " + z2 + "=" + Rechnen.ggt(z1, z2));
break;
}
} catch (IllegalArgumentException e) {
JOptionPane.showMessageDialog(null, "Bitte geben Sie positive Zahlen ein!");
continue;
}
}
JOptionPane.showMessageDialog(null, "Danke und auf Wiedersehen!");
System.exit(0);
}
private static String getAction_Dialog(String... actions) {
JRadioButton[] buttons = new JRadioButton[actions.length];
ButtonGroup group = new ButtonGroup();
for (int i = 0; i < actions.length; i++) {
buttons[i] = new JRadioButton(actions[i]);
group.add(buttons[i]);
}
buttons[0].setSelected(true);
Object[] message = buttons;
Object[] options = { "OK", "Abbruch" };
int n = JOptionPane.showOptionDialog(new JFrame(), message, "Aktionswahl",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
if (n == JOptionPane.OK_OPTION) {
for (int i = 0; i < actions.length; i++) {
if (buttons[i].isSelected()) {
return actions[i];
}
}
}
return null;
}
}

29
GreogorianischerKalender/.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -0,0 +1,11 @@
<?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$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="19" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,14 @@
public class Main {
private static boolean isLeapYearGregorianCalendar(int year) {
int decade = year / 10;
return decade % 4 != 0;
}
public static void main(String[] args) {
System.out.println("is leap year: 1904: " + isLeapYearGregorianCalendar(1904));
System.out.println("is leap year: 1003: " + isLeapYearGregorianCalendar(1003));
System.out.println("is leap year: 1422: " + isLeapYearGregorianCalendar(1422));
System.out.println("is leap year: 2022: " + isLeapYearGregorianCalendar(2022));
}
}

29
Konto/.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

11
Konto/Konto.iml Normal file
View File

@ -0,0 +1,11 @@
<?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$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="19" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

35
Konto/src/Konto.java Normal file
View File

@ -0,0 +1,35 @@
public class Konto {
private double guthaben;
void abheben(double betrag) {
var neuesGuthaben = guthaben - betrag;
if (neuesGuthaben < 0) {
System.out.println("Sie konnten nur " + guthaben + " abheben");
this.guthaben = 0;
return;
}
guthaben = neuesGuthaben;
}
void einzahlen(double betrag) {
if (betrag < 0) {
System.err.println("no");
return;
}
this.guthaben += betrag;
}
double getGuthaben() {
return guthaben;
}
public static void main(String[] args) {
var konto = new Konto();
konto.einzahlen(134);
konto.einzahlen(0.345);
System.out.println("guthaben: " + konto.getGuthaben());
konto.abheben(1e6);
}
}

29
Maximum/.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

11
Maximum/Maximum.iml Normal file
View File

@ -0,0 +1,11 @@
<?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$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="19" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

28
Maximum/src/Main.java Normal file
View File

@ -0,0 +1,28 @@
public class Main {
static int max(int a, int b) {
int max = a > b ? a : b;
System.out.println("max: " + max);
return max;
}
static int max(int a, int b, int c) {
if (a < b) {
return b > c ? c : a;
}
return a > c ? a : c;
}
static double max(double a, double b, double c) {
if (a < b) {
return b > c ? c : a;
}
return a > c ? a : c;
}
public static void main(String[] args) {
System.out.println(max(2, 3));
System.out.println(max(5, 49, -3));
System.out.println(max(0.2345, Math.PI, 99.23));
}
}

29
Verzinsung/.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

11
Verzinsung/Verzinsung.iml Normal file
View File

@ -0,0 +1,11 @@
<?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$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="19" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

44
Verzinsung/src/Main.java Normal file
View File

@ -0,0 +1,44 @@
import javax.swing.*;
public class Main {
static double linearZins(double kp, double zs, int n) {
double k = kp;
for (int i = 0; i < n; i++) {
k += kp * zs;
}
return k;
}
static double expZins(double kp, double zs, int n) {
double k = kp;
for (int i = 0; i < n; i++) {
k += k * zs;
}
return k;
}
static double enterUnsigendDouble(String message) {
while (true) {
try {
double value = Double.parseDouble(JOptionPane.showInputDialog(message));
if (value >= 0.0) {
return value;
}
} catch (Exception e) {
System.out.println("not a number");
}
}
}
public static void main(String[] args) {
int n = (int) enterUnsigendDouble("Iterationen: ");
double kp = enterUnsigendDouble("Kapital: ");
double zs = enterUnsigendDouble("Zinssatz: ");
System.out.println(linearZins(kp, zs, n) + " / " + expZins(kp, zs, n));
}
}

29
Zaubern/.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

11
Zaubern/Zaubern.iml Normal file
View File

@ -0,0 +1,11 @@
<?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$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="19" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

81
Zaubern/src/Main.java Normal file
View File

@ -0,0 +1,81 @@
import java.util.Random;
public class Main {
enum Zauberspruch {
ENTWAFFNUNGSZAUBER,
BELEUCHTUNGSZAUBER,
SCHWEBEZAUBER,
AUFRUFEZAUBER,
VERDUNKLUNGSZAUBER,
SCHUTZZAUBER,
VERKLEINERUNGSZAUBER,
}
private static int anzahlZauber;
private static void printSpellCount() {
System.out.println("anzahl Zauber: " + anzahlZauber);
}
//hier kommt Ihr Enum hin
public static void main(String[] args) {
System.out.println("Harry Potter lernen seine Zaubersprüche und deren Bedeutung");
System.out.println("----------------------------------------------------------\n");
zauber(Zauberspruch.BELEUCHTUNGSZAUBER);
zauber(Zauberspruch.SCHUTZZAUBER);
Zauberspruch faulerZauber = Zauberspruch.AUFRUFEZAUBER;
zauber(faulerZauber);
zauber(zufaelligerZauber());
printSpellCount();
}
public static void zauber(Zauberspruch zauber) {
switch (zauber) {
case ENTWAFFNUNGSZAUBER -> {
anzahlZauber ++;
System.out.println("Expelliarmus!");
System.out.println("Sprachliche Herkunft: lat. expellere = vertreiben; arma = Waffen");
System.out.println("Bedeutung: Mit diesem Zauberspruch wird einem Gegner der Zauberstab aus der Hand entrissen, damit er nicht zaubern kann.\n");
}
case BELEUCHTUNGSZAUBER -> {
anzahlZauber ++;
System.out.println("Lumos!");
System.out.println("Sprachliche Herkunft: lat. frz. lumière = Licht");
System.out.println("Bedeutung: Lässt den Zauberstab aufleuchten, um Licht ins Dunkle zu bringen.\n");
}
case SCHWEBEZAUBER -> {
anzahlZauber ++;
System.out.println("Wingardium Leviosa!");
System.out.println("Sprachliche Herkunft: engl. wing = Flügel; lat. arduus hoch/engl. arduous = schwer besteigbar, steil; lat. levis = leicht");
System.out.println("Bedeutung: Lässt Gegenstände oder Personen durch die Luft schweben. Besser nicht draußen bei starkem Wind benutzen!\n");
}
case AUFRUFEZAUBER -> {
anzahlZauber ++;
System.out.println("Accio!");
System.out.println("Sprachliche Herkunft: lateinisch accio ich rufe herbei");
System.out.println("Bedeutung: Dieser Zauber wird benutzt, um Gegenstände zu sich fliegen zu lassen. Fernbedienungen hassen diesen Trick\n");
}
case VERDUNKLUNGSZAUBER -> {
anzahlZauber ++;
System.out.println("Nox!");
System.out.println("Sprachliche Herkunft: lat. nox = Nacht");
System.out.println("Bedeutung: Macht einen durch Lumos leuchtenden Zauberstab wieder aus.\n");
}
case SCHUTZZAUBER -> {
anzahlZauber ++;
System.out.println("Expecto Patronum!");
System.out.println("Sprachliche Herkunft: lat. für ich erwarte den Schutzgeist");
System.out.println("Bedeutung: Beschwört einen Schutzgeist, genannt „Patronus“. Der Patronus schützt vor Gefahren wie Todessern. Kann aber nicht vor Regen, dem Zuspätkommen oder Heißhunger schützen!\n");
}
default -> {
anzahlZauber ++;
System.out.println("Fauler Zauber\n");
}
}
}
public static Zauberspruch zufaelligerZauber() {
Random random = new Random();
return Zauberspruch.values()[random.nextInt( Zauberspruch.values().length) ];
}
}