forked from jean/GDP-Uebungen
completed task 5
This commit is contained in:
parent
519bc165dd
commit
3fa88b6a5c
58
GDP_Gesamt/src/Uebungen/Uebung5/Aufgabe5.java
Normal file
58
GDP_Gesamt/src/Uebungen/Uebung5/Aufgabe5.java
Normal file
@ -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();
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user