Facebook
From Trivial Hog, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 230
  1. import java.util.Random;
  2.  
  3. /**
  4.  * Created by azur on 25.11.2017.
  5.  */
  6. public class JednorekiBandyta {
  7.     public static void main(String[] args) {
  8.  
  9.         MaszynaLosujaca wygrywajacyWynik = new MaszynaLosujaca(7,7,7);
  10.      MaszynaLosujaca maszyna = new MaszynaLosujaca();
  11.  
  12.  
  13.         int iloscWygranych =0;
  14.  
  15.         for (int i = 0; i < 100; i++) {
  16.         maszyna.losuj();
  17.             System.out.println(maszyna.toString());
  18.         if(maszyna.equals(wygrywajacyWynik)){
  19.             iloscWygranych++;
  20.         }
  21.         }
  22.         System.out.println("Ilość wygranych " + iloscWygranych);
  23.     }
  24.  
  25.  
  26. }
  27.  
  28. class MaszynaLosujaca{
  29.     int slotA;
  30.     int slotB;
  31.     int slotC;
  32.  
  33.     public MaszynaLosujaca(int slotA, int slotB, int slotC) {
  34.         this.slotA = slotA;
  35.         this.slotB = slotB;
  36.         this.slotC = slotC;
  37.     }
  38.     public MaszynaLosujaca() {
  39.     }
  40.  
  41.     void losuj(){
  42.         Random liczbaLosowa = new Random();
  43.  
  44.         this.slotA = liczbaLosowa.nextInt(10);
  45.         this.slotB = liczbaLosowa.nextInt(10);
  46.         this.slotC = liczbaLosowa.nextInt(10);
  47.     }
  48.  
  49.    public String toString(){
  50.        return "Wynik losowania to   " + slotA + " | "+ slotB + " | "+ slotC;
  51.    }
  52.  
  53.     @Override
  54.     public boolean equals(Object o) {
  55.         if (this == o) return true;
  56.         if (o == null || getClass() != o.getClass()) return false;
  57.  
  58.         MaszynaLosujaca that = (MaszynaLosujaca) o;
  59.  
  60.         if (slotA != that.slotA) return false;
  61.         if (slotB != that.slotB) return false;
  62.         return slotC == that.slotC;
  63.     }
  64.  
  65.  
  66. }
  67.  
  68.