Advertisement
Randomsurpriseguy

Regenübung 2.0

Dec 21st, 2017
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Übung8;
  2. import java.util.Scanner;
  3. public class Aufgabe {
  4.    
  5.     static Scanner sc=new Scanner(System.in);
  6.    
  7.     public static void AP2D(double[][] Array) {
  8.         int x;
  9.         int y=0;
  10.         while (y<Array.length) {
  11.             x=0;
  12.             while (x<Array[y].length) {
  13.                 System.out.print(Array[y][x]+"\t");
  14.                 x++;
  15.             }
  16.             System.out.println();
  17.             y++;
  18.         }
  19.        
  20.     System.out.println();//Schönheitsop, damit Arrays nicht direkt aneinanderhängen
  21.     }
  22.    
  23.     public static boolean[][] Sickern(boolean[][] Array, double[][] Chance){
  24.         int x=Array[0].length-1;
  25.         int y=Array.length-1;
  26.         while (y>=1) {
  27.             x=0;
  28.             while (x<Array[y].length) {
  29.                 if (Array[y-1][x]&&!Array[y][x]) {//Sickert nur auf Pos. wenn Pos leer ist und oberhalb voll ist
  30.                     if (Math.random()<Chance[y][x]) {
  31.                         Array[y-1][x]=false;
  32.                         Array[y][x]=true;
  33.                     }
  34.                 }
  35.                 x++;
  36.             }
  37.             y--;
  38.         }
  39.         x=0;
  40.         while (x<Array[0].length) {
  41.             if (Math.random()<Chance[y][x]) {
  42.                 Array[0][x]=true;
  43.             }
  44.             x++;
  45.         }
  46.        
  47.         return Array;
  48.     }
  49.    
  50.     public static void Wasserstand(boolean[][] Array,int c) {//Arrayausgabe von 2Dimensionaler Matrix
  51.         System.out.println("Durchlauf"+c);
  52.         System.out.println("----------------Wasserstand----------------");
  53.         int x;
  54.         int y=0;
  55.         while (y<Array.length) {
  56.             x=0;
  57.             while (x<Array[y].length) {
  58.                 if (Array[y][x]) System.out.print("■ ");
  59.                 else System.out.print("□ ");
  60.                 x++;
  61.             }
  62.             System.out.println();
  63.             y++;
  64.            
  65.         }
  66.         System.out.println("-------------------------------------------\n");
  67.     }
  68.    
  69.     public static void main(String[] args) {
  70.         int c=1;//Durchlaufcounter
  71.         int h=5;//Tiefe des Querschnitts,Größe kann nach Belieben festgelegt werden (logischerweise als positive ganze Zahl)
  72.         int b=6;//breite des Querschnitts
  73.         boolean H2O[][]=new boolean[h][b];//boolean Feld mit true, wenn an der Position Wasser ist und false wenn nicht. Die erste Zeile befindet sich bereits unterhalb der Oberfläche, deren Wasserwert stets als true angenommen wird, da es ja regnet.
  74.         double P[][]=new double[h][b];//Mit p an position die Wahrscheinlichkeit, dass das Wasser in einem Durchlauf in die Position sickert, wenn oberhalb wasser vorhanden ist
  75.         System.out.println("Gebe in positiven Prozent die durchschnittliche Durchsickerwahrscheinlichkeit in dem Querschnitt an \nund einen absoluten Abweichungsbereich um diesen. \nFür einen Bereich von 0 bis 100 Prozent einfach 0 und 100 eingeben.");
  76.         double AP=1000;
  77.         double Dif=1000;
  78.         while (AP<0||AP>100) {
  79.             System.out.println("Durchschnittswahrscheinlichkeit: ");
  80.             AP=sc.nextDouble();
  81.         }
  82.         while (Dif<0||Dif>100) {
  83.             System.out.println("Abweichungsbereich: ");
  84.             Dif=sc.nextDouble();
  85.         }
  86.         double A;
  87.         int x=0;
  88.         int y=0;
  89.         while (y<P.length) {
  90.             x=0;
  91.             while (x<P[y].length) {
  92.                 A=1000;
  93.                 while (A>100||A<0) {
  94.                     A=Math.random()*2*Dif-Dif+AP;
  95.                 }
  96.                 P[y][x]=A/100;//Gibt einen Wert im bereich 2Dif um AP aus
  97.                 x++;
  98.             }
  99.             y++;
  100.         }
  101.         AP2D(P);
  102.         String Auswahl=Random;
  103.         System.out.println("Für manuellen Durchlauf gebe M ein, für automatischen A.");
  104.         while (!Auswahl.equals("M")&&!Auswahl.equals("A")){
  105.             Auswahl=sc.next();
  106.         }
  107.         if (Auswahl.equals("M"){
  108.         String S="";
  109.         System.out.println("Drücke eine beliebige Taste und Enter um einen Durchlauf zu simulieren. Gebe \"Stopp\" ein, um das Programm zu beenden");
  110.         while (!S.equals("Stopp")) {//Für benutzerabhängige Anzahl von Durchläufen
  111.             H2O=Sickern(H2O,P);
  112.             Wasserstand(H2O,c);
  113.             S=sc.next();
  114.             c++;
  115.         }
  116.         }
  117.         else {
  118.         boolean W=false;
  119.         while (!W) {// Solange bis alle H2O Felder belegt sind
  120.             W=true;
  121.             y=0;
  122.             while (y<H2O.length) {
  123.                 x=0;
  124.                 while(x<H2O[y].length) {
  125.                     if (!H2O[y][x]) W=false;
  126.                     x++;
  127.                 }
  128.                 y++;
  129.             }
  130.             if (!W) {
  131.                 H2O=Sickern(H2O,P);
  132.                 Wasserstand(H2O,c);
  133.                 c++;
  134.             }
  135.         }
  136.         }
  137.         sc.close();
  138.     }
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement