Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 48c93b9b79 | |||
| fbb22de72a | |||
| 91c0e69df6 | |||
| 98abf5c8e9 | |||
| 3fa88b6a5c | |||
| 519bc165dd | |||
| e1ea1d2e75 | |||
| 44d88bb3e7 | |||
| 65f3c0e022 |
Generated
+3
@@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
Generated
+6
@@ -0,0 +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="openjdk-15" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/GDP-Uebungen.iml" filepath="$PROJECT_DIR$/GDP-Uebungen.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -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$/GDP_Gesamt/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
@@ -1,18 +1,14 @@
|
|||||||
package Uebungen.Uebung5;
|
package Uebungen.Uebung5;
|
||||||
|
|
||||||
import java.awt.desktop.SystemSleepEvent;
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.lang.Character;
|
import java.lang.Character;
|
||||||
import java.util.Arrays;
|
|
||||||
public class Aufgabe2 {
|
public class Aufgabe2 {
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
// initiate scanner for input
|
// initiate scanner for input
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
while(true){
|
while(true){
|
||||||
userInterface();
|
userInterface();
|
||||||
System.out.print("\n\n Check anoter string? [y/N]: ");
|
System.out.print("\n\n Check anoter string? [y/N]: ");
|
||||||
if(scanner.nextLine().charAt(0)!='y') break;
|
if(scanner.nextLine()!="y") break;
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,32 +19,44 @@ public class Aufgabe2 {
|
|||||||
stringAsCharArr = normalize(stringAsCharArr);
|
stringAsCharArr = normalize(stringAsCharArr);
|
||||||
char[] usedCharArr = usedChars(stringAsCharArr);
|
char[] usedCharArr = usedChars(stringAsCharArr);
|
||||||
int[] charAmountArr = countChars(usedCharArr ,stringAsCharArr);
|
int[] charAmountArr = countChars(usedCharArr ,stringAsCharArr);
|
||||||
|
sort(charAmountArr,usedCharArr);
|
||||||
histogramm(20,usedCharArr, charAmountArr);
|
histogramm(20,usedCharArr, charAmountArr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static char[] normalize(char[] workerArray){
|
public static char[] normalize(char[] workerArray){
|
||||||
for(int i=0; i<workerArray.length;i++)
|
for(int i=0; i<workerArray.length;i++)
|
||||||
workerArray[i]=Character.toLowerCase(workerArray[i]);
|
workerArray[i]=Character.toLowerCase(workerArray[i]);
|
||||||
return workerArray;
|
return workerArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void histogramm(int width, char[] availableChars, int[] charAmount){
|
public static void histogramm(int width, char[] availableChars, int[] charAmount){
|
||||||
int max = maximum(charAmount);
|
int max = maximum(charAmount);
|
||||||
for(int i=0;i<availableChars.length;i++) {
|
for(int i=0;i<availableChars.length;i++) {
|
||||||
System.out.print("\""+availableChars[i]+"\": ");
|
System.out.print("\""+availableChars[i]+"\": ");
|
||||||
if(max>width)
|
if(max>width) // scale if max width is exceeded
|
||||||
for(int j=0;j<scale(charAmount[i],max,width);j++) System.out.print("#");
|
for(int j=0;j<scale(charAmount[i],max,width);j++) System.out.print("#");
|
||||||
else
|
else
|
||||||
for(int j=0;j<charAmount[i];j++) System.out.print("#");
|
for(int j=0;j<charAmount[i];j++) System.out.print("#");
|
||||||
System.out.println("x"+charAmount[i]);
|
System.out.println("x"+charAmount[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public static int scale(int value, int oldMax, int newMax){
|
public static int scale(int value, int oldMax, int newMax){
|
||||||
double calc = (double) value/oldMax*newMax;
|
double calc = (double) value/oldMax*newMax;
|
||||||
return (int) calc;
|
return (int) calc;
|
||||||
}
|
}
|
||||||
|
// Bubble Sort
|
||||||
|
public static void sort(int[] amounts, char[] chars){
|
||||||
|
for(int i=amounts.length-1;i>0; i--)
|
||||||
|
for(int j=0;j<i;j++)
|
||||||
|
if(amounts[j]<amounts[j+1])
|
||||||
|
swapItems(amounts,chars,j,j+1);
|
||||||
|
}
|
||||||
|
public static void swapItems(int[] amounts, char[] chars, int index1, int index2){
|
||||||
|
char memC = chars[index1];
|
||||||
|
int memI = amounts[index1];
|
||||||
|
chars[index1] = chars[index2];
|
||||||
|
amounts[index1] = amounts[index2];
|
||||||
|
chars[index2] = memC;
|
||||||
|
amounts[index2] = memI;
|
||||||
|
}
|
||||||
public static int maximum(int[] inputArray){
|
public static int maximum(int[] inputArray){
|
||||||
int largestNumber = inputArray[0];
|
int largestNumber = inputArray[0];
|
||||||
for(int i=1;i<inputArray.length;i++)
|
for(int i=1;i<inputArray.length;i++)
|
||||||
@@ -86,7 +94,6 @@ public class Aufgabe2 {
|
|||||||
targetArray[targetPosition] = currChar; // add the current char
|
targetArray[targetPosition] = currChar; // add the current char
|
||||||
targetPosition++; // we added a new char, so we need to increment for the next one
|
targetPosition++; // we added a new char, so we need to increment for the next one
|
||||||
}
|
}
|
||||||
|
|
||||||
return targetArray;
|
return targetArray;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package Uebungen.Uebung5;
|
||||||
|
|
||||||
|
public class Aufgabe3 {
|
||||||
|
public static void main(String[] args){
|
||||||
|
int[] myArray = {1,2,3};
|
||||||
|
outputArray(myArray);
|
||||||
|
myArray = anfuegen(myArray, 4);
|
||||||
|
outputArray(myArray);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
public static int[] anfuegen(int[] inputArray, int addedInt){
|
||||||
|
int[] outputArray = new int[inputArray.length+1];
|
||||||
|
for(int i=0;i<inputArray.length;i++)
|
||||||
|
outputArray[i] = inputArray[i];
|
||||||
|
outputArray[inputArray.length]=addedInt;
|
||||||
|
return outputArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void outputArray(int[] inputArray){
|
||||||
|
System.out.print("[");
|
||||||
|
for(int i=0;i<inputArray.length;i++)
|
||||||
|
if(inputArray.length-1==i)
|
||||||
|
System.out.print(inputArray[i]);
|
||||||
|
else
|
||||||
|
System.out.print(inputArray[i]+" ,");
|
||||||
|
System.out.println("]");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
package Uebungen.Uebung5;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Arrays;
|
||||||
|
public class Aufgabe4 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int timeout = 150; // milliseconds
|
||||||
|
int[] testValues = {2,34,134,4,53,11,87,142,742,115,00,411,61,33,23456,2346,12,4562,4562,56245,62456,2456,24562};
|
||||||
|
Arrays.sort(testValues);
|
||||||
|
for (int value:testValues){
|
||||||
|
int result = binarySearch(testValues,value, timeout);
|
||||||
|
System.out.println("Found: "+testValues[result]+" at index " + result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static int binarySearch(int[] inputArray, int value,int timeout){
|
||||||
|
System.out.println("Searching for " + value);
|
||||||
|
printArray(inputArray);
|
||||||
|
int res=-1;
|
||||||
|
int rangeMax=inputArray.length-1, rangeMin=0,center=0;
|
||||||
|
int diff;
|
||||||
|
long lastdate=0;
|
||||||
|
while(res < 0){
|
||||||
|
Date date = new Date();
|
||||||
|
long deltaT = date.getTime()-lastdate;
|
||||||
|
if(deltaT>timeout) {
|
||||||
|
lastdate = date.getTime();
|
||||||
|
diff = (rangeMax - rangeMin) / 2; // intermediate value
|
||||||
|
if (diff==0) {
|
||||||
|
if (value == inputArray[center]) {
|
||||||
|
res = center;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res = center+1;
|
||||||
|
center +=1; // not needed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
center = rangeMin + diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
infoGraphic(value, center, rangeMin, rangeMax, rangeMax, inputArray);
|
||||||
|
if (value >= inputArray[center]) {
|
||||||
|
rangeMin = center;
|
||||||
|
} else {
|
||||||
|
rangeMax = center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
public static void printArray(int[] inputArray){
|
||||||
|
int maxlength=maxLength(inputArray);
|
||||||
|
System.out.print("I|");
|
||||||
|
for(int i=0; i<inputArray.length;i++){
|
||||||
|
System.out.print(fixedLengthString(Integer.toString(i), maxlength));
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
System.out.print("V|");
|
||||||
|
for(int i=0; i<inputArray.length;i++){
|
||||||
|
System.out.print(fixedLengthString(Integer.toString(inputArray[i]), maxlength));
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
public static void infoGraphic(int value, int center, int min, int max, int modulo, int[] array){
|
||||||
|
int maxlength=maxLength(array);
|
||||||
|
System.out.print("P|");
|
||||||
|
for(int i=0; i<array.length;i++){
|
||||||
|
if(i==max&i==center)
|
||||||
|
System.out.print(fixedLengthString("C,<", maxlength, false));
|
||||||
|
else if(i==min&i==center)
|
||||||
|
System.out.print(fixedLengthString(">,C", maxlength, false));
|
||||||
|
else if(i==center)
|
||||||
|
System.out.print(fixedLengthString("C", maxlength, false));
|
||||||
|
else if(i==max)
|
||||||
|
System.out.print(fixedLengthString("<", maxlength, false));
|
||||||
|
else if(i==min)
|
||||||
|
System.out.print(fixedLengthString(">", maxlength, false));
|
||||||
|
else
|
||||||
|
System.out.print(fixedLengthString(" ", maxlength, false));
|
||||||
|
}
|
||||||
|
System.out.println("center: "+center+" MOD: "+modulo+" min: "+min+" max:"+max);
|
||||||
|
}
|
||||||
|
public static String fixedLengthString(String string, int length){
|
||||||
|
return fixedLengthString( string, length, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String fixedLengthString(String string, int length,boolean brackets) {
|
||||||
|
if(brackets) return String.format("%1$"+length+ "s|", string);
|
||||||
|
else return String.format("%1$"+(length+1)+ "s", string);
|
||||||
|
|
||||||
|
}
|
||||||
|
public static int maxLength(int[] inputArray){
|
||||||
|
int res=0;
|
||||||
|
for(int number:inputArray){
|
||||||
|
int length = (int) (Math.log10(number) + 1);
|
||||||
|
if(length>res)
|
||||||
|
res=length;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package Uebungen.Uebung5;
|
||||||
|
|
||||||
|
public class Aufgabe5 {
|
||||||
|
public static double verdienst(double stunden, double lohn, double faktor) {
|
||||||
|
// 5.1 return: an inline if condition is executed
|
||||||
|
// if stunden are equal or lower than 8, stunden*lohn gets returnt
|
||||||
|
// else stunden above 8 are added and mutliplied by factor and the result gets multiplied by lohn
|
||||||
|
return stunden <= 8.0
|
||||||
|
? stunden * lohn
|
||||||
|
: (8.0 + faktor * (stunden - 8.0)) * lohn;
|
||||||
|
}
|
||||||
|
public static void main(String[] args) {
|
||||||
|
final double lohn = 15.0;
|
||||||
|
final double faktor = 1.15;
|
||||||
|
double[] stundenArray = {8.0,8.0,9.0,9.0,6.0,8.0 };
|
||||||
|
System.out.println("Der aktuelle verdienst beträgt: " + gesamtVerdienst(stundenArray,lohn,faktor));
|
||||||
|
stundenArray = anfuegen(stundenArray,4.0);
|
||||||
|
System.out.println("Der aktuelle verdienst beträgt: " + gesamtVerdienst(stundenArray,lohn,faktor));
|
||||||
|
stundenArray = entfernen(stundenArray,6);
|
||||||
|
System.out.println("Der aktuelle verdienst beträgt: " + gesamtVerdienst(stundenArray,lohn,faktor));
|
||||||
|
stundenArray = entfernen(stundenArray,0);
|
||||||
|
System.out.println("Der aktuelle verdienst beträgt: " + gesamtVerdienst(stundenArray,lohn,faktor));
|
||||||
|
}
|
||||||
|
public static double[] anfuegen(double[] inputArray, double addedDouble){
|
||||||
|
double[] outputArray = new double[inputArray.length+1];
|
||||||
|
for(int i=0;i<inputArray.length;i++)
|
||||||
|
outputArray[i] = inputArray[i];
|
||||||
|
outputArray[inputArray.length]=addedDouble;
|
||||||
|
System.out.println("Das Element mit dem Index " + inputArray.length + " und dem Wert " + addedDouble + " wurde hinzugefügt!");
|
||||||
|
printArray(outputArray);
|
||||||
|
return outputArray;
|
||||||
|
}
|
||||||
|
public static double[] entfernen(double[] inputArray, int delIndex){
|
||||||
|
double[] outputArray = new double[inputArray.length-1];
|
||||||
|
for(int i=0;i<outputArray.length;i++)
|
||||||
|
if(i>=delIndex)
|
||||||
|
outputArray[i] = inputArray[i+1];
|
||||||
|
else
|
||||||
|
outputArray[i] = inputArray[i];
|
||||||
|
System.out.println("Das Element mit dem Index " + delIndex + " und dem Wert " + inputArray[delIndex] + " wurde entfernt!");
|
||||||
|
printArray(outputArray);
|
||||||
|
return outputArray;
|
||||||
|
}
|
||||||
|
public static double gesamtVerdienst(double[] inputArray, double lohn, double faktor){
|
||||||
|
double res = 0;
|
||||||
|
for(double stunden:inputArray){
|
||||||
|
res += verdienst(stunden, lohn, faktor);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
public static void printArray(double[] inputArray){
|
||||||
|
for(int i=0; i<inputArray.length;i++){
|
||||||
|
System.out.print(Double.toString(inputArray[i]) + "| ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user