Disclaimer: Dieser Thread wurde aus dem alten Forum importiert. Daher werden eventuell nicht alle Formatierungen richtig angezeigt. Der ursprüngliche Thread beginnt im zweiten Post dieses Threads.
Hilfe
Hi, könnte jemand hier posten, wie die Methode MultInteger vom Augabenblatt 3 schon im korrekten OOP-Still ausschaut ? danke
re: hier…
public class MultInteger {
int multiplikand;
/**
* MultInteger takes one argument:
* @param multiplikand the number to be multiplied as an int
*
*/
public MultInteger(int multiplikand) {
this.multiplikand = multiplikand;
}
/**
* Method multiply takes one argument
* @param multiplikator the number to be multiplied with as an int
*
*/
int multiply(int multiplikator) {
return multiplikand * multiplikator;
}
/**
* Creates new MultInteger-object and calls its method multiply()
* @param args accepts two argumentsfrom console , first being the number
* to be multiplied, second the multiplier
*/
public static void main(String[] args) {
MultInteger m;
int multiplikand = 0;
int multiplikator = 0;
int result;
//if exactly two arguments present, try to parse them as int
if (args.length == 2) {
try {
multiplikand = Integer.parseInt(args[0]);
multiplikator = Integer.parseInt(args[1]);
} catch (NumberFormatException n) {
System.err.println("main: error while converting number: " + n);
System.err.println("Exiting....");
return;
}
}
//create new MultInteger-instance, and multiply
m = new MultInteger(multiplikand);
result = m.multiply(multiplikator);
//print equation and result to stdout
System.out.println(multiplikand + " * " + multiplikator + " = "
+ result);
return;
}
}