Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BobbyTheTeenAI
  4. {
  5.   public static void main(String[] args)
  6.   {
  7.     Scanner in = new Scanner(System.in);
  8.  
  9.     System.out.println("Кажи нещо на Боби:"); // say something to Bobby
  10.     String line = in.nextLine(); // reads the next line from the console
  11.  
  12.  
  13.     if (line.isEmpty()) {    // if line is empty user gets respond from Bobby and the program waits for the next line.
  14.       System.out.println("Хубаво деее");
  15.       line = in.nextLine();
  16.     }
  17.  
  18.     Boolean isTrue = true; /// this is a boolean used for breaking the infinite loop with a command
  19.     if (line.equals("Спри")) {
  20.       isTrue = false;
  21.       System.out.println("Аре чау....");  /// program saying goodbye. after this the  program stops.
  22.     }
  23.  
  24.     while (isTrue) { // loops till the user enters a End command;
  25.  
  26.       String lastSymbol = line.substring(line.length() - 1); // gets the last symbol of the String line.
  27.       String secondToLastSymbol = line.substring(line.length() - 2); // gets the second to last symbol from the String line
  28.  
  29.  
  30.       for (int i = 0; i < 1; i++) { // loops ones throe the if-else statement
  31.  
  32.         if (secondToLastSymbol.equals(secondToLastSymbol.toLowerCase())) {
  33.           if (lastSymbol.equals("?")) {
  34.             System.out.println("Добре.");
  35.           }
  36.           else {
  37.             System.out.println("Ахъ");
  38.           }
  39.         }
  40.         else if (secondToLastSymbol.equals(secondToLastSymbol.toUpperCase())) {
  41.           if (lastSymbol.equals("?")) {
  42.             System.out.println("Споко бе, ман!");
  43.           }
  44.           else {
  45.             System.out.println("Спокоооо, знам к'во правя!");
  46.           }
  47.         }
  48.       }
  49.       line = in.nextLine();  /// if the line is not equal to the STOP command it waits for the next line from the uses.
  50.  
  51.       if (line.equals("Спри")) {
  52.         System.out.println("Аре...");
  53.         break;
  54.       }
  55.     }
  56.   }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement