Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Random;
- import java.util.Scanner;
- import java.io.*;
- public class App {
- // Auxiliary Functions
- void convertTime(int seconds) {
- if(seconds >= 0 && seconds < 60) {
- System.out.println("Streaming for " + seconds + " seconds.");
- }
- else if(seconds >= 60 && seconds < 3600) {
- int minutes = (int)(seconds / 60);
- int secondsRemaining = seconds % 60;
- System.out.println("Streaming for " + minutes + " minutes and " + secondsRemaining + " seconds.");
- }
- else if(seconds >= 3600) {
- int hours = (int)(seconds / 3600);
- int minutesRemaining = (int)( (seconds - hours * 3600) / 60);
- int secondsRemaining = (seconds - hours * 3600) % 60;
- System.out.println("Streaming for " + hours + " hours, " + minutesRemaining + " minutes and " + secondsRemaining + " seconds.");
- }
- } // END OF FUNCTION CONVERTTIME
- void createLandscapeAsImage(Stream streamOfSomeone) {
- // System.out.println("********************************************************************************");
- // I will make it like real one dimensions (16:9) <----> Width = columns = 80 and Height = rows = 45
- // I will make 22 rows = int(45/2), because vertical distance of "|"s is bigger than horizontial space between "-"s
- for(int rows=1; rows<=22; rows++) {
- for(int columns=1; columns<=80; columns++) {
- // Rule for first row
- if(rows == 1) {
- // This code will be executed 80 times = range of columns
- System.out.print("-");
- if(columns == 80) {
- System.out.println();
- }
- }
- // Rule of 2nd row
- else if(rows == 2) {
- if(columns == 1) {
- System.out.print("|");
- }
- else if(columns == 2) {
- System.out.print(streamOfSomeone.streamer.nameOfChannel + ": " + streamOfSomeone.title);
- }
- else if(columns >= 3 && columns <= 80 - (streamOfSomeone.streamer.nameOfChannel + ": " + streamOfSomeone.title).length() ) {
- System.out.print(" ");
- }
- else if(columns == 80) {
- System.out.print("|");
- System.out.println();
- }
- }
- // Rule of medium rows
- else if(rows >= 3 && rows <= 20) {
- if(columns == 1) {
- System.out.print("|");
- }
- else if(columns >=2 && columns <= 79) {
- System.out.print(" ");
- }
- else if(columns == 80) {
- System.out.print("|");
- System.out.println();
- }
- }
- // Rule for row 21
- else if(rows == 21) {
- if(columns == 1) {
- System.out.print("|");
- }
- else if(columns >=2 && columns < 80 - ("Viewers: " + (streamOfSomeone.viewers + 1)).length()) {
- System.out.print(" ");
- }
- else if(columns == 80 - ("Viewers: " + streamOfSomeone.viewers).length()) {
- System.out.print("Viewers: " + streamOfSomeone.viewers);
- }
- else if(columns == 80) {
- System.out.print("|");
- System.out.println();
- }
- }
- // Rule for last row (22)
- else if(rows == 22) {
- System.out.print("-");
- if(columns == 80) {
- System.out.println();
- }
- }
- } // END OF SECOND FOR-LOOP
- } // END OF FIRST FOR-LOOP
- // ************************************************************************************************************************************
- // ************************************************************************************************************************************
- // ************************************************************************************************************************************
- // ************************************************************************************************************************************
- // I have ended with "screen-size"
- for(int times=1; times<=3; times++) {
- // Now, I will draw the shape of "screen-base"
- // 38 blank-spaces
- for(int i=1; i<39; i++) {
- System.out.print(" ");
- }
- // 4 symbols = "|" in positions 39,40,41 and 42 (4 spaces after the 38 blank spaces)
- for(int j=1; j<=4; j++) {
- System.out.print("|");
- }
- System.out.println();
- }
- // THE FINAL BASE OF SCREEN
- for(int numOfBaseLevels=1; numOfBaseLevels<=2; numOfBaseLevels++) {
- for(int columns=1; columns<=80; columns++) {
- System.out.print("-");
- }
- System.out.println();
- }
- // ************************************************************************************************************************************
- // ************************************************************************************************************************************
- // ************************************************************************************************************************************
- // ************************************************************************************************************************************
- } // END OF FUNCTION CREATELANSCAPEASIMAGE
- String selectRandomTalk(Stream streamOfSomeone) {
- ArrayList <String> talks = new ArrayList <String> ();
- talks.add("Hello guys? What's up?");
- talks.add("Hi " + streamOfSomeone.streamer.nameOfChannel + "! How you doing?");
- talks.add("I am so happy that my favorite streamer is back. Let's go " + streamOfSomeone.streamer.nameOfChannel);
- talks.add("Anyone knows why is he so happy today?");
- talks.add(streamOfSomeone.streamer.nameOfChannel + ", my day was pretty busy and difficult today. I like watching your channel");
- talks.add("Keep on going. You are the best!");
- talks.add("Wow! You have already " + streamOfSomeone.viewers + " viewers!");
- talks.add("Such a nice guy in this wholesome streaming community!");
- talks.add("How can I improve myself in aim?");
- talks.add("I am sure he will be the best one day!");
- Random randomObject = new Random();
- // Create a random number ---> select a random talk
- int randomTalkIndex = randomObject.nextInt(talks.size());
- int randomUserIndex = randomObject.nextInt(1000) + 1;
- return ( "User " + randomUserIndex + ": " + talks.get(randomTalkIndex) );
- }
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public static void main(String[] args) {
- // CREATE A VARIABLE THAT WILL COUNT THE DURATION OF USER'S CONNECTION IN THE STREAMING COMMUNITY
- long startTime = System.currentTimeMillis();
- // First create the streamers
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ STREAMER 1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ArrayList <String> socialsThomas = new ArrayList <String> ();
- socialsThomas.add("Facebook: Θωμάς Μπουφίκος");
- socialsThomas.add("Instagram: thomas_boufikos");
- socialsThomas.add("Twitter: Thomas Boufikos");
- Streamer Thomas = new Streamer("Thomas Boufikos", "Tommino", "Greek", 20, socialsThomas);
- // Create the bots of this channel
- NightBot nb = new NightBot("Nb", Thomas);
- Thomas.botsList.add(nb);
- PlayBot pb = new PlayBot("Pb", Thomas);
- Thomas.botsList.add(pb);
- ArrayList <String> categoriesThomas = new ArrayList <String> ();
- categoriesThomas.add("Shooters Games");
- categoriesThomas.add("Family Friendly");
- categoriesThomas.add("Greek and English Language spoken");
- categoriesThomas.add("Multiplayer");
- Stream streamOfThomas = new Stream(Thomas, "Fortnite", "My very first Stream in this streaming community", categoriesThomas);
- StreamBot sb = new StreamBot("Sb", Thomas, streamOfThomas);
- Thomas.botsList.add(sb);
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ STREAMER 2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ArrayList <String> socialsNinja = new ArrayList <String> ();
- socialsNinja.add("Facebook: Tyler Blevins Official");
- socialsNinja.add("Instagram: ninja");
- socialsNinja.add("Twitter: ninja_official");
- Streamer Ninja = new Streamer("Tyler Blevins", "Ninja", "American", 27, socialsNinja);
- // Create the bots of this channel
- NightBot nb2 = new NightBot("Nb2", Ninja);
- Ninja.botsList.add(nb2);
- PlayBot pb2 = new PlayBot("Pb2", Ninja);
- Ninja.botsList.add(pb2);
- ArrayList <String> categoriesNinja = new ArrayList <String> ();
- categoriesNinja.add("Shooters Games");
- categoriesNinja.add("Up to 18");
- categoriesNinja.add("Battle Royale Game");
- categoriesNinja.add("Multiplayer");
- Stream streamOfNinja = new Stream(Ninja, "Fortnite", "Chilling with the squad", categoriesNinja);
- StreamBot sb2 = new StreamBot("Sb2", Ninja, streamOfNinja);
- Ninja.botsList.add(sb2);
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ STREAMER 3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ArrayList <String> socialsShroud = new ArrayList <String> ();
- socialsShroud.add("Facebook: Michael Grzesiek Official");
- socialsShroud.add("Instagram: shroud_official");
- socialsShroud.add("Twitter: shroud");
- Streamer Shroud = new Streamer("Michael Grzesiek", "Shroud", "American/Canadian", 25, socialsShroud);
- // Create the bots of this channel
- NightBot nb3 = new NightBot("Nb3", Shroud);
- Shroud.botsList.add(nb3);
- PlayBot pb3 = new PlayBot("Pb3", Shroud);
- Shroud.botsList.add(pb3);
- ArrayList <String> categoriesShroud = new ArrayList <String> ();
- categoriesShroud.add("Shooters Games");
- categoriesShroud.add("Teen-rated Stream");
- categoriesShroud.add("First Person Shooters");
- categoriesShroud.add("Multiplayer");
- Stream streamOfShroud = new Stream(Shroud, "Call Of Duty: Modern Warframe", "I'm trying the new golden AK47 in COD MW", categoriesShroud);
- StreamBot sb3 = new StreamBot("Sb3", Shroud, streamOfShroud);
- Shroud.botsList.add(sb3);
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ STREAMER 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ArrayList <String> socialsTfue = new ArrayList <String> ();
- socialsTfue.add("Facebook: Turner Ellis Tenney");
- socialsTfue.add("Instagram: Tfue");
- socialsTfue.add("Twitter: Official_Tfue");
- Streamer Tfue = new Streamer("Turner Ellis Tenney", "Tfue", "American", 21, socialsTfue);
- // Create the bots of this channel
- NightBot nb4 = new NightBot("Nb4", Tfue);
- Tfue.botsList.add(nb4);
- PlayBot pb4 = new PlayBot("Pb4", Tfue);
- Tfue.botsList.add(pb4);
- ArrayList <String> categoriesTfue = new ArrayList <String> ();
- categoriesTfue.add("Shooters Games");
- categoriesTfue.add("Teen-rated Stream");
- categoriesTfue.add("English");
- categoriesTfue.add("Multiplayer");
- Stream streamOfTfue = new Stream(Tfue, "Fortnite", "Fortnite Pro Scrims: Friday Nite Squad Cash Cup", categoriesTfue);
- StreamBot sb4 = new StreamBot("Sb4", Tfue, streamOfTfue);
- Tfue.botsList.add(sb4);
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // *************************************************************************************************************************
- // *************************************************************************************************************************
- // *************************************************************************************************************************
- // *************************************************************************************************************************
- Scanner scanner2 = new Scanner(System.in);
- // First ask the username
- System.out.println("Hello user! Please type down 0 or 1 to select: ");
- System.out.println("0. Free use of our streaming community without the need of logging in.");
- System.out.println("1. You will have to enter username and password to create an account and use our streaming services.");
- System.out.println();
- System.out.println("In both cases, you will the ability to communicate with streamer and chat and write some commands to their bots");
- System.out.println("in order to play games or learn some info for them.");
- System.out.println();
- // Create the 3 basic variables for our purpose (log in)
- String username;
- String password;
- String passwordForConfirmation;
- // Read the user's input
- System.out.print("Select (0 or 1): ");
- int firstChoice = scanner2.nextInt();
- while(firstChoice != 0 && firstChoice != 1) {
- System.out.print("Select (0 or 1): ");
- firstChoice = scanner2.nextInt();
- }
- // At the end of the while-loop, the variable "firstChoice" has the value 0 or the value 1!
- if(firstChoice == 0) {
- System.out.println();
- System.out.println();
- System.out.println();
- System.out.println("So, you chose " + firstChoice + " and that means you will use our streaming services anonymously.");
- System.out.println("Your username is 'User 0' and you have no password for logging in.");
- username = "User 0";
- password = "";
- passwordForConfirmation = "";
- } // END OF IF-CASE <----> FOR GUEST USERS
- else {
- System.out.println();
- System.out.println();
- System.out.println();
- System.out.println("So, you chose " + firstChoice + " and that means that you are going to enter a username and a password.");
- System.out.print("Please type down your username: ");
- // Den diavazei tin prwti eisodo o scanner, opote apodidw tin prwti kai adiavasti eisodo se mia asxeti metavliti
- String toKanwGtDENDiavazeiTinPrwtiEisodo = scanner2.nextLine();
- username = scanner2.nextLine();
- System.out.print("Now, enter your password: ");
- password = scanner2.nextLine();
- // Now, I want the password to be confirmed by the user
- int mistakes = 0;
- while(mistakes < 3) {
- System.out.print("Confirm password: ");
- passwordForConfirmation = scanner2.nextLine();
- if(password.equals(passwordForConfirmation)) {
- System.out.println("Brilliant. Welcome to our streaming community Mr " + username);
- break;
- }
- else {
- mistakes++;
- }
- } // END OF WHILE-LOOP
- if(mistakes == 3) {
- username = "User 0";
- System.out.println("You have entered the wrong password 3 times. So, you will continue as 'User 0' and will have no password");
- }
- } // END OF ELSE-STATEMENT <----> FOR PASSWORD USERS
- System.out.println();
- System.out.println();
- Scanner scanner = new Scanner(System.in);
- // Ask the user to select which stream he wants to watch
- System.out.println("Hello " + username + "! Please type down 1,2,3 or 4 to select which stream you want to watch:");
- System.out.println("1. " + Thomas.nameOfChannel + ": " + streamOfThomas.title);
- System.out.println("2. " + Ninja.nameOfChannel + ": " + streamOfNinja.title);
- System.out.println("3. " + Shroud.nameOfChannel + ": " + streamOfShroud.title);
- System.out.println("4. " + Tfue.nameOfChannel + ": " + streamOfTfue.title);
- System.out.println();
- System.out.print("Select (1,2,3 or 4): ");
- int streamChoice = scanner.nextInt();
- Streamer streamerChoice;
- Stream streamOfStreamer;
- while(streamChoice != 1 && streamChoice != 2 && streamChoice != 3 && streamChoice != 4) {
- System.out.print("Select (1,2,3 or 4): ");
- streamChoice = scanner.nextInt();
- }
- switch(streamChoice) {
- case 1:
- streamerChoice = Thomas;
- streamOfStreamer = streamOfThomas;
- streamOfStreamer.viewers += 1; // Because user just started watching the stream
- break;
- case 2:
- streamerChoice = Ninja;
- streamOfStreamer = streamOfNinja;
- streamOfStreamer.viewers += 1; // Because user just started watching the stream
- break;
- case 3:
- streamerChoice = Shroud;
- streamOfStreamer = streamOfShroud;
- streamOfStreamer.viewers += 1; // Because user just started watching the stream
- break;
- case 4:
- streamerChoice = Tfue;
- streamOfStreamer = streamOfTfue;
- streamOfStreamer.viewers += 1; // Because user just started watching the stream
- break;
- default:
- streamerChoice = new Streamer();
- streamOfStreamer = new Stream();
- streamOfStreamer.viewers += 1; // Because user just started watching the stream
- break;
- }
- // **********************************************************************************************
- // *************** An unused variable in order to solve the problem *****************************
- String paliDiavazeiMiaTzampaEisodo = scanner.nextLine();
- // **********************************************************************************************
- // **********************************************************************************************
- // Some declarations after entering in a stream
- System.out.println();
- System.out.println();
- System.out.println();
- System.out.println();
- System.out.println();
- System.out.println();
- System.out.println();
- App app2 = new App();
- app2.createLandscapeAsImage(streamOfStreamer);
- System.out.println();
- System.out.println();
- System.out.println();
- System.out.println();
- System.out.println();
- System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
- System.out.println(" CHANNEL " + streamOfStreamer.streamer.nameOfChannel);
- System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
- // Create the contact between the user and the streamers' bots
- String userInput = "";
- while(userInput.equals("stop") == false && userInput.equals("logout") == false && userInput.equals("!stop") == false && userInput.equals("!logout") == false) {
- System.out.println(app2.selectRandomTalk(streamOfStreamer));
- // System.out.println("Write a command: ");
- System.out.print(username + ": ");
- userInput = scanner.nextLine();
- // Now, I have some input/command from the user
- // I want to check if this is a valid command or not
- // First, I have to remember that botsList can contain 4 different types of variables
- // 1. NightBot, 2. PlayBot or 3. StreamBot and 4. Bot (the first class and superclass of the other bots)
- boolean isValidCommand = false;
- for(int i=0; i<streamerChoice.botsList.size(); i++){
- // For every bot in botsList of the streamer
- Bot bot = streamerChoice.botsList.get(i);
- // Variable "bot" can also be --OR-- NightBot --OR-- PlayBot --OR-- simple Bot
- if(bot instanceof PlayBot){
- ArrayList <String> commands = ((PlayBot) bot).commands;
- for(int j=0; j<commands.size(); j++){
- // System.out.println(commands.get(j));
- if(userInput.equals(commands.get(j))){
- // That means this is a valid command for NightBot
- // So, we have to call the function "select...." with argument = commands.get(j). With this argument
- // the correct function will be called
- isValidCommand = true;
- System.out.print(" PlayBot answers: ");
- ((PlayBot) bot).selectMethodByCommand(commands.get(j));
- break;
- }
- }
- } // END OF IF-CASE FOR PLAYBOT CLASS
- else if(bot instanceof NightBot){
- ArrayList <String> commands = ((NightBot) bot).commands;
- for(int j=0; j<commands.size(); j++){
- // System.out.println(commands.get(j));
- if(userInput.equals(commands.get(j))){
- // That means this is a valid command for NightBot
- // So, we have to call the function "select...." with argument = commands.get(j). With this argument
- // the correct function will be called
- isValidCommand = true;
- System.out.print(" NightBot answers: ");
- ((NightBot) bot).selectMethodByCommand(commands.get(j));
- break;
- }
- }
- } // END OF ELSE-IF-CASE FOR NIGHTBOT CLASS
- else if(bot instanceof StreamBot){
- ArrayList <String> commands = ((StreamBot) bot).commands;
- for(int j=0; j<commands.size(); j++){
- // System.out.println(commands.get(j));
- if(userInput.equals(commands.get(j))){
- // That means this is a valid command for NightBot
- // So, we have to call the function "select...." with argument = commands.get(j). With this argument
- // the correct function will be called
- isValidCommand = true;
- System.out.print(" StreamBot answers: ");
- ((StreamBot) bot).selectMethodByCommand(commands.get(j));
- break;
- }
- }
- // IF USERINPUT = UPTIME
- if(userInput.equals("!uptime")) {
- int secondsInitially = ((StreamBot) bot).uptime();
- long secondsOfRunningApp = System.currentTimeMillis();
- long elapsedTimeApp = secondsOfRunningApp - startTime;
- int uptimeSeconds = (int)(elapsedTimeApp / 1000F) + secondsInitially;
- App app = new App();
- app.convertTime(uptimeSeconds);
- }
- } // END OF ELSE-IF-CASE FOR STREAMBOT CLASS
- } // END OF FOR-LOOP SCANS THE BOTSLIST OF THE STREAMER
- // Scanning for bots' commands has just ended
- // There is a possibility for the given command to be invalid
- boolean iHaveToStop = (userInput.equals("stop") == true) || (userInput.equals("logout") == true) || (userInput.equals("!stop") == true) ||(userInput.equals("!logout") == true);
- // The above variable becomes true, when userInput = "!stop" OR "stop" OR "!logout" OR "logout"
- // Then, I have to display some kind of message
- if(isValidCommand == false && iHaveToStop == true) {
- System.out.println("You have successfully logged out! You cannot watch streams or communicate with others until you log in again!");
- // Time to stop the programme
- // First, I will close the Scanner instance named "scanner"
- scanner.close();
- long endTime = System.currentTimeMillis();
- long elapsedTimeInMillis = endTime - startTime;
- int elapsedTimeInSeconds = (int) (elapsedTimeInMillis / 1000F);
- if(elapsedTimeInSeconds < 60) {
- System.out.println("(You had been connected for " + elapsedTimeInSeconds + " seconds)");
- }
- else {
- int minutesLoggedIn = (int) (elapsedTimeInSeconds / 60);
- int secondsLoggedIn = elapsedTimeInSeconds % 60;
- System.out.println("(You had been connected for " + minutesLoggedIn + " minutes and " + secondsLoggedIn + " seconds).");
- }
- } // END OF IF-CASE WHEN I TYPE "STOP" OR "LOGOUT" IN CONSOLE
- else if(isValidCommand == false && iHaveToStop == false) {
- // System.out.println("Invalid command (" + userInput + "). Try another command and notice that a common mistake is that some forget to write '!' first!");
- }
- System.out.println();
- // System.out.println();
- } // END OF WHILE-LOOP <-------------------> TAKES ALWAYS NEW COMMANDS
- System.exit(0);
- } // END OF MAIN FUNCTION
- } // END OF CLASS APP = MAIN FUNCTION OF THE PROJECT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement