ERLEDIGT
NEIN
NEIN
ANTWORTEN
0
0
ZUGRIFFE
1231
1231
EMPFEHLEN
-
Und hier eine Roh-Version für Beanshell (ich verwende jEdit).
Natürlich ohne Lösungsweg.
Code java:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
// Zuerst ein paar Hilfsklassen und Methoden definieren void vrPrint(String str) { textArea.setSelectedText(str+"\n"); } class Ei { public String name; public int gramm; public int kcal; public Ei () {} public Ei(String name, int gramm, int kcal) { this.name = name; this.gramm = gramm; this.kcal = kcal; } public String toString() { str = new String(name); str += ": "+gramm+" Gramm"; str += ", "+kcal +" kcal" ; return str; } } class Ostersuche { private int tragkraft; private Ei[] nest; private Ei[] korb; public static void erstelleNest(int cntEier, int tragkraft , int kcalMin, int kcalMax , int gMin, int gMax) { int g; // Masse in Gramm int c; // kcal int gDiff = gMax - gMin; int cDiff = kcalMax - kcalMin; vrPrint(""+tragkraft); for ( i = 0; i < cntEier; i++ ) { vrPrint("Ei "+i); g = gMin+(int)Math.rint(Math.random()*gDiff); c = kcalMin+(int)Math.rint(Math.random()*cDiff); vrPrint(g+" "+c); } } public static void erstelleNest() { int cntEier = 500; int tragkraft = 500; int kcalMin = 50; int kcalMax = 1500; int gMin = 50; int gMax = 300; Ostersuche.erstelleNest(cntEier, tragkraft , kcalMin, kcalMax , gMin, gMax); } Ostersuche() { tragkraft = 0; nest = new Ei[0]; korb = new Ei[0]; } public void einlesen() { String str; String[] tkn; BufferedReader br = new BufferedReader(new StringReader(textArea.getText())); buf = new LinkedList(); str = br.readLine(); tragkraft = Integer.valueOf(str); int cnt; for ( cnt = 0; (str=br.readLine()) != null; cnt++ ) { str = str.trim(); n = str; str = br.readLine(); if ( str == null ) break; tkn = str.split("\\s+"); if ( tkn.length < 2 ) break; g = Integer.valueOf(tkn[0]); c = Integer.valueOf(tkn[1]); buf.add(new Ei(n,g,c)); } nest = new Ei[cnt]; cnt = 0; for ( ei : buf ) { nest[cnt++] = (Ei)ei; } } private void ausgeben(Ei[] e) { int cCnt = 0; int gCnt = 0; for ( ei : e ) { vrPrint(ei.toString()); cCnt += ei.kcal; gCnt += ei.gramm; } str = "Summe"; str += ": "+gCnt+" Gramm"; str += ", "+cCnt+" kcal" ; vrPrint(str); } public void nestAusgeben() { ausgeben(nest); } public void korbAusgeben() { ausgeben(korb); } public void fuelleKorb() { // das verrate ich euch nicht ;) return; } } // Ab hier beginnt die eigentliche Verarbeitung ret = Macros.confirm(view , "Soll eine neue Datei angelegt werden?" , JOptionPane.YES_NO_CANCEL_OPTION); if ( ret == JOptionPane.CANCEL_OPTION ) return; if ( ret == JOptionPane.YES_OPTION ) jEdit.newFile(view); Ostersuche.erstelleNest(); suche = new Ostersuche(); suche.einlesen(); jEdit.newFile(view); suche.nestAusgeben();
Vielen Dank für die Nutzung des Bewerten- und Danke-Buttons
Wenn man sieht, dass man einen anderen glücklich gemacht hat, ist die Welt um zwei glückliche Menschen reicher.
Ähnliche Themen
-
Probleme mit dem ausführen von beanshell
Von mrno im Forum JavaAntworten: 0Letzter Beitrag: 14.12.06, 14:26 -
Quiz?
Von MeisterLampion im Forum Office-AnwendungenAntworten: 12Letzter Beitrag: 03.11.06, 15:48 -
BeanShell von java nach script und zurück
Von VBKenner im Forum JavaAntworten: 2Letzter Beitrag: 09.03.06, 11:44 -
Die nette Beanshell
Von Thomas Darimont im Forum JavaAntworten: 0Letzter Beitrag: 18.02.05, 23:50 -
Quiz
Von alkaline im Forum PHPAntworten: 0Letzter Beitrag: 27.09.04, 10:16





Login





