Rechnungsblatt

Chillchen

Mitglied
Guten Abend meine lieben Mitprogrammierer,

Ich hoffe ich bin hier richtig und jemand kann mir helfen. Ich habe das Aufgabe ein Rechungsblatt zu erstellen, mit einfachen Rechnungen von die 1.Klasse. Eine Zahl soll dabei immer verdeckt sein bzw. durch einen _ ersetzt werden, damit man diese Zahl dort einsetzten kann. Das einzige was mich jetzt noch stört ist, dass die Zahlen in meinem Powershell mit Komma ausgeschrieben sind, und ich weiss nicht warum. finde den letzten kleinen Fehler nicht mehr. wär Ihnen sehr verbunden, für das Hilfe.

[Java] import java.util.Random;
import java.util.Arrays;

public final class Rechnungsblatt {

static final Random RANDOM = new Random();

public static void main(String[] args) {
if (args.length!=1) {
System.out.println("Bitte gewuenschte Anzahl Rechnungen eingeben");
}
else{
int e = Integer.parseInt(args[0]);
zufallszahlen(e);
}
}

//Zufallszahlen und Rechnung erstellen:

static void zufallszahlen(int x) {
String operand1 = "+";
String operand2 = "-";
String operand3 = "*";
String operand4 = "/";
String operand5 = "=";

StringBuilder res = new StringBuilder();
for (int i=0; i<x; i++) {
int a = RANDOM.nextInt(7);
// int b = RANDOM.nextInt(5);
int add1 = RANDOM.nextInt(12)+1;
int add2 = RANDOM.nextInt(12)+1;
int sub = RANDOM.nextInt(12)+1;
int differenz = RANDOM.nextInt(12)+1;
int mul1 = RANDOM.nextInt(12)+1;
int mul2 = RANDOM.nextInt(12)+1;
int divisor = RANDOM.nextInt(12)+1;
int quotient = RANDOM.nextInt(12)+1;
int summe = add1+add2;
int min = sub+differenz;
int product = mul1*mul2;
int dividend = divisor*quotient;

String add1string = Integer.toString(add1);
String add2string = Integer.toString(add2);
String substring = Integer.toString(sub);
String differenzstring = Integer.toString(differenz);
String mul1string = Integer.toString(mul1);
String mul2string = Integer.toString(mul2);
String divisorstring = Integer.toString(divisor);
String quotientstring = Integer.toString(quotient);
String sumstring = Integer.toString(summe);
String minstring = Integer.toString(min);
String productstring = Integer.toString(product);
String dividendstring = Integer.toString(dividend);

// 8 Rechnungstypen festlegen: +=, =+, -=, =-, ...

String[][] typ = new String[8][5];
typ[0][0] = typ[1][4] = sumstring;
typ[0][1] = typ[2][1] = typ[4][1] = typ[6][1] = operand5;
typ[1][3] = typ[3][3] = typ[5][3] = typ[7][3] = operand5;
typ[0][2] = typ[1][0] = add1string;
typ[0][3] = typ[1][1] = operand1;
typ[0][4] = typ[1][2] = add2string;
typ[2][0] = typ[3][4] = differenzstring;
typ[2][2] = typ[3][0] = minstring;
typ[2][3] = typ[3][1] = operand2;
typ[2][4] = typ[3][2] = substring;
typ[4][0] = typ[5][4] = productstring;
typ[4][2] = typ[5][0] = mul1string;
typ[4][3] = typ[5][1] = operand3;
typ[4][4] = typ[5][2] = mul2string;
typ[6][0] = typ[7][4] = quotientstring;
typ[6][2] = typ[7][0] = dividendstring;
typ[6][3] = typ[7][1] = operand4;
typ[6][4] = typ[7][2] = divisorstring;

int b = underline();
typ[a] = "__";

System.out.format("%s ", Arrays.deepToString(typ[a]));

if(i%5==4) {
System.out.format("%n");
}
}
System.out.format("%n");
}

// Zufällig Zahl durch underline ersetzen:
static int underline () {
int b = RANDOM.nextInt(4);
while (b%2 == 1) {
b = RANDOM.nextInt(4);
}
return b;
}
}

[/Java]


Vielen Dank für die Hilfe, und Entschuldigung für die Grammatik Fehler, aber Deutsch ist nicht meine Muttersprache.

Liebe Grüsse

Chillchen
 

JavaMeister

Gesperrter Benutzer
Arrays deepToString gibt die Inhalte per Komma getrennt aus, wenn du es anders haben willst, musst du über das Array Iterieren und eben anders ausgeben.
 

Neue Themen


Oben