Hallo!
Ich bin leider totaler Java Neuling und komm noch sehr schwer damit zurecht.Ich habe jetzt eine Aufgabe Programmiert bei der bei Eclipse auch alles passt und das richtige Ergebnis rauskommt. Wenn ich die Aufgabe jedoch über PABS-Abgabesystem abgeb kommt folgende Fehlermeldung:
1Test(s) saved.
Compilation successful.
Testsuite: ex11.tests.TestInterestCalculation
Tests run:3, Failures: 0, Errors: 1, Time elapsed: 0.038 sec
Testcase: testCalculateInterest took 0.008 sec
Testcase: testCompareInterest took 0.001 sec
Testcase: testPrintInterestComparison took 0.003 sec
Caused an ERROR
3
java.lang.ArrayIndexOutOfBoundsException: 3
at ex11.InterestCalculation.printInterestComparison(InterestCalculation.java:76)
at ex11.tests.TestInterestCalculation.testPrintInterestComparison(TestInterestCalculation.java:173)
Test ex11.tests.TestInterestCalculation failed
Kann mir vllt jemand weiterhelfen?
Wär echt nett
Ich bin leider totaler Java Neuling und komm noch sehr schwer damit zurecht.Ich habe jetzt eine Aufgabe Programmiert bei der bei Eclipse auch alles passt und das richtige Ergebnis rauskommt. Wenn ich die Aufgabe jedoch über PABS-Abgabesystem abgeb kommt folgende Fehlermeldung:
1Test(s) saved.
Compilation successful.
Testsuite: ex11.tests.TestInterestCalculation
Tests run:3, Failures: 0, Errors: 1, Time elapsed: 0.038 sec
Testcase: testCalculateInterest took 0.008 sec
Testcase: testCompareInterest took 0.001 sec
Testcase: testPrintInterestComparison took 0.003 sec
Caused an ERROR
3
java.lang.ArrayIndexOutOfBoundsException: 3
at ex11.InterestCalculation.printInterestComparison(InterestCalculation.java:76)
at ex11.tests.TestInterestCalculation.testPrintInterestComparison(TestInterestCalculation.java:173)
Test ex11.tests.TestInterestCalculation failed
Java:
Meine Lösung sieht so aus:
/*Aufgabe 11a)
*/
public class InterestCalculation {
public static double [] calculateInterest (double amount,int years, double interest, boolean isCompound) {
double[] Betrag = new double[years + 2];
double Zinssatz = 1 + interest;
if (amount==0 || interest <=0 || interest>1||years<1)
return null;
if(isCompound == true){
Betrag[0] = -0.5;
Betrag[1] = amount;
for(int i = 2; i < (Betrag.length); i++) {
Betrag[i] = round(Betrag[i - 1] * Zinssatz);
}
}
else {
Betrag[0] = -1;
Betrag[1] = amount;
for( int i = 2; i < (Betrag.length); i++) {
Betrag[i] = round(Betrag[i-1] + (Betrag[1] * interest));
}
}
return Betrag ;
}
private static double round(double guthaben){
return Math.round(guthaben*Math.pow(10, 2))/Math.pow(10, 2);
}
/*Aufgabe 11 b)
*/
public static double[][] compareInterests(double interest_1, int years_1,
boolean isCompound_1,double interest_2, int years_2, boolean isCompound_2 ,double amount){
double[][]Vergleich = new double [2][2];
Vergleich[0][0]=Vergleich[0][1]=amount;
if (amount == 0)
return null;
if (interest_1 <= 0.0||interest_1 > 1.0||interest_2 <= 0.0||interest_2 > 1.0)
return null;
if (years_1 < 1||years_2 < 1)
return null;
if (interest_1 > 0 & interest_1 <= 1 & interest_2 > 0 & interest_2 <= 1){
Vergleich[0] = calculateInterest(amount,years_1,interest_1,isCompound_1);
Vergleich[1] = calculateInterest(amount,years_2,interest_2,isCompound_2);
}
return Vergleich;
}
/*Aufgabe 11 c)
*/
public static String printInterestComparison(double [][]values){
String Ergebnis=("Anfangsbetrag: "+ values[0][1]+"\n"+
"Zinsentwicklung einfache Verzinsung: "+values[0][2]+","+values[0][3]+","+values[0][4]
+","+values[0][5]+","+"\n\n"+
"Anfangsbetrag: " + values[1][1]+"\n"+"Zinsentwicklung Zinseszins: "+values[1][2]+","
+values[1][3]+","+values[1][4]+","+values[1][5]+",");
return Ergebnis;
}
public static void main(String[] args) {
double[][]ct=compareInterests(0.1,4,false,0.1,4,true,500);
System.out.println(printInterestComparison(ct));
}
}
Wär echt nett
Zuletzt bearbeitet von einem Moderator: