/** This method will get the information to create an instance of a MarshmallowMonster. */
  private void makeUserMonster() {
    // Step one: Get variables
    String userName; // Declares (YAY DECLARATIONS) a String type called userName
    int userEyes;
    int userNoseCount;
    double userHair;
    double userLegs;
    boolean userBellyButton;

    // Step two: Define variables by using Scanner to get user input.
    System.out.println("Type in a name for your monster.");
    userName = monsterScanner.nextLine();
    System.out.println("Type in a number of eyes for your monster");
    userEyes = monsterScanner.nextInt();
    System.out.println("Type in a number of noses for your monster.");
    userNoseCount = monsterScanner.nextInt();
    System.out.println(
        "How much hair do you want your monster to have? Type in a floating point or decimal number");
    userHair = monsterScanner.nextDouble();
    System.out.println("How many Legs do you want your monster to have? Any real number will work");
    userLegs = monsterScanner.nextDouble();
    System.out.println("Does your monster have a bellybutton? Type in True or False");
    userBellyButton = monsterScanner.nextBoolean();

    // Step three: Make a monster - use the Constructor! (The order of the parameters matters and
    // must match the order of everything else)
    userMonster =
        new MarshmallowMonsterIAP(
            userName, userEyes, userNoseCount, userHair, userLegs, userBellyButton);
  }
  /** This method will get the information to create an instance of a MarshmallowMonster. */
  private void MakeUserMonster() {
    // Step one: Get variables
    String userName;
    int userEyes;
    int userNoseCount;
    double userHair;
    double userLegs;
    boolean userBellyButton;

    // Step two: Define variables by using Scanner to get user input.
    System.out.println("Type in your name for your monster.");
    userName = monsterScanner.nextLine();
    System.out.println("Type in the number of eyes for your monster");
    userEyes = monsterScanner.nextInt();
    System.out.println("Type in the number of noses for you monster");
    userNoseCount = monsterScanner.nextInt();
    System.out.println("How much hair does your monster have? Type in a floating point or decimal");
    userHair = monsterScanner.nextDouble();
    System.out.println("How many legs?");
    userLegs = monsterScanner.nextDouble();
    System.out.println("Does it have a belly button? Type true or false");
    userBellyButton = monsterScanner.nextBoolean();

    // Step three: make a monster - use the constructor.
    userMonster =
        new MarshmallowMonsters(
            userName, userEyes, userNoseCount, userHair, userLegs, userBellyButton);
  }
  private void askQuestions() {
    System.out.println("Type in a better name for the monster");
    String betterMonsterName = monsterScanner.next();

    System.out.println("Type in a new number of eyes");
    int betterMonsterEyes = monsterScanner.nextInt();

    System.out.println("Type in a new number of legs");
    double betterMonsterLegs = monsterScanner.nextDouble();

    System.out.println("Type in a new number of noses");
    int betterMonsterNose = monsterScanner.nextInt();

    System.out.println("Type in a new number of hair");
    double betterMonsterHair = monsterScanner.nextDouble();

    System.out.println("Will it have a bellybutton?(True/False)");
    boolean betterMonsterBellyButton = monsterScanner.nextBoolean();

    ashMonster.setMonsterName(betterMonsterName);
    ashMonster.setMonsterEyes(betterMonsterEyes);
    ashMonster.setMonsterLegs(betterMonsterLegs);
    ashMonster.setMonsterNose(betterMonsterNose);
    ashMonster.setMonsterHair(betterMonsterHair);
    ashMonster.setMonsterBellyButton(betterMonsterBellyButton);
  }
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner scan = new Scanner(System.in);
    System.out.println("What time is it? (hours only): ");
    int hourOfDay = scan.nextInt();
    System.out.println("How much money do I have? ");
    float money = scan.nextFloat();
    System.out.println("Am I healthy? true/false: ");
    boolean isHealthy = scan.nextBoolean();
    if (isHealthy) {
      if (money < 10) {
        System.out.println("I will go to the cafe.");
      }
      if (money >= 10) {
        System.out.println("I will go to the movies.");
      }

    } else {
      if (money > 0) {
        System.out.println("I will buy medicine and stay home.");
      } else {
        System.out.println("I will stay home and have tea.");
      }
    }
  }
  /** This method will get the information to create an instance of a MarshmallowMonster. */
  private void makeUserMonster() {
    // Step one: Get variables
    String userName;
    int userEyes;
    int userNoseCount;
    double userHair;
    double userLegs;
    boolean userBellyButton;

    // Step two:Define variables by using Scanner to get inputs
    System.out.println("Type in your name for your monster.");
    userName = monsterScanner.nextLine();
    System.out.println("Type in the number of eyes for your monster.");
    userEyes = monsterScanner.nextInt();
    System.out.println("Type in number of Noses.");
    userNoseCount = monsterScanner.nextInt();
    System.out.println("Type in number of hair.");
    userHair = monsterScanner.nextDouble();
    System.out.println("Type in new number of legs.");
    userLegs = monsterScanner.nextDouble();
    System.out.println("Does it have a bellybutton?(True/False)");
    userBellyButton = monsterScanner.nextBoolean();

    // Step three: Make a monster - use the Constructor!
    userMonster =
        new MarshmallowMonster(
            userName, userEyes, userNoseCount, userHair, userLegs, userBellyButton);
  }
  private void askQuestions() {

    System.out.println("Type in a better name for the monster");
    String betterMonsterName = monsterScanner.next();
    greysonMonster.setMonsterName(betterMonsterName);

    System.out.println("Type in a different number of eyes for the monster");
    int betterMonsterEyes = monsterScanner.nextInt();
    greysonMonster.setMonsterEyes(betterMonsterEyes);

    System.out.println("Type in a different number of noses for the monster");
    int betterMonsterNoses = monsterScanner.nextInt();
    greysonMonster.setMonsterNoses(betterMonsterNoses);

    System.out.println("Type in a different number of hair for the monster");
    double betterMonsterHair = monsterScanner.nextDouble();
    greysonMonster.setMonsterHair(betterMonsterHair);

    System.out.println("Type in a new number for the monster's legs");
    double betterMonsterLegs = monsterScanner.nextDouble();
    greysonMonster.setMonsterLegs(betterMonsterLegs);

    System.out.println("Does the monster have a bellybutton? True or false.");
    boolean betterMonsterBellyButton = monsterScanner.nextBoolean();
    greysonMonster.setMonsterBellyButton(betterMonsterBellyButton);
  }
Beispiel #7
0
  public static void main(String args[]) {
    Scanner scan = new Scanner(System.in);
    int y = 1;
    int z = 0;
    int k = 0;
    int[] forEachArray = {1, 2, 3, 4, 5};

    boolean condition;
    System.out.print("Is condition true or false? ");
    condition = scan.nextBoolean();

    int x;
    System.out.print("Enter x: ");
    x = scan.nextInt();

    // If-Else statements
    if (condition) {
      System.out.println("Condition is: " + condition);
    } else {
      System.out.println("Condition is: " + condition);
    }

    // Nested if-else
    if (x <= 5) {
      System.out.println("x is less than or equal to 5");
    } else if (x > 5 && x <= 10) {
      System.out.println("x is greater than 5 and less than or equal to 10");
    } else {
      System.out.println("x satisfies neither of the two preceding statements");
    }

    // For loop
    for (int i = 0; i <= 10; i++) {
      System.out.print(i + " ");
    }

    System.out.println();

    // While loop
    while (k <= 5) {
      System.out.print(k + " ");
      k++;
    }

    System.out.println();

    // Do-While loop
    do {
      y++;
    } while (y <= 7);

    System.out.println("y is: " + y);

    // For each loop
    for (int j : forEachArray) {
      z += j;
    }

    System.out.println("z is: " + z);
  }
Beispiel #8
0
  private static void search() {
    Research[] allResearches = service.findAllResearches();
    for (int i = 0; i < allResearches.length; i++) {
      System.out.println(i + ": " + allResearches[i].getName());
    }
    Research mResearch = allResearches[sc.nextInt()];

    Question[] questions = service.findAllQuestionsByResearch(mResearch);
    for (int i = 0; i < questions.length; i++) {
      System.out.println(i + ": " + questions[i].getQuestion());
    }

    ArrayList<Restricion> restricions = new ArrayList<Restricion>();
    while (true) {
      System.out.print("dodac? > ");
      boolean b = sc.nextBoolean();
      if (!b) {
        break;
      }
      Restricion restricion = new Restricion();
      System.out.println("nr pytania >");
      restricion.setQuestion(questions[sc.nextInt()]);
      System.out.println("restrykcja >");
      restricion.setRest(sc.next());
      System.out.println("1.equal, 2.greater, 3. less, 4.like");
      switch (sc.nextInt()) {
        case 1:
          restricion.setRestrictionType(RestrictionType.EQUAL);
          break;

        case 2:
          restricion.setRestrictionType(RestrictionType.GREATER);
          break;

        case 3:
          restricion.setRestrictionType(RestrictionType.LESS);
          break;

        case 4:
          restricion.setRestrictionType(RestrictionType.LIKE);
          break;

        default:
          break;
      }
      restricions.add(restricion);
    }

    AnswerList[] search = service.search(mResearch.getId(), restricions);
    for (AnswerList answerList : search) {
      System.out.println(answerList.getAnswers());
      for (Answer answer : answerList.getAnswers()) {
        System.out.println(answer.getQuestion() + ": " + answer.getAnswer());
      }
    }
    System.out.println("*");
  }
Beispiel #9
0
  public static void inputPriceStock(Scanner inputs, Stock item) {
    System.out.print("Enter price: ");
    double price = inputs.nextDouble();

    System.out.print("Enter stock: ");
    boolean stock = inputs.nextBoolean();

    item.setPrice(price);
    item.setStock(stock);
  }
  /**
   * helper for ItemParser, parses in booleans using their type
   *
   * @param scan
   * @param type
   * @return
   * @throws ParserError
   */
  private static boolean parseBoolean(Scanner scan, String type) throws ParserError {
    if (!gobble(scan, "<" + type + ">")) {
      throw new ParserError("Parsing Boolean: Expecting <" + type + ">, got " + scan.next());
    }
    boolean value = scan.nextBoolean();

    if (!gobble(scan, "</" + type + ">")) {
      throw new ParserError("Parsing Boolean: Expecting </" + type + ">, got " + scan.next());
    }
    return value;
  }
  private Animation parseImageSpriteSheetAnimation(
      Scanner cmdScanner, SpriteSheet sheet, int frameDuration) {
    int firstFrameCol = cmdScanner.nextInt();
    int firstFrameRow = cmdScanner.nextInt();
    int lastFrameCol = cmdScanner.nextInt();
    int lastFrameRow = cmdScanner.nextInt();
    boolean loop = cmdScanner.nextBoolean();

    return new Animation(
        sheet, firstFrameCol, firstFrameRow, lastFrameCol, lastFrameRow, true, frameDuration, loop);
  }
 private static void lookForDifferentThingsUsingScanner(String string) {
   Scanner scanner = new Scanner(string);
   while (scanner.hasNext()) {
     if (scanner.hasNextBoolean()) {
       System.out.println("Found Boolean :" + scanner.nextBoolean());
     } else if (scanner.hasNextInt()) {
       System.out.println("Found Integer :" + scanner.nextInt());
     } else {
       System.out.println("Different thing :" + scanner.next());
     }
   }
 }
Beispiel #13
0
  /** This method allows to change the fields of each of the plants */
  public void changeInfo() {

    boolean choice;

    System.out.println(
        "Enter true if the current info of your plant is correct, "
            + "enter false if you would like to change the plant information: ");
    String toString = toString(); // Assign the method text to a string object

    // System.out.println("\n");

    System.out.println(toString); // Display current information to the user

    choice = s.nextBoolean(); // User will decide whether plant information is correct

    s.nextLine(); // Clear newline character

    // If the user enters false then this if statement block will execute asking the user for the
    // information of the plant
    if (!choice) {
      System.out.println("Enter the common name of the plant: ");
      commonName = s.nextLine();

      System.out.println("Enter the scientific name of the plant: ");
      scientificName = s.nextLine();

      System.out.println("What is the maximum height of this plant: ");
      maxHeightInFeet = s.nextDouble();

      System.out.println("How much does this plant cost: ");
      plantPrice = s.nextDouble();

      System.out.println("Is this plant fragile: (true for yes and false for no: ");
      isFragile = s.nextBoolean();

      s.nextLine(); // Clear newline
    }
  }
 @Override
 public Boolean deserialize(Scanner scanner) {
   if (scanner.hasNextBoolean()) {
     return scanner.nextBoolean();
   } else {
     String next = scanner.next();
     if ("null".equals(next)) {
       return null;
     } else {
       logger.log(Level.SEVERE, "Boolean" + next);
       return null;
     }
   }
 }
Beispiel #15
0
 private static void scanner2() {
   Scanner sc = new Scanner(System.in);
   while (!sc.hasNext("exit")) {
     System.out.println(
         sc.hasNextInt()
             ? "(int) " + sc.nextInt()
             : sc.hasNextLong()
                 ? "(long) " + sc.nextLong()
                 : sc.hasNextDouble()
                     ? "(double) " + sc.nextDouble()
                     : sc.hasNextBoolean()
                         ? "(boolean) " + sc.nextBoolean()
                         : "(String) " + sc.next());
   }
 }
 public static void main(final String[] args) {
   final Scanner sis = new Scanner(System.in);
   output(HELP_MESSAGE);
   while (sis.hasNext()) {
     if (sis.hasNextInt()) {
       final int next = sis.nextInt();
       output("You entered an Integer = %d", next);
     } else if (sis.hasNextLong()) {
       final long next = sis.nextLong();
       output("You entered a Long = %d", next);
     } else if (sis.hasNextDouble()) {
       final double next = sis.nextDouble();
       output("You entered a Double = %f", next);
     } else if (sis.hasNext("\\d+")) {
       final BigInteger next = sis.nextBigInteger();
       output("You entered a BigInteger = %s", next);
     } else if (sis.hasNextBoolean()) {
       final boolean next = sis.nextBoolean();
       output("You entered a Boolean representation = %s", next);
     } else if (sis.hasNext(DATE_PATTERN)) {
       final String next = sis.next(DATE_PATTERN);
       output("You entered a Date representation = %s", next);
     } else // unclassified
     {
       final String next = sis.next();
       if (isValidURL(next)) {
         output("You entered a valid URL = %s", next);
       } else {
         if (EXIT_COMMANDS.contains(next)) {
           output("Exit command %s issued, exiting!", next);
           break;
         } else if (HELP_COMMANDS.contains(next)) {
           output(HELP_MESSAGE);
         } else {
           output("You entered an unclassified String = %s", next);
         }
       }
     }
   }
   /*
      This will close the underlying Readable, in this case System.in, and free those resources.
      You will not be to read from System.in anymore after this you call .close().
      If you wanted to use System.in for something else, then don't close the Scanner.
   */
   sis.close();
   System.exit(0);
 }
Beispiel #17
0
  private void addClient() {
    try {
      Scanner input = new Scanner(System.in);
      System.out.println("Fullname:");
      String fullName = input.nextLine();
      System.out.println("VIP:");
      boolean vip = input.nextBoolean();
      System.out.println("User name:");
      String userName = input.nextLine();
      System.out.println("Password:"******"Validation exception" + vex);
    }
  }
Beispiel #18
0
  public static void main(String args[]) {
    Clac cal = new Clac();
    Scanner sc = new Scanner(System.in);
    int maths_marks, english_marks, hindi_marks, science_marks, social_marks;
    boolean choice;

    System.out.println("Enter mathematics marks between 0-100 : ");
    maths_marks = sc.nextInt();
    if (maths_marks < 0 || maths_marks > 100) {
      System.out.println("Please Enter mathematics marks again : ");
      maths_marks = sc.nextInt();
    }

    System.out.println("Enter English marks marks between 0-100: ");
    english_marks = sc.nextInt();
    if (english_marks < 0 || english_marks > 100) {
      System.out.println("Please Enter mathematics marks again : ");
      english_marks = sc.nextInt();
    }

    System.out.println("Enter Hindi marks marks between 0-100: ");
    hindi_marks = sc.nextInt();
    if (hindi_marks < 0 || hindi_marks > 100) {
      System.out.println("Please Enter mathematics marks again : ");
      hindi_marks = sc.nextInt();
    }

    System.out.println("Enter Science marks marks between 0-100: ");
    science_marks = sc.nextInt();
    if (science_marks < 0 || science_marks > 100) {
      System.out.println("Please Enter mathematics marks again : ");
      science_marks = sc.nextInt();
    }

    System.out.println("Enter Social Science marks marks between 0-100: ");
    social_marks = sc.nextInt();
    if (social_marks < 0 || social_marks > 100) {
      System.out.println("Please Enter mathematics marks again : ");
      social_marks = sc.nextInt();
    }
    System.out.println("Type true to caluculate percentage,total and grades : ");
    choice = sc.nextBoolean();
    if (choice == true) {
      cal.percentage(maths_marks, english_marks, hindi_marks, science_marks, social_marks);
    }
  }
Beispiel #19
0
  public static void main(String[] arg) throws Exception {
    // saisie du probleme
    if (arg.length < 2) System.out.println("java testHC  mode file.ham");
    else {

      // le probleme dans un fichier de donnees
      @SuppressWarnings("resource")
      Scanner donnee = new Scanner(new FileReader(arg[1]));

      for (int i = 0; i < 3; i++) donnee.nextLine();
      donnee.next();
      int nbv = donnee.nextInt();

      for (int i = 0; i < 4; i++) donnee.nextLine();
      boolean D[][] = new boolean[nbv][nbv];

      for (int i = 0; i < nbv; i++) {
        for (int j = 0; j < nbv; j++) {
          D[i][j] = donnee.nextBoolean();
          System.out.println(D[i][j] + " ");
        }
        System.out.println();
      }

      HC pb = new HC(nbv, D);

      System.out.println(arg[0]);

      // les differents modes
      if (arg[0].equals("-verif")) {
        CertificatTSP c = (CertificatTSP) pb.red().cert();
        System.out.print("Proposez un certificat:");
        c.saisie();

        System.out.print("Votre certificat est-il correct? ");
        System.out.println(pb.red().estCorrect(c));

      } else if (arg[0].equals("-nondet")) {
        System.out.println(pb.red().aUneSolutionNonDeterministe());
      } else if (arg[0].equals("-exhaust")) {
        System.out.println("le probleme a-t-il une solution? ");
        System.out.println(pb.red().aUneSolution());
      } else System.out.println("erreur de mode");
    }
  }
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner input = new Scanner(System.in);

    Fan f = new Fan();
    System.out.print("Enter the speed of the fan: ");
    f.speed = input.nextInt();

    System.out.print("Enter the radius of the fan: ");
    f.radius = input.nextInt();

    System.out.print("Is the fan on? (T or F) ");
    f.fanstatus = input.nextBoolean();

    System.out.print("Enter the color of the fan ");
    f.color = input.next();

    System.out.println("Fan description: " + f.toString());
  }
