cleaned up
This commit is contained in:
parent
3edae31699
commit
ff7d904cab
0
Uebung_3/.idea/.gitignore → GDP_Gesamt/.idea/.gitignore
generated
vendored
0
Uebung_3/.idea/.gitignore → GDP_Gesamt/.idea/.gitignore
generated
vendored
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="false" project-jdk-name="15" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="15" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -2,7 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Uebung03.iml" filepath="$PROJECT_DIR$/Uebung03.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/GDP_Gesamt.iml" filepath="$PROJECT_DIR$/GDP_Gesamt.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
GDP_Gesamt/.idea/vcs.xml
generated
Normal file
6
GDP_Gesamt/.idea/vcs.xml
generated
Normal 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>
|
BIN
GDP_Gesamt/aufgaben/GdP-Uebung05-v1.pdf
Normal file
BIN
GDP_Gesamt/aufgaben/GdP-Uebung05-v1.pdf
Normal file
Binary file not shown.
29
GDP_Gesamt/src/Livecoding/Methoden.java
Normal file
29
GDP_Gesamt/src/Livecoding/Methoden.java
Normal file
@ -0,0 +1,29 @@
|
||||
package Livecoding;
|
||||
|
||||
public class Methoden {
|
||||
public static void main(String[]args){
|
||||
sop("Zinseszins: ");
|
||||
//sop(Double.toString(zinseszins(50,2,5)),true);
|
||||
sop(runden(zinseszins(50,2,5),2),true);
|
||||
//sop(Double.toString(zinsesZinsmitZinsanstieg(500, 30)));
|
||||
sop(runden(zinsesZinsmitZinsanstieg(500, 30),2),true);
|
||||
}
|
||||
private static void sop(String input){
|
||||
System.out.print(input);
|
||||
}
|
||||
private static void sop(String input, boolean newline){
|
||||
System.out.println(input);
|
||||
}
|
||||
private static double zinseszins(double startguthaben, double zinsSatz, int anlageJahre){
|
||||
double res;
|
||||
res = startguthaben*Math.pow(1+zinsSatz/100, anlageJahre);
|
||||
return res;
|
||||
}
|
||||
private static int zinsesZinsmitZinsanstieg(int K, int p){
|
||||
return (K*(p+1))/1;
|
||||
}
|
||||
public static String runden(double wert, int dezi){
|
||||
return String.format("%." + dezi + "f",wert);
|
||||
}
|
||||
|
||||
}
|
72
GDP_Gesamt/src/Livecoding/Spicker.java
Normal file
72
GDP_Gesamt/src/Livecoding/Spicker.java
Normal file
@ -0,0 +1,72 @@
|
||||
package Livecoding;
|
||||
|
||||
public class Spicker {
|
||||
public static void main(String[] args){
|
||||
// impliziter cast
|
||||
int intZahl = 1;
|
||||
double dZahl = intZahl;
|
||||
|
||||
// expliziter Cast
|
||||
dZahl = 1.9;
|
||||
intZahl = (int) dZahl;
|
||||
|
||||
boolean istGut = true;
|
||||
int zahl = 0;
|
||||
if(!istGut){
|
||||
System.out.println("A");
|
||||
} else if(istGut && zahl == 0){
|
||||
System.out.print("C");
|
||||
} else {
|
||||
System.out.println("B");
|
||||
}
|
||||
|
||||
//... weiter im Text
|
||||
|
||||
|
||||
// Switch
|
||||
int a = 1;
|
||||
switch(a){
|
||||
case 1:
|
||||
System.out.print("Hallo");
|
||||
break;
|
||||
case 2:
|
||||
System.out.print("Ciao");
|
||||
break;
|
||||
default:
|
||||
System.out.print("Nix passiert");
|
||||
}
|
||||
|
||||
// Schleifen
|
||||
int b = 0, c = 0, d=0;
|
||||
while(b<010) {b++; }
|
||||
do{c++;}while(c<=10);
|
||||
|
||||
for(int i1= 0; i1<=10; i1++) {d++;}
|
||||
|
||||
// Methoden
|
||||
methodenOhneReturn(b);
|
||||
|
||||
int f = methodeMitReturn(2,5);
|
||||
|
||||
// arrays:
|
||||
int[] meinArray = new int[] {3,5,3,2};
|
||||
int[] meinArray2 = new int[4];
|
||||
// meinArray[0] = 3; //...
|
||||
for(int i=0; i<meinArray.length;i++){
|
||||
System.out.println(meinArray[1]);
|
||||
}
|
||||
|
||||
// Variante 2: foreach -Schleife
|
||||
for(int element:meinArray)
|
||||
System.out.println(element);
|
||||
}
|
||||
|
||||
|
||||
// Methoden
|
||||
public static void methodenOhneReturn(int a){
|
||||
System.out.print(a);
|
||||
}
|
||||
public static int methodeMitReturn( int a, int b){
|
||||
return a+b;
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package Uebungen.Uebung1;
|
||||
|
||||
public class HelloWorld {
|
||||
public static void main (String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
package Uebungen.Uebung1;
|
||||
|
||||
public class Sum {
|
||||
public static void main(String[] args){
|
||||
// Ganze Zahl, bis zu der summiert wird
|
||||
@ -12,7 +14,7 @@ public class Sum {
|
||||
sum = 0;
|
||||
counter = 1;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for(int i = 0 ; i <= boundary;i++){
|
||||
@ -31,5 +33,5 @@ public class Sum {
|
||||
System.out.print("\n---------- fin ---------\n\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
package Uebungen.Uebung2;
|
||||
|
||||
public class Variablen{
|
||||
public static void main(String[]args){
|
||||
byte bVar1 = 5;
|
@ -1,3 +1,5 @@
|
||||
package Uebungen.Uebung2;
|
||||
|
||||
public class Verdienstrechner{
|
||||
public static void main(String[] args){
|
||||
float stunden = 7;
|
||||
@ -10,8 +12,8 @@ public class Verdienstrechner{
|
||||
System.out.println("Stundenlohn: " + stundenlohn);
|
||||
|
||||
System.out.println("Stunden insgesamt: " + stunden);
|
||||
|
||||
|
||||
System.out.println("Ich habe " + verdienst + " verdient.");
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
package Uebungen.Uebung3;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Kreis {
|
@ -1,3 +1,4 @@
|
||||
package Uebungen.Uebung3;
|
||||
import java.util.Scanner;
|
||||
public class SatellitenZeit {
|
||||
public static void main(String[] args) {
|
@ -1,3 +1,4 @@
|
||||
package Uebungen.Uebung3;
|
||||
import java.util.Scanner;
|
||||
public class Steuer {
|
||||
public static void main(String[] args){
|
@ -1,3 +1,4 @@
|
||||
package Uebungen.Uebung3;
|
||||
import java.util.Scanner;
|
||||
public class Temperatur {
|
||||
public static void main(String[] args){
|
@ -1,9 +1,11 @@
|
||||
package Uebungen.Uebung4;
|
||||
import java.util.Scanner;
|
||||
public class Maximum {
|
||||
public static void main(String[] args){
|
||||
System.out.print("Bitte geben Sie die Anzahl der Zufallszahlen an: ");
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
int arraySize = Integer.parseInt(scanner.next());
|
||||
|
||||
double[] valueStore = new double[arraySize];
|
||||
for (int i=0; i<arraySize;i++){
|
||||
valueStore[i] = Math.random();
|
@ -1,4 +1,5 @@
|
||||
//import java.util.Scanner;
|
||||
package Uebungen.Uebung4;
|
||||
|
||||
import java.util.Arrays;
|
||||
public class Schnittmenge {
|
||||
public static void main(String[] args){
|
@ -1,3 +1,5 @@
|
||||
package Uebungen.Uebung4;
|
||||
|
||||
import java.util.Scanner;
|
||||
public class Wechselgeld {
|
||||
public static void main(String... args){
|
57
GDP_Gesamt/src/Uebungen/Uebung5/Aufgabe1.java
Normal file
57
GDP_Gesamt/src/Uebungen/Uebung5/Aufgabe1.java
Normal file
@ -0,0 +1,57 @@
|
||||
package Uebungen.Uebung5;
|
||||
import java.util.Scanner;
|
||||
public class Aufgabe1 {
|
||||
|
||||
public static void main(String[] args){
|
||||
// initiate scanner for input
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
// primes till 100 for testing
|
||||
//int[] primes = new int[] { 2, 3,7, 13, 17, 23, 31, 37, 43, 53, 59, 67, 73, 79, 89 };
|
||||
// select number range
|
||||
while(true){
|
||||
userInterface();
|
||||
System.out.print("\n\n Check anoter range? [y/N]: ");
|
||||
if(scanner.nextLine().charAt(0)!='y') break;
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
public static void userInterface(){
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
int rangeMin=0, rangeMax=0;
|
||||
do{
|
||||
System.out.print("\nEnter lowest number from range: ");
|
||||
rangeMin = Integer.parseInt(scanner.nextLine());
|
||||
if(rangeMin<2) System.out.print("[WARNING] Number must be greater than \"1\"!\n");
|
||||
}while(rangeMin<2);
|
||||
|
||||
do{
|
||||
System.out.print("\nEnter greatest number from range: ");
|
||||
rangeMax = Integer.parseInt(scanner.nextLine());
|
||||
if(rangeMax<rangeMin) System.out.print("[WARNING] Number must be at least equal or greater than \"" + rangeMin + "\"!\n");
|
||||
}while(rangeMax<rangeMin);
|
||||
int numAmount = rangeMax - rangeMin;
|
||||
int[] numbers = new int[numAmount+1];
|
||||
System.out.print("Adding numbers => ");
|
||||
for(int i=0; i<=numAmount;i++){
|
||||
numbers[i] = i+rangeMin;
|
||||
//System.out.print("number["+i+"]="+(i+rangeMin)+" ");
|
||||
}
|
||||
System.out.println();
|
||||
System.out.print("Prime numbers => ");
|
||||
for(int number:numbers){
|
||||
if(isPrime(number)) System.out.print(number + ", ");
|
||||
}
|
||||
}
|
||||
public static boolean isPrime(int number){
|
||||
boolean res=true; // output variable
|
||||
// test through all divisors form 2 to number-1
|
||||
for(int i=2;i<number;i++){
|
||||
if(number%i==0){
|
||||
res=false;
|
||||
//System.out.print("("+ number%i + ")" ); // Debug
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
69
GDP_Gesamt/src/Uebungen/Uebung5/Aufgabe2.java
Normal file
69
GDP_Gesamt/src/Uebungen/Uebung5/Aufgabe2.java
Normal file
@ -0,0 +1,69 @@
|
||||
package Uebungen.Uebung5;
|
||||
|
||||
import java.util.Scanner;
|
||||
import java.lang.Character;
|
||||
import java.util.Arrays;
|
||||
public class Aufgabe2 {
|
||||
|
||||
public static void main(String[] args){
|
||||
// initiate scanner for input
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
while(true){
|
||||
userInterface();
|
||||
System.out.print("\n\n Check anoter string? [y/N]: ");
|
||||
if(scanner.nextLine().charAt(0)!='y') break;
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
public static void userInterface() {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.print("Enter desired string: ");
|
||||
char[] stringAsCharArr = scanner.nextLine().toCharArray();
|
||||
char[] usedCharArr = usedChars2(stringAsCharArr);
|
||||
for(char character:usedCharArr) System.out.println(" \""+ character + "\""); // Debug
|
||||
// System.out.println(stringAsCharArr.hashCode()); // Get the hashcode of the array
|
||||
}
|
||||
|
||||
public static char[] usedChars(char[] charArray){
|
||||
char[] workingArray = new char[charArray.length];
|
||||
int position = 0; // current position
|
||||
for(char currChar:charArray) {
|
||||
currChar=Character.toLowerCase(currChar); //normalize
|
||||
boolean exists=false;
|
||||
for(char targetChar:workingArray) if(targetChar==currChar) exists=true;
|
||||
if(!exists){
|
||||
workingArray[position]=currChar;
|
||||
position++;
|
||||
}
|
||||
}
|
||||
char[] targestArray = new char[position];
|
||||
for(int i=0;i<position;i++) targestArray[i] = workingArray[i];
|
||||
Arrays.sort(targestArray);
|
||||
return targestArray;
|
||||
}
|
||||
// Improved function: less code, less demanding
|
||||
public static char[] usedChars2(char[] workingArray){
|
||||
// workingArray gets an new hashcode after modifying, so its okay using it
|
||||
// now we remove all characters that occur multiple times
|
||||
// we also count how many chars we got
|
||||
int counter=0;
|
||||
for(int i=0; i<workingArray.length;i++){
|
||||
if((int)workingArray[i]!=0) {
|
||||
counter++; // found a new one -> increment counter
|
||||
// now remove all similar chars from that point till the end of the array
|
||||
for (int j = i + 1; j < workingArray.length; j++) {
|
||||
if (workingArray[i] == workingArray[j]) workingArray[j] = (char) 0; // set the char to "Null character"
|
||||
}
|
||||
}
|
||||
}
|
||||
char[] targetArray = new char[counter]; // create new
|
||||
int targetPosition = 0; // initiate counter for the Target Array
|
||||
for(char currChar:workingArray){ // seek through all chars
|
||||
if((int)currChar!=0){ // if its not a null character it is a new char
|
||||
targetArray[targetPosition] = currChar; // add the current char
|
||||
targetPosition++; // we added a new char, so we need to increment for the next one
|
||||
}
|
||||
}
|
||||
return targetArray;
|
||||
}
|
||||
}
|
8
Uebung_1/.vscode/settings.json
vendored
8
Uebung_1/.vscode/settings.json
vendored
@ -1,8 +0,0 @@
|
||||
{
|
||||
"files.exclude": {
|
||||
"**/.classpath": true,
|
||||
"**/.project": true,
|
||||
"**/.settings": true,
|
||||
"**/.factorypath": true
|
||||
}
|
||||
}
|
Binary file not shown.
@ -1,26 +0,0 @@
|
||||
public class SumTemplate {
|
||||
public static void main(String[] args){
|
||||
// Ganze Zahl, bis zu der summiert wird
|
||||
int boundary;
|
||||
// Summe der bisher addierten ganzen Zahlen
|
||||
int sum;
|
||||
// Ganze Zahl
|
||||
int counter;
|
||||
|
||||
// Festlegen der Startwerte
|
||||
boundary = 4;
|
||||
sum = 0;
|
||||
counter = 1;
|
||||
|
||||
// Berechnen der Summe sum über alle Zahlen von 1 bis boundary
|
||||
while(counter <= boundary){
|
||||
sum = sum + counter;
|
||||
counter = counter + 1;
|
||||
}
|
||||
// Ausgaben der Summe, gemeinsam mit erläuterndem Text
|
||||
System.out.print("Die Summe der Zahlen von 1 bis ");
|
||||
System.out.print(boundary);
|
||||
System.out.print(" ist ");
|
||||
System.out.print(sum);
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,21 +0,0 @@
|
||||
public class Variablen{
|
||||
public static void main(String[]args){
|
||||
byte bVar1 = 5;
|
||||
short sVar1 = 400;
|
||||
int iVar1 = -35676;
|
||||
long lVar1 = 100000000L;
|
||||
float fVar1 = 0.123f;
|
||||
double dVar1 = 0.123;
|
||||
boolean istPrim1 = false;
|
||||
char cVar1 = 'x';
|
||||
System.out.println();
|
||||
System.out.println(bVar1);
|
||||
System.out.println(sVar1);
|
||||
System.out.println(iVar1);
|
||||
System.out.println(lVar1);
|
||||
System.out.println(fVar1);
|
||||
System.out.println(dVar1);
|
||||
System.out.println(cVar1);
|
||||
System.out.println(istPrim1);
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
@ -1,35 +0,0 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Verdienstrechner {
|
||||
public static void main(String[] args) {
|
||||
float stunden = 9f;
|
||||
float stundenlohn = 12.0f;
|
||||
float ueStundenlohn = 17.5f;
|
||||
float ueStunden = 0;
|
||||
float regArbeitszeit = 8;
|
||||
Scanner scan = new Scanner(System.in);
|
||||
System.out.print("Standardwerte verwenden? [J/n]: ");
|
||||
if (scan.nextLine().equalsIgnoreCase("n")) {
|
||||
System.out.print("\nDeine regulaere Arbeitszeit: ");
|
||||
regArbeitszeit = scan.nextFloat();
|
||||
System.out.print("\nWie viel verdienst du in der Stunde?: ");
|
||||
stundenlohn = scan.nextFloat();
|
||||
System.out.print("\n Wie viel Stunden hast du gearbeitet?: ");
|
||||
stunden = scan.nextFloat();
|
||||
System.out.print("\n Wie viel verdienst du bei Überstunden?:");
|
||||
ueStundenlohn = scan.nextFloat();
|
||||
}
|
||||
System.out.println("------ BERECHNE-------\n");
|
||||
System.out.println("Stundenlohn: " + stundenlohn);
|
||||
System.out.println("Stunden insgesamt: " + stunden);
|
||||
if (stunden > regArbeitszeit) {
|
||||
ueStunden = stunden - regArbeitszeit;
|
||||
System.out.println("Ueberstunden: " + ueStunden);
|
||||
stunden = 8;
|
||||
}
|
||||
float verdienst = stunden * stundenlohn + ueStundenlohn * ueStunden;
|
||||
|
||||
System.out.println("Ich habe " + verdienst + " verdient.");
|
||||
scan.close();
|
||||
}
|
||||
}
|
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.
@ -1,6 +0,0 @@
|
||||
public class CountDown {
|
||||
public static void main(String[] args){
|
||||
System.out.println();
|
||||
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
public class Liveuebung {
|
||||
public static void crazyLoop(String[] args){
|
||||
int zaehler= 0;
|
||||
while(zaehler < 3){
|
||||
System.out.println(zaehler++);
|
||||
|
||||
}
|
||||
}
|
||||
public static int calc(int[] numbers){
|
||||
int sum = 0;
|
||||
for(int i=numbers.length-1;i>=0;i--){
|
||||
sum += numbers[i];
|
||||
}
|
||||
return sum*sum;
|
||||
}
|
||||
|
||||
public static int calc2(int... numbers){
|
||||
int sum=0;
|
||||
for(int number:numbers){
|
||||
sum += number;
|
||||
}
|
||||
return sum*sum;
|
||||
}
|
||||
public static void main(String[] args){
|
||||
int[] input = {1,2,3};
|
||||
int ret = calc(input);
|
||||
System.out.println("Ergebnis: " + ret);
|
||||
System.out.println("Anzahl " + input.length);
|
||||
System.out.println("-----------------");
|
||||
System.out.println("Rechne" + calc2(1,2,3));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
import java.util.Scanner;
|
||||
public class ScannerBeispiel {
|
||||
public static void main(String[] args){
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
byte byteWert = Byte.parseByte(scanner.nextLine());
|
||||
short shortWert = Short.parseShort(scanner.nextLine());
|
||||
int intWert = Integer.parseInt(scanner.nextLine());
|
||||
long longWert = Long.parseLong(scanner.nextLine());
|
||||
float floatWert = Float.parseFloat(scanner.nextLine());
|
||||
double doubleWert = Double.parseDouble(scanner.nextLine());
|
||||
boolean booleanWert = Boolean.parseBoolean(scanner.nextLine());
|
||||
scanner.close();
|
||||
}
|
||||
}
|
3
Uebung_4/.idea/.gitignore
generated
vendored
3
Uebung_4/.idea/.gitignore
generated
vendored
@ -1,3 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
6
Uebung_4/.idea/misc.xml
generated
6
Uebung_4/.idea/misc.xml
generated
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="false" project-jdk-name="15" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
Uebung_4/.idea/modules.xml
generated
8
Uebung_4/.idea/modules.xml
generated
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/U4.iml" filepath="$PROJECT_DIR$/U4.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -1,11 +0,0 @@
|
||||
<?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="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user