Advertisement
Nairo05

Untitled

Oct 11th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.20 KB | None | 0 0
  1. //Main
  2. public class Main {
  3.  
  4.     public static void main(String[] args){
  5.         new Beete();
  6.     }
  7. }
  8.  
  9.  
  10. //Class Beete
  11. import javax.swing.*;
  12. import java.util.ArrayList;
  13. import java.util.Random;
  14.  
  15. public class Beete {
  16.  
  17.     private static final int BLAU = 0;
  18.     private static final int GELB = 1;
  19.     private static final int GRUN = 2;
  20.     private static final int ROT = 3;
  21.     private static final int ORANGE = 4;
  22.     private static final int ROSA = 5;
  23.     private static final int TURKIS = 6;
  24.  
  25.     private int beet[][];
  26.     private int anzahlblumen;
  27.     private int wunsche;
  28.     private ArrayList<Integer> combis = new ArrayList();
  29.     private ArrayList<Integer> blumen = new ArrayList();
  30.  
  31.     public Beete(){
  32.        anzahlblumen = Integer.parseInt(JOptionPane.showInputDialog(null,"Wie viele Blumen", "Eingaben", JOptionPane.PLAIN_MESSAGE));
  33.        wunsche = Integer.parseInt(JOptionPane.showInputDialog(null,"Wie viele Wünsche ?", "Eingaben", JOptionPane.PLAIN_MESSAGE));
  34.  
  35.        //Platzhalten um durch 3 teilen zu können
  36.        combis.add(9);
  37.  
  38.         for (int i = 0; i < wunsche; i++){
  39.             JTextField f1 = new JTextField();
  40.             JTextField blume1 = new JTextField();
  41.             JTextField blume2 = new JTextField();
  42.             JTextField punkte = new JTextField();
  43.  
  44.             f1.setText("Blau="+BLAU+ " Gelb="+GELB+" Grun="+GRUN+" ROT="+ROT+ " Orange="+ORANGE+" Rosa="+ROSA+ " Turkis="+TURKIS);
  45.  
  46.             Object[] message = {"info", f1, "blume1", blume1, "blume2", blume2, "punkte", punkte};
  47.  
  48.             JOptionPane pane = new JOptionPane( message,
  49.                     JOptionPane.PLAIN_MESSAGE,
  50.                     JOptionPane.OK_CANCEL_OPTION);
  51.             pane.createDialog(null, "Combis").setVisible(true);
  52.  
  53.             combis.add(Integer.valueOf(blume1.getText()));
  54.             combis.add(Integer.valueOf(blume2.getText()));
  55.             combis.add(Integer.valueOf(punkte.getText()));
  56.         }
  57.  
  58.         System.out.println("Eingelesen:");
  59.         System.out.println(anzahlblumen+" vercchiedene Blumen: ");
  60.         System.out.println(wunsche+" Wünsche, nämlich");
  61.  
  62.         for (int i = 1; i < combis.size(); i++){
  63.             if ((i%3)==0){
  64.                 System.out.println("gibt "+combis.get(i)+" Punkte");
  65.             } else {
  66.                 System.out.println("Blume " + combis.get(i));
  67.             }
  68.         }
  69.  
  70.  
  71.         if (anzahlblumen <= 7){
  72.             while (blumen.size() < anzahlblumen){
  73.                 for (int i = 1; i < combis.size(); i++){
  74.                     if (((i%3)==0)&&(combis.get(i)==3)){
  75.                         if (!blumen.contains(combis.get(i-1))) {
  76.                             blumen.add(combis.get(i - 1));
  77.                         }
  78.                         if (!blumen.contains(combis.get(i-2))) {
  79.                             blumen.add(combis.get(i - 2));
  80.                         }
  81.                     }
  82.                 }
  83.                 for (int i = 1; i < combis.size(); i++){
  84.                     if (((i%3)==0)&&(combis.get(i)==2)){
  85.                         if (!blumen.contains(combis.get(i-1))) {
  86.                             blumen.add(combis.get(i - 1));
  87.                         }
  88.                         if (!blumen.contains(combis.get(i-2))) {
  89.                             blumen.add(combis.get(i - 2));
  90.                         }
  91.                     }
  92.                 }
  93.                 for (int i = 1; i < combis.size(); i++) {
  94.                     if (((i % 3) == 0) && (combis.get(i) == 1)) {
  95.                         if (!blumen.contains(combis.get(i-1))) {
  96.                             blumen.add(combis.get(i - 1));
  97.                         }
  98.                         if (!blumen.contains(combis.get(i-2))) {
  99.                             blumen.add(combis.get(i - 2));
  100.                         }
  101.                     }
  102.                 }
  103.  
  104.                 int randint = new Random().nextInt(7);
  105.                 if (!blumen.contains(randint)){
  106.                     blumen.add(randint);
  107.                 }
  108.  
  109.             }
  110.         }
  111.  
  112.         System.out.println("Es wurden folgende Blumenfarben ausgewählt:");
  113.         for (int i = 0; i < blumen.size(); i++){
  114.             System.out.println(blumen.get(i)+" ");
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement