Hallo Leute!
Aufgabe war, ein kleines Progamm zu schreiben, dass bei beliebig vielen in dem Array coeffs[] abgelegten Zahlen auf der Kommandozeile die Funktionsschreibweise eines Polynoms (also f(x) = coeffs[0]*x^(n-1) + coeffs[1]*x^(n-2) +...) ausgibt.
Dazu sollte man einen Konstruktor und eine Instanzmethode ( printPolynom() ) benutzen (eben genau zu dem Zweck dies zu üben).
Beides habe ich getan, wodurch sich dieses Grundgerüst ergibt:
Jetzt sollte man in der main-Methode mehrere Objekte der Klasse Polynom instanzieren und sie dann über die printPolynom()-Methode ausgeben lassen, was ich dann versucht habe, erstmal nur mit einem Objekt:
Darauf bekomme ich dann folgende Fehlermeldung:
Polynom.java:37: cannot find symbol
symbol : constructor Polynom(int,int,int)
location: class Polynom
Polynom f = new Polynom(4, 3, 2);
^
Polynom.java:38: printPolynom() in Polynom cannot be applied to (Polynom)
printPolynom(f);
^
2 errors
Ich habe wirklich ewig nach dem Fehler gesucht und bin kein Stück weiter gekommen.
Kann mir bitte einer helfen? Ich komm alleine einfach nicht weiter...
Aufgabe war, ein kleines Progamm zu schreiben, dass bei beliebig vielen in dem Array coeffs[] abgelegten Zahlen auf der Kommandozeile die Funktionsschreibweise eines Polynoms (also f(x) = coeffs[0]*x^(n-1) + coeffs[1]*x^(n-2) +...) ausgibt.
Dazu sollte man einen Konstruktor und eine Instanzmethode ( printPolynom() ) benutzen (eben genau zu dem Zweck dies zu üben).
Beides habe ich getan, wodurch sich dieses Grundgerüst ergibt:
Java:
public class Polynom {
int coeffs[];
public Polynom(int coeffs[]) {
this.coeffs = coeffs.clone();
}
public void printPolynom() {
System.out.print("f(x) =");
for (int i = 0; i < coeffs.length; i++) {
if (i < (coeffs.length - 2)) {
System.out.print(" " + coeffs[i] + "x^" + (coeffs.length - 1 - i));
} if (i == coeffs.length - 2) {
System.out.print(" " + coeffs[i] + "x");
} if (i == coeffs.length - 1) {
System.out.print(" " + coeffs[i] + (coeffs.length - 1 - i));
} if (i != (coeffs.length -1)) {
System.out.print(" +");
}
}
System.out.println("");
}
public static void main(String[] args) {
}
}
Jetzt sollte man in der main-Methode mehrere Objekte der Klasse Polynom instanzieren und sie dann über die printPolynom()-Methode ausgeben lassen, was ich dann versucht habe, erstmal nur mit einem Objekt:
Java:
public class Polynom {
int coeffs[];
public Polynom(int coeffs[]) {
this.coeffs = coeffs.clone();
}
public void printPolynom() {
System.out.print("f(x) =");
for (int i = 0; i < coeffs.length; i++) {
if (i < (coeffs.length - 2)) {
System.out.print(" " + coeffs[i] + "x^" + (coeffs.length - 1 - i));
} if (i == coeffs.length - 2) {
System.out.print(" " + coeffs[i] + "x");
} if (i == coeffs.length - 1) {
System.out.print(" " + coeffs[i] + (coeffs.length - 1 - i));
} if (i != (coeffs.length -1)) {
System.out.print(" +");
}
}
System.out.println("");
}
public static void main(String[] args) {
Polynom f = new Polynom(4, 3, 2);
printPolynom(f);
}
}
Darauf bekomme ich dann folgende Fehlermeldung:
Polynom.java:37: cannot find symbol
symbol : constructor Polynom(int,int,int)
location: class Polynom
Polynom f = new Polynom(4, 3, 2);
^
Polynom.java:38: printPolynom() in Polynom cannot be applied to (Polynom)
printPolynom(f);
^
2 errors
Ich habe wirklich ewig nach dem Fehler gesucht und bin kein Stück weiter gekommen.
Kann mir bitte einer helfen? Ich komm alleine einfach nicht weiter...