i have these 2 programs. at the moment they can add 3 numbers. i need to add another mathematical function to the program.
1:
Code
/**
* Eine Klasse fuer verschiedene Mathematische Funktionen.
*
* @author)
* @version 1.01, 02/2011
*/
public class MyMath {
/**
* Diese Methode berechnet und liefert die Summe von 3 Zahlen vom Typ int.
*
* @param n1
* erste Zahl
* @param n2
* zweite Zahl
* @param n3
* dritte Zahl
* @return die Summe der Zahlen
*/
public static int summiere3Zahlen(int n1, int n2, int n3) {
return n1 + n2 + n3;
}
}
2.
Code
/**
* Testprogramm fuer die Klasse MyMath.
*
* @author
* @version 1.01, 24.02.2011
*/
public class MyMathTest {
/**
* Main-Method zum Starten und Testen der Klasse MyMath. Diese main-Methode
* ist der definierte Einstiegspunkt fuer die Ausfuehrung des Programs und
* erlaubt das Programm zu testen.
*
* @param args
* die Argumente, die man im Allgemeinen fuer die Ausfuehrung
* geben kann
*/
public static void main(String[] args) {
// Statische Methoden der Klasse MyMath testen
System.out.println("Summe von 1,2,3: "
+ MyMath.summiere3Zahlen(1, 2, 3));
System.out.println("Summe von -1,-2,3: "
+ MyMath.summiere3Zahlen(-1, -2, 3));
}
}
my tries:
1.
Code
/**
* Eine Klasse fuer verschiedene Mathematische Funktionen.
*
* @author
* @version 1.01, 02/2011
*/
public class MyMath {
/**
* Diese Methode berechnet und liefert die Summe und die Differenz von 3 Zahlen vom Typ int.
*
* @param n1
* erste Zahl
* @param n2
* zweite Zahl
* @param n3
* dritte Zahl
* @return die Summe und die Differenz der Zahlen
*/
public static int summiere3Zahlen(int n1, int n2, int n3) {
return n1 + n2 + n3;
}
public static int differenziere3Zahlen(int n1, int n2, int n3) {
return n1 - n2 - n3;
}
}
2.
public class MyMathTest {
/**
* Main-Method zum Starten und Testen der Klasse MyMath. Diese main-Methode
* ist der definierte Einstiegspunkt fuer die Ausfuehrung des Programs und
* erlaubt das Programm zu testen.
*
* @param args
* die Argumente, die man im Allgemeinen fuer die Ausfuehrung
* geben kann
*/
public static void main(String[] args) {
// Statische Methoden der Klasse MyMath testen
System.out.println("Summe von 1,2,3: "
+ MyMath.summiere3Zahlen(1, 2, 3));
System.out.println("Summe von -1,-2,3: "
+ MyMath.summiere3Zahlen(-1, -2, 3));
}
public static void main(String[] args) {
System.out.printIn("Differenz von 1,2,3: "
+ MyMath.differenziere3Zahlen(1, 2, 3));
System.out.printIn("Differenz von -1,-2,3: "
+ MyMath.differenziere3Zahlen(-1, -2, 3));
}
}
i tried a lot now but i dont get it to work :/
offhand looks good to me. can you define "dont get it to work"? is it not compiling? or is it not giving you the results you're expecting? if so, what is your teacher's definition of "difference of three numbers"? first minus second minus third?