Beispiel #21
0
 public static void main(String agrs[]) {
   Scanner in = new Scanner(System.in);
   while (true) {
     try {
       System.out.println("输入一个整形");
       int a = in.nextInt();
       System.out.println("输入一个double");
       double b = in.nextDouble();
       System.out.println("输入一个float");
       float c = in.nextFloat();
       System.out.println("输入一个boolean");
       boolean d = in.nextBoolean(); // 这句肯定是会报错。如果不是输入true或则false
       System.out.println(a + "\t" + b + "\t" + c + "\t" + d);
     } catch (Exception e) {
       e.printStackTrace();
     } finally {
       System.out.println("我来看热闹的,我是finally");
     }
   }
 }
  private Animation parseImagestripAnimations(
      Scanner cmdScanner, ImageStrip imgStrip, int frameDuration) {
    int firstFrameCol, lastFrameCol;

    if (cmdScanner.hasNextBoolean()) {
      firstFrameCol = 0;
      lastFrameCol = imgStrip.getCols();
    } else {
      firstFrameCol = cmdScanner.nextInt();
      lastFrameCol = cmdScanner.nextInt();
    }
    boolean loop = cmdScanner.nextBoolean();

    List<Image> result = new ArrayList<Image>();
    for (int col = firstFrameCol; col < lastFrameCol && col < imgStrip.getCols(); col++) {
      result.add(imgStrip.getSubImage(col));
    }
    Animation anim = new Animation(result.toArray(new Image[result.size()]), frameDuration);
    anim.setAutoUpdate(false);
    anim.setLooping(loop);
    return anim;
  }
Beispiel #23
0
 private static void createNewResearch() {
   Research r = new Research();
   r.setCreationDate(new Date());
   System.out.print("nazwa tabeli >");
   r.setName(sc.next());
   ArrayList<Question> qs = new ArrayList<Question>();
   while (true) {
     System.out.print("dodac? > ");
     boolean b = sc.nextBoolean();
     if (!b) {
       break;
     }
     Question question = new Question();
     System.out.print("tresc pytania >");
     question.setQuestion(sc.next());
     System.out.print("typ 1.boolean, 2.string, 3.date, 4.integer>");
     switch (sc.nextInt()) {
       case 1:
         question.setQuestionType(QuestionType.BOOLEAN);
         break;
       case 2:
         question.setQuestionType(QuestionType.STRING);
         break;
       case 3:
         question.setQuestionType(QuestionType.DATE);
         break;
       case 4:
         question.setQuestionType(QuestionType.INTEGER);
         break;
       default:
         break;
     }
     qs.add(question);
   }
   r.setQuestions(qs);
   service.persist(r);
 }
Beispiel #24
0
  public boolean load() {
    if (!file.exists()) return true;

    Scanner in;
    try {
      in = new Scanner(file);
    } catch (FileNotFoundException e) {
      pl.getLogger().severe("ipbans.dat appears to exist, but Scanner threw exception.");
      pl.getLogger().throwing(this.getClass().getName(), "load", e);
      return false;
    }

    Scanner tempScan;
    byte version = -1;
    List<String> buffer = new ArrayList<String>(10);
    while (in.hasNextLine()) {
      buffer.add(in.nextLine());
    }
    in.close();

    for (int i = 0; i < buffer.size(); i++) {
      String line = buffer.get(i);
      tempScan = new Scanner(line);
      {
        if (tempScan.hasNext()) {
          String identifier = tempScan.next();
          if (identifier.equals("VERSION:")) {
            if (tempScan.hasNextByte()) {
              version = tempScan.nextByte();
            } else {
              pl.getLogger().warning("Missing version number in " + file.getName());
              pl.getLogger().warning("Assuming " + IP_BANS_VERSION);
              version = IP_BANS_VERSION;
            }
          } else // IP listing
          {
            try {

              String ips = tempScan.next();

              tempScan.useDelimiter("\u00C4");
              String reason = tempScan.next();
              String info = tempScan.next();
              tempScan.reset();
              tempScan.skip("\u00C4");
              long endTime = tempScan.nextLong();
              String uuidStr = tempScan.next();
              String bannerUuidStr = tempScan.next();
              boolean isReq = tempScan.nextBoolean();
              long expireTime = -1;
              boolean aoe = false;
              if (isReq) {
                expireTime = tempScan.nextLong();
                aoe = tempScan.nextBoolean();
              }

              Scanner ipsScan = new Scanner(ips);
              ipsScan.useDelimiter(",");

              List<String> ipsList = new ArrayList<String>();

              while (ipsScan.hasNext()) ipsList.add(ipsScan.next());

              ipsScan.close();

              UUID banned = uuidStr.equals("null") ? null : UUID.fromString(uuidStr);
              UUID banner = bannerUuidStr.equals("null") ? null : UUID.fromString(bannerUuidStr);

              IpBan ipban =
                  new IpBan(ipsList, reason, info, endTime, banned, banner, isReq, expireTime, aoe);

              if (ipban.isOver()) {
                // it's over- dont add it back
                this.removeBan(ipban);
              } else if (ipban.isExpired()) {
                // its expired, fetch new ban if needed
                IpBan newBan = ipban.expire();
                if (newBan != null) {
                  this.addBan(newBan);
                }
                this.removeBan(ipban);
              } else {
                this.ipBans.add(ipban);
              }

            } catch (InputMismatchException ime) {
              pl.getLogger().severe("Input mismatch in " + file.getName() + ". Ban will be lost.");
              pl.getLogger().throwing(this.getClass().getName(), "load", ime);
              continue;
            } catch (NoSuchElementException nsee) {
              pl.getLogger().severe("Missing element in " + file.getName() + ". Ban will be lost.");
              pl.getLogger().throwing(this.getClass().getName(), "load", nsee);
              continue;
            }
          }
        } else {
          pl.getLogger().warning("Found unexpected empty line in " + file.getName());
        }
      }
      tempScan.close();
    }

    return true;
  }
Beispiel #25
0
  public static void checkforwin() {
    if (board.button1.getText().equals("X")) {
      if (board.button4.getText().equals("X")) {
        if (board.button7.getText().equals("X")) {
          playerWon = true;
          computerWon = false;
          System.out.println("Player won!");
          board.setVisible(false);
        }
      }
    }
    if (board.button1.getText().equals("X")) {
      if (board.button5.getText().equals("X")) {
        if (board.button9.getText().equals("X")) {
          playerWon = true;
          computerWon = false;
          System.out.println("Player won!");
        }
      }
    }
    if (board.button1.getText().equals("X")) {
      if (board.button2.getText().equals("X")) {
        if (board.button3.getText().equals("X")) {
          playerWon = true;
          computerWon = false;
          System.out.println("Player won!");
        }
      }
    }
    if (board.button3.getText().equals("X")) {
      if (board.button5.getText().equals("X")) {
        if (board.button7.getText().equals("X")) {
          playerWon = true;
          computerWon = false;
          System.out.println("Player won!");
        }
      }
    }
    if (board.button3.getText().equals("X")) {
      if (board.button6.getText().equals("X")) {
        if (board.button9.getText().equals("X")) {
          playerWon = true;
          computerWon = false;
          System.out.println("Player won!");
        }
      }
    }
    if (board.button7.getText().equals("X")) {
      if (board.button8.getText().equals("X")) {
        if (board.button9.getText().equals("X")) {
          playerWon = true;
          computerWon = false;
          System.out.println("Player won!");
        }
      }
    }
    if (board.button4.getText().equals("X")) {
      if (board.button5.getText().equals("X")) {
        if (board.button6.getText().equals("X")) {
          playerWon = true;
          computerWon = false;
          System.out.println("Player won!");
        }
      }
    }
    if (board.button2.getText().equals("X")) {
      if (board.button5.getText().equals("X")) {
        if (board.button8.getText().equals("X")) {
          playerWon = true;
          computerWon = false;
          System.out.println("Player won!");
        }
      }
    }

    // incepe cu O
    if (board.button1.getText().equals("O")) {
      if (board.button4.getText().equals("O")) {
        if (board.button7.getText().equals("O")) {
          playerWon = false;
          computerWon = true;
          System.out.println("Player 2 won!");
        }
      }
    }
    if (board.button1.getText().equals("O")) {
      if (board.button5.getText().equals("O")) {
        if (board.button9.getText().equals("O")) {
          playerWon = false;
          computerWon = true;
          System.out.println("Player 2 won!");
        }
      }
    }
    if (board.button1.getText().equals("O")) {
      if (board.button2.getText().equals("O")) {
        if (board.button3.getText().equals("O")) {
          playerWon = false;
          computerWon = true;
          System.out.println("Player 2 won!");
        }
      }
    }
    if (board.button3.getText().equals("O")) {
      if (board.button5.getText().equals("O")) {
        if (board.button7.getText().equals("O")) {
          playerWon = false;
          computerWon = true;
          System.out.println("Player 2 won!");
        }
      }
    }
    if (board.button3.getText().equals("O")) {
      if (board.button6.getText().equals("O")) {
        if (board.button9.getText().equals("O")) {
          playerWon = false;
          computerWon = true;
          System.out.println("Player 2 won!");
        }
      }
    }
    if (board.button7.getText().equals("O")) {
      if (board.button8.getText().equals("O")) {
        if (board.button9.getText().equals("O")) {
          playerWon = false;
          computerWon = true;
          System.out.println("Player 2 won!");
        }
      }
    }
    if (board.button4.getText().equals("O")) {
      if (board.button5.getText().equals("O")) {
        if (board.button6.getText().equals("O")) {
          playerWon = false;
          computerWon = true;
          System.out.println("Player 2 won!");
        }
      }
    }
    if (board.button2.getText().equals("O")) {
      if (board.button5.getText().equals("O")) {
        if (board.button8.getText().equals("O")) {
          playerWon = false;
          computerWon = true;
          System.out.println("Player 2 won!");
        }
      }
    }
    if (playerWon == true || computerWon == true) {

      System.out.println("Would you like to play again!? true or false");
      playAgain = scan.nextBoolean();
      if (playAgain == true) {
        board.setVisible(false);
        System.out.println("Player1 Won: " + playerWon);
        System.out.println("Player2 Won: " + computerWon);
        board.button1.setText("");
        board.button2.setText("");
        board.button3.setText("");
        board.button4.setText("");
        board.button5.setText("");
        board.button6.setText("");
        board.button7.setText("");
        board.button8.setText("");
        board.button9.setText("");
        // playerTurn - true
        // playerWne - false
        // computerWne - false

        playerTurn = true;
        playerWon = false;
        computerWon = false;
        board.setVisible(true);

      } else {
        System.out.println("Thanks for playing...! ");
      }
    }
  }
Beispiel #26
0
 public static boolean scanBoolean(Object out) {
   System.out.print(out);
   Scanner scanner = new Scanner(System.in);
   return (scanner.nextBoolean());
 }
Beispiel #27
0
  public static Object parseValue(Database database, Object val, DataType type) {
    if (!(val instanceof String)) {
      return val;
    }

    int typeId = Integer.MIN_VALUE;
    if (type.getDataTypeId() != null) {
      typeId = type.getDataTypeId();
    }
    String typeName = type.getTypeName();

    LiquibaseDataType liquibaseDataType = DataTypeFactory.getInstance().from(type, database);

    String stringVal = (String) val;
    if (stringVal.isEmpty()) {
      if (liquibaseDataType instanceof CharType) {
        return "";
      } else {
        return null;
      }
    }

    if (database instanceof OracleDatabase
        && !stringVal.startsWith("'")
        && !stringVal.endsWith("'")) {
      // oracle returns functions without quotes
      Object maybeDate = null;

      if (liquibaseDataType instanceof DateType || typeId == Types.DATE) {
        if (stringVal.endsWith("'HH24:MI:SS')")) {
          maybeDate =
              DataTypeFactory.getInstance()
                  .fromDescription("time", database)
                  .sqlToObject(stringVal, database);
        } else {
          maybeDate =
              DataTypeFactory.getInstance()
                  .fromDescription("date", database)
                  .sqlToObject(stringVal, database);
        }
      } else if (liquibaseDataType instanceof DateTimeType || typeId == Types.TIMESTAMP) {
        maybeDate =
            DataTypeFactory.getInstance()
                .fromDescription("datetime", database)
                .sqlToObject(stringVal, database);
      } else {
        return new DatabaseFunction(stringVal);
      }
      if (maybeDate != null) {
        if (maybeDate instanceof java.util.Date) {
          return maybeDate;
        } else {
          return new DatabaseFunction(stringVal);
        }
      }
    }

    if (stringVal.startsWith("'") && stringVal.endsWith("'")) {
      stringVal = stringVal.substring(1, stringVal.length() - 1);
    } else if (stringVal.startsWith("((") && stringVal.endsWith("))")) {
      stringVal = stringVal.substring(2, stringVal.length() - 2);
    } else if (stringVal.startsWith("('") && stringVal.endsWith("')")) {
      stringVal = stringVal.substring(2, stringVal.length() - 2);
    } else if (stringVal.startsWith("(") && stringVal.endsWith(")")) {
      return new DatabaseFunction(stringVal.substring(1, stringVal.length() - 1));
    }

    Scanner scanner = new Scanner(stringVal.trim());
    if (typeId == Types.ARRAY) {
      return new DatabaseFunction(stringVal);
    } else if ((liquibaseDataType instanceof BigIntType || typeId == Types.BIGINT)) {
      if (scanner.hasNextBigInteger()) {
        return scanner.nextBigInteger();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if (typeId == Types.BINARY) {
      return new DatabaseFunction(stringVal.trim());
    } else if (typeId == Types.BIT) {
      if (stringVal.startsWith("b'")) { // mysql returns boolean values as b'0' and b'1'
        stringVal = stringVal.replaceFirst("b'", "").replaceFirst("'$", "");
      }
      stringVal = stringVal.trim();
      if (scanner.hasNextBoolean()) {
        return scanner.nextBoolean();
      } else {
        return new Integer(stringVal);
      }
    } else if (liquibaseDataType instanceof BlobType || typeId == Types.BLOB) {
      return new DatabaseFunction(stringVal);
    } else if ((liquibaseDataType instanceof BooleanType || typeId == Types.BOOLEAN)) {
      if (scanner.hasNextBoolean()) {
        return scanner.nextBoolean();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if (liquibaseDataType instanceof CharType || typeId == Types.CHAR) {
      return stringVal;
    } else if (liquibaseDataType instanceof ClobType || typeId == Types.CLOB) {
      return stringVal;
    } else if (typeId == Types.DATALINK) {
      return new DatabaseFunction(stringVal);
    } else if (liquibaseDataType instanceof DateType || typeId == Types.DATE) {
      if (typeName.equalsIgnoreCase("year")) {
        return stringVal.trim();
      }
      return DataTypeFactory.getInstance()
          .fromDescription("date", database)
          .sqlToObject(stringVal, database);
    } else if ((liquibaseDataType instanceof DecimalType || typeId == Types.DECIMAL)) {
      if (scanner.hasNextBigDecimal()) {
        return scanner.nextBigDecimal();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if (typeId == Types.DISTINCT) {
      return new DatabaseFunction(stringVal);
    } else if ((liquibaseDataType instanceof DoubleType || typeId == Types.DOUBLE)) {
      if (scanner.hasNextDouble()) {
        return scanner.nextDouble();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if ((liquibaseDataType instanceof FloatType || typeId == Types.FLOAT)) {
      if (scanner.hasNextFloat()) {
        return scanner.nextFloat();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if ((liquibaseDataType instanceof IntType || typeId == Types.INTEGER)) {
      if (scanner.hasNextInt()) {
        return scanner.nextInt();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if (typeId == Types.JAVA_OBJECT) {
      return new DatabaseFunction(stringVal);
    } else if (typeId == Types.LONGNVARCHAR) {
      return stringVal;
    } else if (typeId == Types.LONGVARBINARY) {
      return new DatabaseFunction(stringVal);
    } else if (typeId == Types.LONGVARCHAR) {
      return stringVal;
    } else if (liquibaseDataType instanceof NCharType || typeId == Types.NCHAR) {
      return stringVal;
    } else if (typeId == Types.NCLOB) {
      return stringVal;
    } else if (typeId == Types.NULL) {
      return null;
    } else if ((liquibaseDataType instanceof NumberType || typeId == Types.NUMERIC)) {
      if (scanner.hasNextBigDecimal()) {
        return scanner.nextBigDecimal();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if (liquibaseDataType instanceof NVarcharType || typeId == Types.NVARCHAR) {
      return stringVal;
    } else if (typeId == Types.OTHER) {
      if (database instanceof DB2Database && typeName.equalsIgnoreCase("DECFLOAT")) {
        return new BigDecimal(stringVal);
      }
      return new DatabaseFunction(stringVal);
    } else if (typeId == Types.REAL) {
      return new BigDecimal(stringVal.trim());
    } else if (typeId == Types.REF) {
      return new DatabaseFunction(stringVal);
    } else if (typeId == Types.ROWID) {
      return new DatabaseFunction(stringVal);
    } else if ((liquibaseDataType instanceof SmallIntType || typeId == Types.SMALLINT)) {
      if (scanner.hasNextInt()) {
        return scanner.nextInt();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if (typeId == Types.SQLXML) {
      return new DatabaseFunction(stringVal);
    } else if (typeId == Types.STRUCT) {
      return new DatabaseFunction(stringVal);
    } else if (liquibaseDataType instanceof TimeType || typeId == Types.TIME) {
      return DataTypeFactory.getInstance()
          .fromDescription("time", database)
          .sqlToObject(stringVal, database);
    } else if (liquibaseDataType instanceof DateTimeType
        || liquibaseDataType instanceof TimestampType
        || typeId == Types.TIMESTAMP) {
      return DataTypeFactory.getInstance()
          .fromDescription("datetime", database)
          .sqlToObject(stringVal, database);
    } else if ((liquibaseDataType instanceof TinyIntType || typeId == Types.TINYINT)) {
      if (scanner.hasNextInt()) {
        return scanner.nextInt();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if (typeId == Types.VARBINARY) {
      return new DatabaseFunction(stringVal);
    } else if (liquibaseDataType instanceof VarcharType || typeId == Types.VARCHAR) {
      return stringVal;
    } else if (database instanceof MySQLDatabase && typeName.toLowerCase().startsWith("enum")) {
      return stringVal;
    } else {
      LogFactory.getLogger()
          .info(
              "Unknown default value: value '"
                  + stringVal
                  + "' type "
                  + typeName
                  + " ("
                  + type
                  + "), assuming it is a function");
      return new DatabaseFunction(stringVal);
    }
  }