Advertisement
makispaiktis

Streaming - Stream.java

Nov 15th, 2019 (edited)
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.89 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Random;
  3.  
  4. public class Stream {
  5.    
  6.     // Variables
  7.     Streamer streamer;
  8.     String gameBeenPlaying;
  9.     String title;
  10.     ArrayList <String> categories;
  11.     // Random-made variables
  12.     int viewers;
  13.     int secondsStreaming;
  14.    
  15.     // Constructors
  16.     Stream(){
  17.         streamer = new Streamer();
  18.         gameBeenPlaying = "";
  19.         title = "";
  20.         categories = new ArrayList <String> ();
  21.         viewers = 0;
  22.         secondsStreaming = 0;
  23.     }
  24.    
  25.     Stream(Streamer streamer, String gameBeenPlaying, String title, ArrayList <String> categories){
  26.         this.streamer = streamer;
  27.         this.gameBeenPlaying = gameBeenPlaying;
  28.         this.title = title;
  29.         this.categories = categories;
  30.        
  31.         // About "viewers"
  32.         Random randomObject = new Random();
  33.         int indexOfViewers = randomObject.nextInt(10);
  34.         // The above variable has a value from 0 to 9 (inclusive) ---> 10 possible values
  35.         // I want this one to be true
  36.         // Probability(0 <= viewers <= 99) = 3 / 10
  37.         // Probability(100 <= viewers <= 999) = 5 / 10
  38.         // Probability(1000 <= viewers <= 9999) = 2 / 10
  39.         if(indexOfViewers >= 0 && viewers <= 2) {
  40.             this.viewers = randomObject.nextInt(100);
  41.         }
  42.         else if(indexOfViewers >= 3 && indexOfViewers <= 7) {
  43.             this.viewers = randomObject.nextInt(900) + 100;
  44.         }
  45.         else {
  46.             this.viewers = randomObject.nextInt(9000) + 1000;
  47.         }
  48.        
  49.         // About "secondsStreaming"
  50.         // I want this:
  51.         // Probability(0s <= timeStreaming < 3600s = 1h) = 3 / 10
  52.         // Probability(3600s <= timeStreaming < 7200s = 2h) = 3 / 10
  53.         // Probability(7200s <= timeStreaming < 10800s = 3h) = 3 / 10
  54.         // Probability(10800s <= timeStreaming < 14400s = 4h) = 1 / 10
  55.         int indexOfSecondsStreaming = randomObject.nextInt(10);
  56.         if(indexOfSecondsStreaming >= 0 && indexOfSecondsStreaming <= 2){
  57.             this.secondsStreaming = randomObject.nextInt(3600);
  58.         }
  59.         else if(indexOfSecondsStreaming >= 3 && indexOfSecondsStreaming <= 5){
  60.             this.secondsStreaming = randomObject.nextInt(3600) + 3600;
  61.         }
  62.         else if(indexOfSecondsStreaming >= 6 && indexOfSecondsStreaming <= 8){
  63.             this.secondsStreaming = randomObject.nextInt(3600) + 7200;
  64.         }
  65.         else{
  66.             this.secondsStreaming = randomObject.nextInt(3600) + 10800;
  67.         }
  68.        
  69.     }   // END OF 2ND CONSTRUCTOR
  70.    
  71.    
  72.     // Methods
  73.     void convertSeconds(int seconds) {
  74.        
  75.     }
  76.    
  77.    
  78.     void showStatus() {
  79.         System.out.println("Streamer: " + streamer.name);
  80.         System.out.println("Game Been Playing Now: " + gameBeenPlaying);
  81.         System.out.println("Title: " + title);
  82.         System.out.println("Categories: ");
  83.         if(categories.size() != 0) {
  84.             for(int i=0; i<categories.size(); i++) {
  85.                 System.out.println(categories.get(i));
  86.             }
  87.         }
  88.         else {
  89.             System.out.println("Streamer " + streamer.name + " has not added categories yet!");
  90.         }
  91.         System.out.println("Viewers: " + viewers);
  92.         System.out.println("Seconds streaming: " + secondsStreaming);
  93.        
  94.     }   // END OF FUNCTION SHOWSTATUS
  95.    
  96.    
  97.    
  98.    
  99.    
  100.    
  101. }   // END OF CLASS STREAM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement